Skip to main content
Warning: You are using the test version of PyPI. This is a pre-production deployment of Warehouse. Changes made here affect the production instance of TestPyPI (testpypi.python.org).
Help us improve Python packaging - Donate today!

Official Python library for using the Memento Protocol

Project Description
The py-memento-client library provides Memento support, as specified in RFC 7089 (http://tools.ietf.org/html/rfc7089).

For more information about Memento, see http://www.mementoweb.org/about/

This source distribution contains the following folders:

* memento_client - the memento_client module
* test - test code for memento_client
* LICENSE - the license for this source code
* README.md - this file
* README.txt - symbolic link to README.md
* setup.py - Python script for building this library

# BUILD

To build this distribution, just type:
```
python setup.py sdist
```
and it will create a dist folder containing a tar.gz containing this distribution.

To start fresh:
```
python setup.py clean
```
will remove the contents of the build and dist folders.

To run automated tests:
```
python setup.py test
```
Note that these rely upon live web resources, which should not change.

# USING THE LIBRARY

This simple use case gets a Memento from the default Memento TimeGate for "http://lanl.gov" on April 24, 2010 at 19:00:00.

```python
import datetime
import memento_client

dt = datetime.datetime(2010, 4, 24, 19, 0)

uri = "http://lanl.gov"

mc = MementoClient()

memento_uri = mc.get_memento_info(uri, dt).get("mementos").get("closest").get("uri")[0]
```

One can specify a specific TimeGate like so.

```python
import datetime
import memento_client

dt = datetime.datetime(2010, 4, 24, 19, 0)
uri = "http://lanl.gov"

timegate = "http://timetravel.mementoweb.org/webcite/timegate/"

mc = MementoClient(timegate_uri=timegate, check_native_timegate=False)

memento_uri = mc.get_memento_info(uri, dt).get("mementos").get("closest").get("uri")[0]
```
The get_memento_info method returns a dictionary much like the JSON format described by API documentation at http://timetravel.mementoweb.org/guide/api/#memento-json.

For example (as run in iPython):

```python
In [48]: mc = MementoClient()

In [49]: mc.get_memento_info("http://www.cnn.com", dt)
Out[49]:
{'mementos': {'closest': {'datetime': datetime.datetime(2001, 9, 11, 18, 15, 28),
'http_status_code': 200,
'uri': [u'http://webarchive.loc.gov/all/20010911181528/http://www2.cnn.com/']},
'first': {'datetime': datetime.datetime(2000, 6, 20, 18, 2, 59),
'uri': ['http://web.archive.org/web/20000620180259/http://cnn.com/']},
'last': {'datetime': datetime.datetime(2015, 8, 7, 20, 0, 34),
'uri': ['http://web.archive.org/web/20150807200034/http://www.cnn.com/']}},
'original_uri': 'http://www.cnn.com',
'timegate_uri': 'http://timetravel.mementoweb.org/timegate/http://www.cnn.com'}
```

As shown above, to get the closest memento to the datetime given, use .get("mementos").get("closest").get("uri")[0] in order to extract the first memento URI from the list.

Other information is also available from this data structure. Using .get("mementos").get("first").get("uri")[0] returns the first URI-M known for the given URI-R. This data structure also contains the "timegate_uri" refering to the URI-G that was used for datetime negotiation during this session. So backtracking is possible, the "original_uri" key is available to extract the URI-R again.

If the TimeGate has no Memento to return (i.e. the archive has no Memento for that URI-R), then the data structure returned only contains the "original_uri" and "timegate_uri" keys, as show below (as run in iPython):

```python
In [46]: mc = MementoClient(timegate_uri="http://timetravel.example.org/testing/timegate")

In [47]: mc.get_memento_info("http://www.cnn.com", dt)Out[47]:
{'original_uri': 'http://www.cnn.com',
'timegate_uri': 'http://timetravel.example.org/testing/timegatehttp://www.cnn.com'}
```
Release History

Release History

History Node

0.5.1.dev7

History Node

0.5.1.dev6

History Node

0.5.1.dev5

History Node

0.5.1.dev4

History Node

0.5.1.dev3

History Node

0.5.1.dev2

History Node

0.5.1.dev1

This version
History Node

0.5.0

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting