Welcome to ArchivesSnake’s documentation!

class asnake.aspace.ASpace(**config)[source]
__getattr__(attr)[source]

returns the JSONModelRelation representing the route with the same name as the attribute requested.

class asnake.jsonmodel.JSONModelObject(json_rep, client=None)[source]

A wrapper over the JSONModel representation of a single object in ArchivesSpace.

id

Return the id for the object if it has a useful ID, or else None.

Note: unlike uri, an id is Not fully unique within some collections returnable by API methods. For example, searches can return different types of objects, and agents have unique ids per agent_type, not across all agents.

json()[source]

return wrapped dict representing JSONModelObject contents.

reify()[source]

Convert object from a ref into a realized object.

class asnake.jsonmodel.ComponentObject(json_rep, client=None)[source]
id

Return the id for the object if it has a useful ID, or else None.

Note: unlike uri, an id is Not fully unique within some collections returnable by API methods. For example, searches can return different types of objects, and agents have unique ids per agent_type, not across all agents.

json()

return wrapped dict representing JSONModelObject contents.

reify()

Convert object from a ref into a realized object.

tree

Returns a TreeNode object for children of archival objects

class asnake.jsonmodel.JSONModelRelation(uri, params={}, client=None)[source]

A wrapper over index routes and other routes that represent groups of items in ASpace.

It provides two means of accessing objects in these collections:

  • you can iterate over the relation to get all objects
  • you can call the relation as a function with an id to get an object with a known id

e.g.

for repo in ASpace().repositories:
    # do stuff with repo here

ASpace.repositories(12) # object at uri /repositories/12

This object wraps the route and parameters, and does no caching - each iteration through a relation fetches data from ASpace fresh.

Additionally, JSONModelRelations implement __getattr__, in order to handle nested and subsidiary routes, such as the routes for individual types of agents.

__getattr__(key)[source]
__call__(myid, **params)[source]

Fetch a JSONModelObject from the relation by id.

with_params(**params)[source]

Return JSONModelRelation with same uri and client, but add kwargs to params.

Usage:

for thing in ASpace().repositories(2).search.with_params(q="primary_type:resource", fq="publish:true"):
    # do something with the things
class asnake.aspace.AgentRelation(uri, params={}, client=None)[source]

subtype of JSONModelRelation for handling the /agents route hierarchy.

Usage:

ASpace().agents                        # all agents of all types
ASpace().agents.corporate_entities     # JSONModelRelation of corporate entities
ASpace().agents["corporate_entities"]  # see above
ASpace().agents["people", "families"]  # Multiple types of agents
__getitem__(only)[source]

filter the AgentRelation to only the type or types passed in

exception asnake.jsonmodel.ASNakeBadAgentType[source]
class asnake.jsonmodel.AgentRelation(uri, params={}, client=None)[source]

subtype of JSONModelRelation for handling the /agents route hierarchy.

Usage:

ASpace().agents                        # all agents of all types
ASpace().agents.corporate_entities     # JSONModelRelation of corporate entities
ASpace().agents["corporate_entities"]  # see above
ASpace().agents["people", "families"]  # Multiple types of agents
class asnake.jsonmodel.ComponentObject(json_rep, client=None)[source]
tree

Returns a TreeNode object for children of archival objects

class asnake.jsonmodel.JM[source]

Helper class for creating hashes suitable for POSTing to ArchivesSpace.

Usage:

JM.resource(title="A Resource's Title", ...) == {"jsonmodel_type": "resource", "title": "A Resource's Title", ...}
JM.agent_software(name="ArchivesSnake") == {"jsonmodel_type": "agent_software", "name": "ArchivesSnake"}
class asnake.jsonmodel.JSONModel(name, parents, dct)[source]

Mixin providing functionality shared by JSONModel and JSONModelRelation classes.

default_client()[source]

return existing ASnakeClient or create, store, and return a new ASnakeClient

class asnake.jsonmodel.JSONModelObject(json_rep, client=None)[source]

A wrapper over the JSONModel representation of a single object in ArchivesSpace.

id

Return the id for the object if it has a useful ID, or else None.

Note: unlike uri, an id is Not fully unique within some collections returnable by API methods. For example, searches can return different types of objects, and agents have unique ids per agent_type, not across all agents.

json()[source]

return wrapped dict representing JSONModelObject contents.

reify()[source]

Convert object from a ref into a realized object.

class asnake.jsonmodel.JSONModelRelation(uri, params={}, client=None)[source]

A wrapper over index routes and other routes that represent groups of items in ASpace.

It provides two means of accessing objects in these collections:

  • you can iterate over the relation to get all objects
  • you can call the relation as a function with an id to get an object with a known id

e.g.

for repo in ASpace().repositories:
    # do stuff with repo here

ASpace.repositories(12) # object at uri /repositories/12

This object wraps the route and parameters, and does no caching - each iteration through a relation fetches data from ASpace fresh.

Additionally, JSONModelRelations implement __getattr__, in order to handle nested and subsidiary routes, such as the routes for individual types of agents.

with_params(**params)[source]

Return JSONModelRelation with same uri and client, but add kwargs to params.

Usage:

for thing in ASpace().repositories(2).search.with_params(q="primary_type:resource", fq="publish:true"):
    # do something with the things
class asnake.jsonmodel.SolrRelation(uri, params={}, client=None)[source]

Sometimes, the API returns solr responses, so we have to handle that. Facets are still tbd, but should be doable, but also I’m not sure if they’re widely used and thus need to be handled?.

with_params(**params)[source]

Return JSONModelRelation with same uri and client, but add kwargs to params.

Usage:

for thing in ASpace().repositories(2).search.with_params(q="primary_type:resource", fq="publish:true"):
    # do something with the things
class asnake.jsonmodel.TreeNode(json_rep, client=None)[source]
record

returns the full JSONModelObject for a node

walk

Serial walk of all objects in tree and children (depth-first traversal)

class asnake.jsonmodel.UserRelation(uri, params={}, client=None)[source]

“Custom” relation to deal with the API’s failure to properly populate permissions for the /users index route

current_user

/users/current-user route.

asnake.jsonmodel.dispatch_type(obj)[source]

Determines if object is JSON suitable for wrapping with a JSONModelObject or TreeNode. Returns either the correct class or False if no class is suitable.

Note: IN GENERAL, it is safe to use this to test if a thing is a JSONModel subtype, but you should STRONGLY prefer wrap_json_object() for constructing objects, because some objects are wrapped, and would need to be manually unwrapped otherwise. So, usage like this:

jmtype = dispatch_type(obj, self.client)
if jmtype:
    return wrap_json_object(obj, self.client)

is fine and expected, but the following is dangerous:

jmtype = dispatch_type(obj, self.client)
if jmtype:
    return jmtype(obj, self.client)

because it will break on wrapped or otherwise odd objects.

asnake.jsonmodel.find_subtree(tree, uri)[source]

Navigates a tree object to get a list of children of a specified archival object uri.

asnake.jsonmodel.wrap_json_object(obj, client=None)[source]

Classify object, and either wrap it in the correct JSONModel type or return it as is.

Prefer this STRONGLY to directly using the output of dispatch_type()

class asnake.client.ASnakeClient(**config)[source]

ArchivesSnake Web Client

authorize(username=None, password=None)[source]

Authorizes the client against the configured archivesspace instance.

Parses the JSON response, and stores the returned session token in the session.headers for future requests. Asks for a “non-expiring” session, which isn’t truly immortal, just long-lived.

delete(url, *args, **kwargs)

Proxied requests.Session.delete() method from requests.Session

get(url, *args, **kwargs)

Proxied requests.Session.get() method from requests.Session

get_paged(url, *args, page_size=10, **kwargs)[source]

get list of json objects from urls of paged items

head(url, *args, **kwargs)

Proxied requests.Session.head() method from requests.Session

options(url, *args, **kwargs)

Proxied requests.Session.options() method from requests.Session

post(url, *args, **kwargs)

Proxied requests.Session.post() method from requests.Session

put(url, *args, **kwargs)

Proxied requests.Session.put() method from requests.Session

exception asnake.client.web_client.ASnakeAuthError[source]
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class asnake.client.web_client.ASnakeClient(**config)[source]

ArchivesSnake Web Client

authorize(username=None, password=None)[source]

Authorizes the client against the configured archivesspace instance.

Parses the JSON response, and stores the returned session token in the session.headers for future requests. Asks for a “non-expiring” session, which isn’t truly immortal, just long-lived.

delete(url, *args, **kwargs)

Proxied requests.Session.delete() method from requests.Session

get(url, *args, **kwargs)

Proxied requests.Session.get() method from requests.Session

get_paged(url, *args, page_size=10, **kwargs)[source]

get list of json objects from urls of paged items

head(url, *args, **kwargs)

Proxied requests.Session.head() method from requests.Session

options(url, *args, **kwargs)

Proxied requests.Session.options() method from requests.Session

post(url, *args, **kwargs)

Proxied requests.Session.post() method from requests.Session

put(url, *args, **kwargs)

Proxied requests.Session.put() method from requests.Session

class asnake.client.web_client.ASnakeProxyMethods(name, parents, dct)[source]

Metaclass to set up proxy methods for all requests-supported HTTP methods

mro() → list

return a type’s method resolution order

exception asnake.client.web_client.ASnakeWeirdReturnError[source]
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

asnake.client.web_client.http_meth_factory(meth)[source]

Utility method for producing HTTP proxy methods for ASnakeProxyMethods mixin class.

Urls are prefixed with the value of baseurl from the client’s ASnakeConfig. Arguments are passed unaltered to the matching requests.Session method.

asnake.client.web_client.listlike_seq(seq)[source]

Determine if a thing is a list-like (sequence of values) sequence that’s not string-like.

class asnake.ASnakeConfig(config=NOTHING) → None[source]

Configuration object. Essentially a convenience wrapper over an instance of boltons.dictutils.OrderedMultiDict

copy_config(config)

Copy relevant information from one config to another.

default_logging_conf(**overrides)

Generate a default stdlib logging configuration.

default_structlog_conf(**overrides)

Generate a default configuration for structlog

setup_logging(config=None, level=None, stream=None, filename=None, filemode=None)

sets up both logging and structlog.

update(*args, **kwargs)[source]

adds a set of configuration values in ‘most preferred’ position (i.e. last updated wins). See boltons.dictutils.OrderedMultiDict.update_extend() in the OMD docs

Indices and tables