aria.storage

Storage package.

class aria.storage.Storage(api_cls, api_kwargs=None, items=(), initiator=None, initiator_kwargs=None, **kwargs)

Bases: aria.logger.LoggerMixin

Base class for storage managers.

Parameters:
  • api_cls – API class for each entry
  • api_kwargs
  • items – items to register
  • initiator – function which initializes the storage before the first use; this function should return a dict, this dict would be passed in addition to the API kwargs; this enables the creation of non-serializable objects
  • initiator_kwargs
  • kwargs
register(entry)

Register an API.

Parameters:entry
serialization_dict
class aria.storage.ModelStorage(*args, **kwargs)

Bases: aria.storage.core.Storage

Manages storage model APIs (“MAPIs”).

drop()

Drop all the tables.

instrument(*args, **kwds)
register(model_cls)

Register a storage model API (“MAPI”).

Parameters:model_cls – model API to register
class aria.storage.ResourceStorage(api_cls, api_kwargs=None, items=(), initiator=None, initiator_kwargs=None, **kwargs)

Bases: aria.storage.core.Storage

Manages storage resource APIs (“RAPIs”).

Parameters:
  • api_cls – API class for each entry
  • api_kwargs
  • items – items to register
  • initiator – function which initializes the storage before the first use; this function should return a dict, this dict would be passed in addition to the API kwargs; this enables the creation of non-serializable objects
  • initiator_kwargs
  • kwargs
register(name)

Register a storage resource API (“RAPI”).

Parameters:name – name

aria.storage.api

Storage APIs.

class aria.storage.api.ModelAPI(model_cls, name=None, **kwargs)

Bases: aria.storage.api.StorageAPI

Base class for model APIs (“MAPI”).

Parameters:
  • model_cls – representing class of the model
  • name – name of the model
delete(entry_id, **kwargs)

Deletes a model from storage.

Parameters:entry_id
get(entry_id, filters=None, **kwargs)

Gets a model from storage.

Parameters:entry_id
iter(**kwargs)

Iterate over all models in storage.

model_cls

Class representing the model

Type:Type
name

Name of the class.

Type:basestring
put(entry, **kwargs)

Puts a model in storage.

Parameters:entry
update(entry, **kwargs)

Update a model in storage.

Parameters:
  • entry
  • kwargs
class aria.storage.api.ResourceAPI(name, **kwargs)

Bases: aria.storage.api.StorageAPI

Base class for resource APIs (“RAPI”).

Parameters:name – resource type
delete(entry_id, path, **kwargs)

Delete a resource from storage.

Parameters:
  • entry_id
  • path
download(entry_id, destination, path=None, **kwargs)

Download a resource from storage.

Parameters:
  • entry_id
  • destination
  • path
name

Name of resource.

Type:basestring
read(entry_id, path, **kwargs)

Get a bytesteam for a resource from storage.

Parameters:
  • entry_id
  • path
upload(entry_id, source, path=None, **kwargs)

Upload a resource to storage.

Parameters:
  • entry_id
  • source
  • path
class aria.storage.api.StorageAPI

Bases: object

Base class for storage APIs.

create(**kwargs)

Create a storage API. :param kwargs: :return:

aria.storage.api.generate_lower_name(model_cls)

Generates the name of the class from the class object, e.g. SomeClass -> some_class

Parameters:model_cls – class to evaluate
Returns:lowercase name
Return type:basestring

aria.storage.collection_instrumentation

Utilities for instrumenting collections of models in storage.

aria.storage.collection_instrumentation.instrument(instrumentation, original_model, mapi)

aria.storage.core

Storage API management.

class aria.storage.core.Storage(api_cls, api_kwargs=None, items=(), initiator=None, initiator_kwargs=None, **kwargs)

Bases: aria.logger.LoggerMixin

Base class for storage managers.

Parameters:
  • api_cls – API class for each entry
  • api_kwargs
  • items – items to register
  • initiator – function which initializes the storage before the first use; this function should return a dict, this dict would be passed in addition to the API kwargs; this enables the creation of non-serializable objects
  • initiator_kwargs
  • kwargs
register(entry)

Register an API.

Parameters:entry
serialization_dict
class aria.storage.core.ModelStorage(*args, **kwargs)

Bases: aria.storage.core.Storage

Manages storage model APIs (“MAPIs”).

drop()

Drop all the tables.

instrument(*args, **kwds)
register(model_cls)

Register a storage model API (“MAPI”).

Parameters:model_cls – model API to register
class aria.storage.core.ResourceStorage(api_cls, api_kwargs=None, items=(), initiator=None, initiator_kwargs=None, **kwargs)

Bases: aria.storage.core.Storage

Manages storage resource APIs (“RAPIs”).

Parameters:
  • api_cls – API class for each entry
  • api_kwargs
  • items – items to register
  • initiator – function which initializes the storage before the first use; this function should return a dict, this dict would be passed in addition to the API kwargs; this enables the creation of non-serializable objects
  • initiator_kwargs
  • kwargs
register(name)

Register a storage resource API (“RAPI”).

Parameters:name – name

aria.storage.exceptions

Storage exceptions.

exception aria.storage.exceptions.NotFoundError

Bases: aria.storage.exceptions.StorageError

exception aria.storage.exceptions.StorageError

Bases: aria.exceptions.AriaError

General storage exception

aria.storage.filesystem_rapi

File system implementation of the storage resource API (“RAPI”).

class aria.storage.filesystem_rapi.FileSystemResourceAPI(directory, **kwargs)

Bases: aria.storage.api.ResourceAPI

File system implementation of the storage resource API (“RAPI”).

Parameters:directory – root dir for storage
connect(*args, **kwds)

Establishes a connection and destroys it after use.

create(**kwargs)

Creates a directory in by path. Tries to create the root directory as well.

Parameters:name – path of directory
delete(entry_id, path=None, **_)

Deletes a file or directory.

Parameters:
  • entry_id – entry ID
  • path – path to delete relative to the root of the entry (otherwise all)
download(entry_id, destination, path=None, **_)

Downloads a file or directory.

Parameters:
  • entry_id – entry ID
  • destination – download destination
  • path – path to download relative to the root of the entry (otherwise all)
read(entry_id, path, **_)

Retrieves the contents of a file.

Parameters:
  • entry_id – entry ID
  • path – path to resource
Returns:

contents of the file

Return type:

bytes

upload(entry_id, source, path=None, **_)

Uploads a file or directory.

Parameters:
  • entry_id – entry ID
  • source – source of the files to upload
  • path – the destination of the file/s relative to the entry root dir.

aria.storage.sql_mapi

SQLAlchemy implementation of the storage model API (“MAPI”).

class aria.storage.sql_mapi.ListResult(metadata, *args, **qwargs)

Bases: list

Contains results about the requested items.

class aria.storage.sql_mapi.SQLAlchemyModelAPI(engine, session, **kwargs)

Bases: aria.storage.api.ModelAPI

SQLAlchemy implementation of the storage model API (“MAPI”).

create(checkfirst=True, create_all=True, **kwargs)
delete(entry, **kwargs)

Deletes a single result based on the model class and element ID.

drop()

Drops the table.

get(entry_id, include=None, **kwargs)

Returns a single result based on the model class and element ID

get_by_name(entry_name, include=None, **kwargs)
iter(include=None, filters=None, sort=None, **kwargs)

Returns a (possibly empty) list of model_class results.

list(include=None, filters=None, pagination=None, sort=None, **kwargs)
put(entry, **kwargs)

Creatse a model_class instance from a serializable model object.

Parameters:entry – dict with relevant kwargs, or an instance of a class that has a to_dict method, and whose attributes match the columns of model_class (might also be just an instance of model_class)
Returns:an instance of model_class
refresh(entry)

Reloads the instance with fresh information from the database.

Parameters:entry – instance to be re-loaded from the database
Returns:refreshed instance
update(entry, **kwargs)

Adds instance to the database session, and attempts to commit.

Returns:updated instance
aria.storage.sql_mapi.init_storage(base_dir, filename='db.sqlite')

Built-in ModelStorage initiator.

Creates a SQLAlchemy engine and a session to be passed to the MAPI.

initiator_kwargs must be passed to the ModelStorage which must hold the base_dir for the location of the database file, and an option filename. This would create an SQLite database.

Parameters:
  • base_dir – directory of the database
  • filename – database file name.
Returns: