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)
In [5]:
catalog = server.connect_ermrest(catalog_number)
pb = catalog.getPathBuilder()
list(pb.schemas)
Out[5]:
In [6]:
latest = catalog.latest_snapshot()
pb = latest.getPathBuilder()
list(pb.schemas)
Out[6]:
Print the snaptime of this catalog snapshot.
In [7]:
print(latest.snaptime)
In [8]:
snapshot = server.connect_ermrest('1', '2PM-DGYP-56Z4')
pb = snapshot.getPathBuilder()
list(pb.schemas)
Out[8]:
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]:
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)
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]:
However, mutation operations on a catalog snapshot are disabled.
In [12]:
try:
subject.insert([{'foo': 'bar'}])
except ErmrestCatalogMutationError as e:
print(e)
In [ ]: