Deriva Ermrest Catalog Snapshot Examples

This notebook gives examples of connecting to ERMrest versioned catalogs.


In [1]:
from deriva.core import DerivaServer, get_credential, ErmrestCatalogMutationError

Fill in your desired scheme, hostname and catalog number.


In [2]:
scheme = 'https'
hostname = 'synapse-dev.isrd.isi.edu'
catalog_number = 1

Use DERIVA-Auth to get a credential or use None if your catalog allows anonymous access.


In [3]:
credential = get_credential(hostname)

Get a handle representing your server.


In [4]:
server = DerivaServer(scheme, hostname, credential)

Connect to a catalog (unversioned)

Connect to a catalog, and list its schemas.


In [5]:
catalog = server.connect_ermrest(catalog_number)
pb = catalog.getPathBuilder()
list(pb.schemas)


Out[5]:
['Synapse', 'public', 'Zebrafish']

Get latest snapshot

The current catalog handle can return a handle to the latest snapshot.


In [6]:
latest = catalog.latest_snapshot()
pb = latest.getPathBuilder()
list(pb.schemas)


Out[6]:
['Synapse', 'public', 'Zebrafish']

Print the snaptime of this catalog snapshot.


In [7]:
print(latest.snaptime)


2PS-ERRT-HD8E

Connect to a catalog snapshot

Here we pass the snaptime parameter explicitly in the connect_ermrest method.


In [8]:
snapshot = server.connect_ermrest('1', '2PM-DGYP-56Z4')
pb = snapshot.getPathBuilder()
list(pb.schemas)


Out[8]:
['Synapse', 'public', 'Zebrafish']

Alternatively, we could pass a "versioned" catalog_id to the connect_ermrest method.


In [9]:
snapshot = server.connect_ermrest('1@2PM-DGYP-56Z4')
pb = snapshot.getPathBuilder()
list(pb.schemas)


Out[9]:
['Synapse', 'public', 'Zebrafish']

Finally, we can poke around at schemas and tables as they existed at the specified snaptime.


In [10]:
subject = pb.schemas['Zebrafish'].tables['Subject']
print(subject.uri)


https://synapse-dev.isrd.isi.edu/ermrest/catalog/1@2PM-DGYP-56Z4/entity/Subject:=Zebrafish:Subject

Data may be read from the snapshot. Here, we will see how many subjects existed at that point in time.


In [11]:
e = subject.entities()
len(e)


Out[11]:
486

However, mutation operations on a catalog snapshot are disabled.


In [12]:
try:
    subject.insert([{'foo': 'bar'}])
except ErmrestCatalogMutationError as e:
    print(e)


Catalog snapshot is immutable

In [ ]: