Models (pydent.models
)¶
This module contains classes for various Aquarium objects.
Models are loaded and initialized from a AqSession
instance.
sample = session.Sample.one()
last50 = session.Item.last(50)
first10 = session.SampleType.first(10)
mysamples = session.Sample.last(10, query={'user_id': 66})
Note
If using an interactive developer, type session. and hit [TAB] to view possible models. Most models have standard method interfaces, such as find, where, one, first, last, all.
From a model instance, attributes can be accessed directly from the model.
print(sample.name)
print(sample.id)
# "LJk12345"
# 3
Calling some attributes will automatically make a new request. For example, calling sample_type from sample will initialize a request for information about that sample’s sample_type:
print(sample.sample_type.name)
# "Plasmid Stock"
If we call sample_type again, a new request will not be made, rather
the model will return the previously returned data. If a new request
is desired, we can reset the field using the
reset_field
method:
assert sample.is_deserialized('sample_type')
sample.reset_field('sample_type')
assert not sample.is_deserialized('sample_type')
# now calling 'sample_type' again will initialize a new request
# which will be cached. This can be checked using `is_deserialized`
sample.sample_type
assert sample.is_deserialized('sample_type')
New in version 0.1.5a7: reset_field
method added to reset
fields.
New in version 0.1.5a7: is_deserialized
can be called
to check if a relation has already been deserialized
Models can be dumped to their JSON data or loaded from data
# dump the data
data = sample.dump()
# load from the data
sample2 = session.Sample.load(data)
Warning
Most model methods require an attached Session
instance. Importing models from pydent.models will result in orphaned models.
Preferrably, if you need to initialize or load new models, use
session.<ModelName>(*args, **kwargs), replacing <ModelName> with the name
of the model class. Alternatively, you can attach a Session instance using
model.connect_to_session(session)
Model Classes¶
Operations¶
|
A Operation model. |
|
Represents an OperationType, which is the definition of a protocol in Aquarium. |
|
A Code model. |
|
A Library model. |
|
A Job model. |
|
A JobAssociation model. |
Plans¶
|
A Plan model. |
|
A PlanAssociation model. |
|
A Wire model. |
Inventory¶
|
A physical object in the lab, which a location and unique id. |
|
A Collection model, such as a 96-well plate, which contains many parts, each of which can be associated with a different sample. |
|
A ObjectType model that represents the type of container an item is. |
|
A Sample model. |
|
A SampleType model. |
|
Represents a PartAssociation linking a part to a collection. |
Data and IO¶
|
A DataAssociation model. |
|
A FieldValue model. |
|
A FieldType model. |
|
A AllowableFieldType model. |
User¶
|
An Account model. |
|
A Budget model. |
|
A Group model. |
|
A Invoice model. |
|
The model initializer. |
|
A User model. |
An association model between a User and a Budget. |
Model Mixins¶
These classes provide some models with common methods such as saving or deleting models from the server or associating data.
Mixin for handling data associations. |
|
Mixin for finding FieldType and FieldValue relationships. |
|
An interface for things that have field types (i.e. |
|
A common interface for things (i.e. |
Field Relationships¶
Field relationships are attribute descriptors that may call information from the Aquarium server if necesssary.
|
Base class for relationships. |
|
Python descriptor that is returned by a field during attribute access. |
|
Calls a specified function upon attribute access. |
|
A relationship that establishes a One-to-Many relationship with another model. |
|
Establishes a One-to-Many relationship using ‘parent_id’ as the attribute to find other models. |
|
A relationship using an intermediate association model. |
|
HasOne initializer. |
|
Returns a single model from a Many relationship. |
|
Automatically serializes/deserializes JSON objects. |
|
Defines a many relationship with another model. |
|
Defines a single relationship with another model. |
|
Field that performs no serialization/deserialization. |
Exceptions¶
Utilities¶
|
Decorator that dynamically attaches a schema to a model. |
-
class
pydent.models.
Account
(**data)[source] Bases:
pydent.base.ModelBase
An Account model.
The model initializer.
- Parameters
data (dict) – data to add to the model
-
_check_for_session
() Raises error if model is not connected to a session.
:raises NoSessionError
-
classmethod
_flatten_deserialized_data
(models, memo) Flattens all of the relationships found in the models, returning a rid: model dictionary.
- Return type
dict
-
_get_data
() Return the model’s data.
-
_get_deserialized_data
() Return the deserialized model data.
-
_model_schema
alias of
pydent.marshaller.base.AccountSchema
-
property
_primary_key
Returns the primary key (e.g. ‘id’) or the rid if id does not exist or is None.
-
_rid_dict
() Dictionary of all models attached to this model keyed by their rid.
-
add_data
(data) Initializes fake attributes that correspond to data.
-
anonymize
() Resets the primary key of the model and assigns a new rid.
Metatypes cannot be annonymized.
- Returns
self
-
append_to_many
(name, model) Appends a model to the many relationship.
- Parameters
name (str) – name of the relationship or attribute
model (ModelBase) – model to append
- Returns
None
- Return type
None
-
connect_to_session
(session) Connect model to a session.
- Parameters
session (
SessionABC
) – theAqSession
- Returns
None
- Raises
SessionAlreadySet – if session is already set
NoSessionError – if session is not a SessionABC type
-
copy
(keep=None) Provides a deepcopy of the model, but annonymizes the primary and global keys unless class is a metatype (e.g. OperationType, SampleType, FieldType) or class name is found in list of ‘keep’.
By default, inventory classes such as Sample, Item, and Collection are ‘kept’.
This specific usecase is that when copying whole plans, that the integrity of the inventory used in the operations is maintained. These are the items that refer to physical inventory in the laboratory and are referred to by their rids, and so it is important to that any of these inventory are always maintain their rids. Meaning in the lab, their is only ONE instance of the inventory. In Trident and Aquarium, there is only ONE instance of inventory that is referred to by its rid.
Similarly, any metatype model must also maintain their rid.
- Parameters
keep (
Optional
[bool
]) – list of model classes (as a list of strings) to keep un-anonymous- Return type
- Returns
copied model
-
dump
(only=None, include=None, ignore=None, include_model_type=False, include_uri=False) Dump (serialize) the Aquarium model instance to JSON.
- Parameters
only (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – dump only the provided keysinclude (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – include the provided nested dump keysignore (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – ignore the provided keysinclude_model_type (
bool
) – if True, include the model class type for each entry using the __model__ keyinclude_uri (
bool
) – if True, include a URI using the session URL and the tableized model class name using the __uri__ key. If a session is not attached, look for the url namespace in the ModelBase.DEFAULT_NAMESPACE class attribute, as in http://aquarium.org/samples/10.
- Return type
dict
- Returns
serialized model instance
-
classmethod
find
(session, model_id) Finds a model instance by its model_id.
- Return type
-
find_callback
(model_name, model_id) Finds a model using the model interface and model_id.
Used to find models in model relationships.
- Return type
-
get_deserialized
(name) Get deserialized data by name.
Deprecated since version 0.1.5a7: method will be removed in 0.2. Use self._get_deserialized_data[name] instead.
- Parameters
name – name of attribute
- Returns
-
classmethod
interface
(session) Creates a model interface from this class and a session.
This method can be overridden in model definitions for special cases.
- Return type
Union
[QueryInterface
,BrowserInterface
]
-
is_deserialized
(name) Check if a given key has already been deserialized.
New in version 0.1.5a7: Method added
- Parameters
name (
str
) – name of the attribute- Return type
bool
- Returns
True if key has been deserialized.
-
classmethod
load
(*args, **kwargs) Deserialize the data to a model.
- Parameters
data (dict) – data to deserialize
- Returns
the deserialized model
- Return type
-
classmethod
load_from
(data, owner=None) Create a new model instance from loaded attributes.
‘obj’ should have a o
-
model_schema
alias of
pydent.marshaller.base.AccountSchema
-
no_getter
(*_) Callback that always returns None.
-
refresh
() Refresh this model from data from the server.
- Returns
self
- Return type
self
-
reload
(data) Reload model attributes from new data.
- Parameters
data (dict) – data to update model instance
- Returns
model instance
- Return type
-
reset_field
(name) Reset the field descriptor to its placeholder value, returning the behavior.
New in version 0.1.5a7: Method added to reset deserialized attributes
- Parameters
name (
str
) – name of the attribute- Returns
None
-
property
session
The connected session instance.
-
property
uri
Return a URI for this model using the attached session url and tableized model name. For example, http://aquarium.org/samples/. If no session is attached, use the ModelBase.DEFAULT_NAMESPACE key for the url.
- Return type
str
- Returns
the instance URI
-
classmethod
where
(session, params) Finds a list of models by some parameters.
- Return type
Optional
[List
[ModelBase
]]
-
where_callback
(model_name, *args, **kwargs) Finds models using a model interface and a set of parameters.
Used to find models in model relationships.
- Return type
Optional
[List
[ModelBase
]]
-
class
pydent.models.
AllowableFieldType
(field_type=None, object_type=None, sample_type=None)[source] Bases:
pydent.base.ModelBase
A AllowableFieldType model.
The model initializer.
- Parameters
data (dict) – data to add to the model
-
_check_for_session
() Raises error if model is not connected to a session.
:raises NoSessionError
-
classmethod
_flatten_deserialized_data
(models, memo) Flattens all of the relationships found in the models, returning a rid: model dictionary.
- Return type
dict
-
_get_data
() Return the model’s data.
-
_get_deserialized_data
() Return the deserialized model data.
-
_model_schema
alias of
pydent.marshaller.base.AllowableFieldTypeSchema
-
property
_primary_key
Returns the primary key (e.g. ‘id’) or the rid if id does not exist or is None.
-
_rid_dict
() Dictionary of all models attached to this model keyed by their rid.
-
add_data
(data) Initializes fake attributes that correspond to data.
-
anonymize
() Resets the primary key of the model and assigns a new rid.
Metatypes cannot be annonymized.
- Returns
self
-
append_to_many
(name, model) Appends a model to the many relationship.
- Parameters
name (str) – name of the relationship or attribute
model (ModelBase) – model to append
- Returns
None
- Return type
None
-
connect_to_session
(session) Connect model to a session.
- Parameters
session (
SessionABC
) – theAqSession
- Returns
None
- Raises
SessionAlreadySet – if session is already set
NoSessionError – if session is not a SessionABC type
-
copy
(keep=None) Provides a deepcopy of the model, but annonymizes the primary and global keys unless class is a metatype (e.g. OperationType, SampleType, FieldType) or class name is found in list of ‘keep’.
By default, inventory classes such as Sample, Item, and Collection are ‘kept’.
This specific usecase is that when copying whole plans, that the integrity of the inventory used in the operations is maintained. These are the items that refer to physical inventory in the laboratory and are referred to by their rids, and so it is important to that any of these inventory are always maintain their rids. Meaning in the lab, their is only ONE instance of the inventory. In Trident and Aquarium, there is only ONE instance of inventory that is referred to by its rid.
Similarly, any metatype model must also maintain their rid.
- Parameters
keep (
Optional
[bool
]) – list of model classes (as a list of strings) to keep un-anonymous- Return type
- Returns
copied model
-
dump
(only=None, include=None, ignore=None, include_model_type=False, include_uri=False) Dump (serialize) the Aquarium model instance to JSON.
- Parameters
only (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – dump only the provided keysinclude (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – include the provided nested dump keysignore (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – ignore the provided keysinclude_model_type (
bool
) – if True, include the model class type for each entry using the __model__ keyinclude_uri (
bool
) – if True, include a URI using the session URL and the tableized model class name using the __uri__ key. If a session is not attached, look for the url namespace in the ModelBase.DEFAULT_NAMESPACE class attribute, as in http://aquarium.org/samples/10.
- Return type
dict
- Returns
serialized model instance
-
classmethod
find
(session, model_id) Finds a model instance by its model_id.
- Return type
-
find_callback
(model_name, model_id) Finds a model using the model interface and model_id.
Used to find models in model relationships.
- Return type
-
get_deserialized
(name) Get deserialized data by name.
Deprecated since version 0.1.5a7: method will be removed in 0.2. Use self._get_deserialized_data[name] instead.
- Parameters
name – name of attribute
- Returns
-
classmethod
interface
(session) Creates a model interface from this class and a session.
This method can be overridden in model definitions for special cases.
- Return type
Union
[QueryInterface
,BrowserInterface
]
-
is_deserialized
(name) Check if a given key has already been deserialized.
New in version 0.1.5a7: Method added
- Parameters
name (
str
) – name of the attribute- Return type
bool
- Returns
True if key has been deserialized.
-
classmethod
load
(*args, **kwargs) Deserialize the data to a model.
- Parameters
data (dict) – data to deserialize
- Returns
the deserialized model
- Return type
-
classmethod
load_from
(data, owner=None) Create a new model instance from loaded attributes.
‘obj’ should have a o
-
model_schema
alias of
pydent.marshaller.base.AllowableFieldTypeSchema
-
no_getter
(*_) Callback that always returns None.
-
refresh
() Refresh this model from data from the server.
- Returns
self
- Return type
self
-
reload
(data) Reload model attributes from new data.
- Parameters
data (dict) – data to update model instance
- Returns
model instance
- Return type
-
reset_field
(name) Reset the field descriptor to its placeholder value, returning the behavior.
New in version 0.1.5a7: Method added to reset deserialized attributes
- Parameters
name (
str
) – name of the attribute- Returns
None
-
property
session
The connected session instance.
-
property
uri
Return a URI for this model using the attached session url and tableized model name. For example, http://aquarium.org/samples/. If no session is attached, use the ModelBase.DEFAULT_NAMESPACE key for the url.
- Return type
str
- Returns
the instance URI
-
classmethod
where
(session, params) Finds a list of models by some parameters.
- Return type
Optional
[List
[ModelBase
]]
-
where_callback
(model_name, *args, **kwargs) Finds models using a model interface and a set of parameters.
Used to find models in model relationships.
- Return type
Optional
[List
[ModelBase
]]
-
class
pydent.models.
Budget
(**data)[source] Bases:
pydent.base.ModelBase
A Budget model.
The model initializer.
- Parameters
data (dict) – data to add to the model
-
_check_for_session
() Raises error if model is not connected to a session.
:raises NoSessionError
-
classmethod
_flatten_deserialized_data
(models, memo) Flattens all of the relationships found in the models, returning a rid: model dictionary.
- Return type
dict
-
_get_data
() Return the model’s data.
-
_get_deserialized_data
() Return the deserialized model data.
-
_model_schema
alias of
pydent.marshaller.base.BudgetSchema
-
property
_primary_key
Returns the primary key (e.g. ‘id’) or the rid if id does not exist or is None.
-
_rid_dict
() Dictionary of all models attached to this model keyed by their rid.
-
add_data
(data) Initializes fake attributes that correspond to data.
-
anonymize
() Resets the primary key of the model and assigns a new rid.
Metatypes cannot be annonymized.
- Returns
self
-
append_to_many
(name, model) Appends a model to the many relationship.
- Parameters
name (str) – name of the relationship or attribute
model (ModelBase) – model to append
- Returns
None
- Return type
None
-
connect_to_session
(session) Connect model to a session.
- Parameters
session (
SessionABC
) – theAqSession
- Returns
None
- Raises
SessionAlreadySet – if session is already set
NoSessionError – if session is not a SessionABC type
-
copy
(keep=None) Provides a deepcopy of the model, but annonymizes the primary and global keys unless class is a metatype (e.g. OperationType, SampleType, FieldType) or class name is found in list of ‘keep’.
By default, inventory classes such as Sample, Item, and Collection are ‘kept’.
This specific usecase is that when copying whole plans, that the integrity of the inventory used in the operations is maintained. These are the items that refer to physical inventory in the laboratory and are referred to by their rids, and so it is important to that any of these inventory are always maintain their rids. Meaning in the lab, their is only ONE instance of the inventory. In Trident and Aquarium, there is only ONE instance of inventory that is referred to by its rid.
Similarly, any metatype model must also maintain their rid.
- Parameters
keep (
Optional
[bool
]) – list of model classes (as a list of strings) to keep un-anonymous- Return type
- Returns
copied model
-
dump
(only=None, include=None, ignore=None, include_model_type=False, include_uri=False) Dump (serialize) the Aquarium model instance to JSON.
- Parameters
only (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – dump only the provided keysinclude (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – include the provided nested dump keysignore (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – ignore the provided keysinclude_model_type (
bool
) – if True, include the model class type for each entry using the __model__ keyinclude_uri (
bool
) – if True, include a URI using the session URL and the tableized model class name using the __uri__ key. If a session is not attached, look for the url namespace in the ModelBase.DEFAULT_NAMESPACE class attribute, as in http://aquarium.org/samples/10.
- Return type
dict
- Returns
serialized model instance
-
classmethod
find
(session, model_id) Finds a model instance by its model_id.
- Return type
-
find_callback
(model_name, model_id) Finds a model using the model interface and model_id.
Used to find models in model relationships.
- Return type
-
get_deserialized
(name) Get deserialized data by name.
Deprecated since version 0.1.5a7: method will be removed in 0.2. Use self._get_deserialized_data[name] instead.
- Parameters
name – name of attribute
- Returns
-
classmethod
interface
(session) Creates a model interface from this class and a session.
This method can be overridden in model definitions for special cases.
- Return type
Union
[QueryInterface
,BrowserInterface
]
-
is_deserialized
(name) Check if a given key has already been deserialized.
New in version 0.1.5a7: Method added
- Parameters
name (
str
) – name of the attribute- Return type
bool
- Returns
True if key has been deserialized.
-
classmethod
load
(*args, **kwargs) Deserialize the data to a model.
- Parameters
data (dict) – data to deserialize
- Returns
the deserialized model
- Return type
-
classmethod
load_from
(data, owner=None) Create a new model instance from loaded attributes.
‘obj’ should have a o
-
model_schema
alias of
pydent.marshaller.base.BudgetSchema
-
no_getter
(*_) Callback that always returns None.
-
refresh
() Refresh this model from data from the server.
- Returns
self
- Return type
self
-
reload
(data) Reload model attributes from new data.
- Parameters
data (dict) – data to update model instance
- Returns
model instance
- Return type
-
reset_field
(name) Reset the field descriptor to its placeholder value, returning the behavior.
New in version 0.1.5a7: Method added to reset deserialized attributes
- Parameters
name (
str
) – name of the attribute- Returns
None
-
property
session
The connected session instance.
-
property
uri
Return a URI for this model using the attached session url and tableized model name. For example, http://aquarium.org/samples/. If no session is attached, use the ModelBase.DEFAULT_NAMESPACE key for the url.
- Return type
str
- Returns
the instance URI
-
classmethod
where
(session, params) Finds a list of models by some parameters.
- Return type
Optional
[List
[ModelBase
]]
-
where_callback
(model_name, *args, **kwargs) Finds models using a model interface and a set of parameters.
Used to find models in model relationships.
- Return type
Optional
[List
[ModelBase
]]
-
class
pydent.models.
Code
(**data)[source] Bases:
pydent.base.ModelBase
A Code model.
The model initializer.
- Parameters
data (dict) – data to add to the model
-
_check_for_session
() Raises error if model is not connected to a session.
:raises NoSessionError
-
classmethod
_flatten_deserialized_data
(models, memo) Flattens all of the relationships found in the models, returning a rid: model dictionary.
- Return type
dict
-
_get_data
() Return the model’s data.
-
_get_deserialized_data
() Return the deserialized model data.
-
_model_schema
alias of
pydent.marshaller.base.CodeSchema
-
property
_primary_key
Returns the primary key (e.g. ‘id’) or the rid if id does not exist or is None.
-
_rid_dict
() Dictionary of all models attached to this model keyed by their rid.
-
add_data
(data) Initializes fake attributes that correspond to data.
-
anonymize
() Resets the primary key of the model and assigns a new rid.
Metatypes cannot be annonymized.
- Returns
self
-
append_to_many
(name, model) Appends a model to the many relationship.
- Parameters
name (str) – name of the relationship or attribute
model (ModelBase) – model to append
- Returns
None
- Return type
None
-
connect_to_session
(session) Connect model to a session.
- Parameters
session (
SessionABC
) – theAqSession
- Returns
None
- Raises
SessionAlreadySet – if session is already set
NoSessionError – if session is not a SessionABC type
-
copy
(keep=None) Provides a deepcopy of the model, but annonymizes the primary and global keys unless class is a metatype (e.g. OperationType, SampleType, FieldType) or class name is found in list of ‘keep’.
By default, inventory classes such as Sample, Item, and Collection are ‘kept’.
This specific usecase is that when copying whole plans, that the integrity of the inventory used in the operations is maintained. These are the items that refer to physical inventory in the laboratory and are referred to by their rids, and so it is important to that any of these inventory are always maintain their rids. Meaning in the lab, their is only ONE instance of the inventory. In Trident and Aquarium, there is only ONE instance of inventory that is referred to by its rid.
Similarly, any metatype model must also maintain their rid.
- Parameters
keep (
Optional
[bool
]) – list of model classes (as a list of strings) to keep un-anonymous- Return type
- Returns
copied model
-
dump
(only=None, include=None, ignore=None, include_model_type=False, include_uri=False) Dump (serialize) the Aquarium model instance to JSON.
- Parameters
only (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – dump only the provided keysinclude (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – include the provided nested dump keysignore (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – ignore the provided keysinclude_model_type (
bool
) – if True, include the model class type for each entry using the __model__ keyinclude_uri (
bool
) – if True, include a URI using the session URL and the tableized model class name using the __uri__ key. If a session is not attached, look for the url namespace in the ModelBase.DEFAULT_NAMESPACE class attribute, as in http://aquarium.org/samples/10.
- Return type
dict
- Returns
serialized model instance
-
classmethod
find
(session, model_id) Finds a model instance by its model_id.
- Return type
-
find_callback
(model_name, model_id) Finds a model using the model interface and model_id.
Used to find models in model relationships.
- Return type
-
get_deserialized
(name) Get deserialized data by name.
Deprecated since version 0.1.5a7: method will be removed in 0.2. Use self._get_deserialized_data[name] instead.
- Parameters
name – name of attribute
- Returns
-
classmethod
interface
(session) Creates a model interface from this class and a session.
This method can be overridden in model definitions for special cases.
- Return type
Union
[QueryInterface
,BrowserInterface
]
-
is_deserialized
(name) Check if a given key has already been deserialized.
New in version 0.1.5a7: Method added
- Parameters
name (
str
) – name of the attribute- Return type
bool
- Returns
True if key has been deserialized.
-
classmethod
load
(*args, **kwargs) Deserialize the data to a model.
- Parameters
data (dict) – data to deserialize
- Returns
the deserialized model
- Return type
-
classmethod
load_from
(data, owner=None) Create a new model instance from loaded attributes.
‘obj’ should have a o
-
model_schema
alias of
pydent.marshaller.base.CodeSchema
-
no_getter
(*_) Callback that always returns None.
-
refresh
() Refresh this model from data from the server.
- Returns
self
- Return type
self
-
reload
(data) Reload model attributes from new data.
- Parameters
data (dict) – data to update model instance
- Returns
model instance
- Return type
-
reset_field
(name) Reset the field descriptor to its placeholder value, returning the behavior.
New in version 0.1.5a7: Method added to reset deserialized attributes
- Parameters
name (
str
) – name of the attribute- Returns
None
-
property
session
The connected session instance.
-
property
uri
Return a URI for this model using the attached session url and tableized model name. For example, http://aquarium.org/samples/. If no session is attached, use the ModelBase.DEFAULT_NAMESPACE key for the url.
- Return type
str
- Returns
the instance URI
-
classmethod
where
(session, params) Finds a list of models by some parameters.
- Return type
Optional
[List
[ModelBase
]]
-
where_callback
(model_name, *args, **kwargs) Finds models using a model interface and a set of parameters.
Used to find models in model relationships.
- Return type
Optional
[List
[ModelBase
]]
-
class
pydent.models.
Collection
(object_type=None, location=None, data_associations=None, parts=None, part_associations=None, **kwargs)[source] Bases:
pydent.models.inventory.ItemLocationMixin
,pydent.models.data_associations.DataAssociatorMixin
,pydent.models.crud_mixin.SaveMixin
,pydent.models.controller_mixin.ControllerMixin
,pydent.base.ModelBase
A Collection model, such as a 96-well plate, which contains many parts, each of which can be associated with a different sample.
Initialize a new Collection.
Changed in version 0.1.5a10: Advanced indexing added for setting and getting samples and data associations
Setting samples using new advanced indexing
object_type = session.ObjectType.one(query='rows > 2 AND columns > 2') collection = session.Collection.new(object_type=object_type) # assign sample '1' to (0, 0) row=0, column=0 collection[0, 0] = 1 # assign sample '2' to (1, 2) row=1, column=2 collection[1, 2] = 2 # assign sample '3234' to row 3 collection[3] = 3234 # assign sample '444' to column 1 collection[:, 1] = 444 # assign sample '6' to the whole collection collection[:, :] = 6 # assign sample using Sample instance collection[2, 2] = session.Sample.one()
Getting samples using new advanced indexing
# get 2d matrix of sample ids print(collection.matrix) # or collection.sample_id_matrix # get 2d matrix of Samples assigned at each location print(collection.sample_matrix) # get 2d matrix of Parts assigned at each location print(collection.part_matrix) # get 2d matrix of PartAssociations assigned at each location collection.part_associations_matrix # get 2d matrix of values of DataAssociations at each location collection.data_matrix # get 2d matrix of DataAssociations at each location collection.data_association_matrix
Assigning data to locations
To assign data, you can use the advanced indexing on the data_matrix
collection.data_matrix[0, 0] = {'key': 'value'} collection.data_matrix[1] = {'key': 'value2'} collection.associate_to('key', 'value3', 3, 3)
You can delete associations using the following:
# delete 3, 3 collection.delete_association_at('key', 3, 3) # delete first three rows at column 3 collection.delete_association_at('key', slice(None, 3, None), 3) # delete all of the 'key' associations collection.delete_association_at('key', slice(None, None, None), slice(None, None, None))
- Parameters
object_type (
Optional
[ObjectType
]) –location (
Optional
[str
]) –data_associations (
Optional
[List
]) –parts (
Optional
[List
]) –part_associations (
Optional
[List
]) –kwargs –
-
_check_for_session
() Raises error if model is not connected to a session.
:raises NoSessionError
-
classmethod
_flatten_deserialized_data
(models, memo) Flattens all of the relationships found in the models, returning a rid: model dictionary.
- Return type
dict
-
_get_data
() Return the model’s data.
-
_get_deserialized_data
() Return the deserialized model data.
-
_model_schema
alias of
pydent.marshaller.base.CollectionSchema
-
property
_primary_key
Returns the primary key (e.g. ‘id’) or the rid if id does not exist or is None.
-
_rid_dict
() Dictionary of all models attached to this model keyed by their rid.
-
add_data
(data) Initializes fake attributes that correspond to data.
-
anonymize
() Resets the primary key of the model and assigns a new rid.
Metatypes cannot be annonymized.
- Returns
self
-
append_to_many
(name, model) Appends a model to the many relationship.
- Parameters
name (str) – name of the relationship or attribute
model (ModelBase) – model to append
- Returns
None
- Return type
None
-
as_item
()[source] Returns the Item object with the ID of this Collection.
-
assign_sample
(sample_id, pairs)[source] Assign sample id to the (row, column) pairs for the collection.
- Parameters
sample_id (
int
) – the sample id to assignpairs (
List
[Tuple
[int
,int
]]) – list of (row, column) tuples
- Returns
self
-
associate
(key, value, upload=None, create_new=False, save=None) Adds a data association with the key and value to this object.
- Parameters
key (str) – Key of the association
value (dict | str | int | float) – a json serializable object
upload (File) – optional file to upload
create_new – if True (default) will create a new association instead of updating the existing association.
- Tuype create_new
bool
- Returns
newly created or updated data association
- Return type
-
associate_file
(key, value, file, job_id=None) Associate a file.
- Parameters
key (str or json) – association key
value (str or json) – association value
file (file object) – file to create
Upload
job_id (int) – optional job_id to associate the
Upload
- Returns
new data association
- Return type
-
associate_file_from_path
(key, value, filepath, job_id=None) Associate a file from a filepath.
- Parameters
key (str or json) – association key
value (str or json) – association value
filepath (str) – path to file to create
Upload
job_id (int) – optional job_id to associate the
Upload
- Returns
new data association
- Return type
-
connect_to_session
(session) Connect model to a session.
- Parameters
session (
SessionABC
) – theAqSession
- Returns
None
- Raises
SessionAlreadySet – if session is already set
NoSessionError – if session is not a SessionABC type
-
controller_method
(controller_method, table, model_id, data, params=None) Method for create, updating, and deleting models.
- Parameters
controller_method (
str
) – Name of the controller methodtable (
str
) – Table name of model (e.g. ‘samples’ or ‘data_associations’)model_id (
Union
[str
,int
,None
]) – Optional model_id (not required for ‘post’)data (
Optional
[dict
]) – dataparams – controller parameters
- Returns
json formatted server response
- Return type
dict
-
copy
(keep=None) Provides a deepcopy of the model, but annonymizes the primary and global keys unless class is a metatype (e.g. OperationType, SampleType, FieldType) or class name is found in list of ‘keep’.
By default, inventory classes such as Sample, Item, and Collection are ‘kept’.
This specific usecase is that when copying whole plans, that the integrity of the inventory used in the operations is maintained. These are the items that refer to physical inventory in the laboratory and are referred to by their rids, and so it is important to that any of these inventory are always maintain their rids. Meaning in the lab, their is only ONE instance of the inventory. In Trident and Aquarium, there is only ONE instance of inventory that is referred to by its rid.
Similarly, any metatype model must also maintain their rid.
- Parameters
keep (
Optional
[bool
]) – list of model classes (as a list of strings) to keep un-anonymous- Return type
- Returns
copied model
-
create
()[source] Create a new empty collection on the server.
-
property
data_association_matrix
Return a view of.
New in version 0.1.5a9.
- Return type
MatrixMapping
[DataAssociation
]- Returns
collection as a view of DataAssociations
-
property
data_matrix
Return a view of values from the.
New in version 0.1.5a9.
- Return type
MatrixMapping
[Any
]- Returns
collection as a view of DataAssociation values
-
dump
(only=None, include=None, ignore=None, include_model_type=False, include_uri=False) Dump (serialize) the Aquarium model instance to JSON.
- Parameters
only (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – dump only the provided keysinclude (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – include the provided nested dump keysignore (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – ignore the provided keysinclude_model_type (
bool
) – if True, include the model class type for each entry using the __model__ keyinclude_uri (
bool
) – if True, include a URI using the session URL and the tableized model class name using the __uri__ key. If a session is not attached, look for the url namespace in the ModelBase.DEFAULT_NAMESPACE class attribute, as in http://aquarium.org/samples/10.
- Return type
dict
- Returns
serialized model instance
-
classmethod
find
(session, model_id) Finds a model instance by its model_id.
- Return type
-
find_callback
(model_name, model_id) Finds a model using the model interface and model_id.
Used to find models in model relationships.
- Return type
-
get_deserialized
(name) Get deserialized data by name.
Deprecated since version 0.1.5a7: method will be removed in 0.2. Use self._get_deserialized_data[name] instead.
- Parameters
name – name of attribute
- Returns
-
classmethod
interface
(session) Creates a model interface from this class and a session.
This method can be overridden in model definitions for special cases.
- Return type
Union
[QueryInterface
,BrowserInterface
]
-
is_deserialized
(name) Check if a given key has already been deserialized.
New in version 0.1.5a7: Method added
- Parameters
name (
str
) – name of the attribute- Return type
bool
- Returns
True if key has been deserialized.
-
classmethod
load
(*args, **kwargs) Deserialize the data to a model.
- Parameters
data (dict) – data to deserialize
- Returns
the deserialized model
- Return type
-
classmethod
load_from
(data, owner=None) Create a new model instance from loaded attributes.
‘obj’ should have a o
-
make
() Makes the Item on the Aquarium server.
Requires this Item to be connected to a session.
-
property
matrix
Returns the matrix of Samples for this Collection.
(Consider using samples of parts directly.)
Changed in version 0.1.5a9: Refactored using MatrixMapping
-
model_schema
alias of
pydent.marshaller.base.CollectionSchema
-
no_getter
(*_) Callback that always returns None.
-
part
(row, col)[source] Returns the part Item at (row, col) of this Collection (zero- based).
- Return type
Item
-
property
part_association_matrix
Return a view of part associations.
New in version 0.1.5a9.
- Return type
MatrixMapping
[PartAssociation
]- Returns
collection as a view of PartAssociations
-
property
part_matrix
Return a view of
Item
New in version 0.1.5a9.
- Return type
MatrixMapping
[Item
]- Returns
collection as a view of Items (Parts)
-
refresh
() Refresh this model from data from the server.
- Returns
self
- Return type
self
-
reload
(data) Reload model attributes from new data.
- Parameters
data (dict) – data to update model instance
- Returns
model instance
- Return type
-
remove_sample
(pairs)[source] Clear the sample_id assigment in the (row, column) pairs for the collection.
- Parameters
pairs (
List
[Tuple
[int
,int
]]) – list of (row, column) tuples- Returns
self
-
reset_field
(name) Reset the field descriptor to its placeholder value, returning the behavior.
New in version 0.1.5a7: Method added to reset deserialized attributes
- Parameters
name (
str
) – name of the attribute- Returns
None
-
property
sample_id_matrix
Return a view of sample_ids
Sample
New in version 0.1.5a9.
- Return type
MatrixMapping
[int
]- Returns
collection as a view of Sample.ids
-
property
sample_matrix
Return a view of
Sample
New in version 0.1.5a9.
- Return type
MatrixMapping
[Sample
]- Returns
collection as a view of Samples
-
property
session
The connected session instance.
-
update
()[source] Updates the item.
Will update the data associations and its location.
-
property
uri
Return a URI for this model using the attached session url and tableized model name. For example, http://aquarium.org/samples/. If no session is attached, use the ModelBase.DEFAULT_NAMESPACE key for the url.
- Return type
str
- Returns
the instance URI
-
classmethod
where
(session, params) Finds a list of models by some parameters.
- Return type
Optional
[List
[ModelBase
]]
-
where_callback
(model_name, *args, **kwargs) Finds models using a model interface and a set of parameters.
Used to find models in model relationships.
- Return type
Optional
[List
[ModelBase
]]
-
class
pydent.models.
DataAssociation
(**data)[source] Bases:
pydent.models.crud_mixin.JSONDeleteMixin
,pydent.models.crud_mixin.JSONSaveMixin
,pydent.base.ModelBase
A DataAssociation model.
The model initializer.
- Parameters
data (dict) – data to add to the model
-
_check_for_session
() Raises error if model is not connected to a session.
:raises NoSessionError
-
classmethod
_flatten_deserialized_data
(models, memo) Flattens all of the relationships found in the models, returning a rid: model dictionary.
- Return type
dict
-
_get_data
() Return the model’s data.
-
_get_deserialized_data
() Return the deserialized model data.
-
_model_schema
alias of
pydent.marshaller.base.DataAssociationSchema
-
property
_primary_key
Returns the primary key (e.g. ‘id’) or the rid if id does not exist or is None.
-
_rid_dict
() Dictionary of all models attached to this model keyed by their rid.
-
add_data
(data) Initializes fake attributes that correspond to data.
-
anonymize
() Resets the primary key of the model and assigns a new rid.
Metatypes cannot be annonymized.
- Returns
self
-
append_to_many
(name, model) Appends a model to the many relationship.
- Parameters
name (str) – name of the relationship or attribute
model (ModelBase) – model to append
- Returns
None
- Return type
None
-
connect_to_session
(session) Connect model to a session.
- Parameters
session (
SessionABC
) – theAqSession
- Returns
None
- Raises
SessionAlreadySet – if session is already set
NoSessionError – if session is not a SessionABC type
-
copy
(keep=None) Provides a deepcopy of the model, but annonymizes the primary and global keys unless class is a metatype (e.g. OperationType, SampleType, FieldType) or class name is found in list of ‘keep’.
By default, inventory classes such as Sample, Item, and Collection are ‘kept’.
This specific usecase is that when copying whole plans, that the integrity of the inventory used in the operations is maintained. These are the items that refer to physical inventory in the laboratory and are referred to by their rids, and so it is important to that any of these inventory are always maintain their rids. Meaning in the lab, their is only ONE instance of the inventory. In Trident and Aquarium, there is only ONE instance of inventory that is referred to by its rid.
Similarly, any metatype model must also maintain their rid.
- Parameters
keep (
Optional
[bool
]) – list of model classes (as a list of strings) to keep un-anonymous- Return type
- Returns
copied model
-
dump
(only=None, include=None, ignore=None, include_model_type=False, include_uri=False) Dump (serialize) the Aquarium model instance to JSON.
- Parameters
only (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – dump only the provided keysinclude (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – include the provided nested dump keysignore (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – ignore the provided keysinclude_model_type (
bool
) – if True, include the model class type for each entry using the __model__ keyinclude_uri (
bool
) – if True, include a URI using the session URL and the tableized model class name using the __uri__ key. If a session is not attached, look for the url namespace in the ModelBase.DEFAULT_NAMESPACE class attribute, as in http://aquarium.org/samples/10.
- Return type
dict
- Returns
serialized model instance
-
classmethod
find
(session, model_id) Finds a model instance by its model_id.
- Return type
-
find_callback
(model_name, model_id) Finds a model using the model interface and model_id.
Used to find models in model relationships.
- Return type
-
get_deserialized
(name) Get deserialized data by name.
Deprecated since version 0.1.5a7: method will be removed in 0.2. Use self._get_deserialized_data[name] instead.
- Parameters
name – name of attribute
- Returns
-
classmethod
interface
(session) Creates a model interface from this class and a session.
This method can be overridden in model definitions for special cases.
- Return type
Union
[QueryInterface
,BrowserInterface
]
-
is_deserialized
(name) Check if a given key has already been deserialized.
New in version 0.1.5a7: Method added
- Parameters
name (
str
) – name of the attribute- Return type
bool
- Returns
True if key has been deserialized.
-
classmethod
load
(*args, **kwargs) Deserialize the data to a model.
- Parameters
data (dict) – data to deserialize
- Returns
the deserialized model
- Return type
-
classmethod
load_from
(data, owner=None) Create a new model instance from loaded attributes.
‘obj’ should have a o
-
model_schema
alias of
pydent.marshaller.base.DataAssociationSchema
-
no_getter
(*_) Callback that always returns None.
-
refresh
() Refresh this model from data from the server.
- Returns
self
- Return type
self
-
reload
(data) Reload model attributes from new data.
- Parameters
data (dict) – data to update model instance
- Returns
model instance
- Return type
-
reset_field
(name) Reset the field descriptor to its placeholder value, returning the behavior.
New in version 0.1.5a7: Method added to reset deserialized attributes
- Parameters
name (
str
) – name of the attribute- Returns
None
-
property
session
The connected session instance.
-
property
uri
Return a URI for this model using the attached session url and tableized model name. For example, http://aquarium.org/samples/. If no session is attached, use the ModelBase.DEFAULT_NAMESPACE key for the url.
- Return type
str
- Returns
the instance URI
-
classmethod
where
(session, params) Finds a list of models by some parameters.
- Return type
Optional
[List
[ModelBase
]]
-
where_callback
(model_name, *args, **kwargs) Finds models using a model interface and a set of parameters.
Used to find models in model relationships.
- Return type
Optional
[List
[ModelBase
]]
-
class
pydent.models.
FieldType
(name=None, ftype=None, array=None, choices=None, operation_type=None, preferred_field_type_id=None, preferred_operation_type_id=None, required=None, routing=None, role=None, parent_class=None, parent_id=None, sample_type=None, aft_stype_and_objtype=(), allowable_field_types=None)[source] Bases:
pydent.models.field_value_mixins.FieldMixin
,pydent.base.ModelBase
A FieldType model.
-
_check_for_session
() Raises error if model is not connected to a session.
:raises NoSessionError
-
classmethod
_flatten_deserialized_data
(models, memo) Flattens all of the relationships found in the models, returning a rid: model dictionary.
- Return type
dict
-
_get_data
() Return the model’s data.
-
_get_deserialized_data
() Return the deserialized model data.
-
_model_schema
alias of
pydent.marshaller.base.FieldTypeSchema
-
property
_primary_key
Returns the primary key (e.g. ‘id’) or the rid if id does not exist or is None.
-
_rid_dict
() Dictionary of all models attached to this model keyed by their rid.
-
add_data
(data) Initializes fake attributes that correspond to data.
-
anonymize
() Resets the primary key of the model and assigns a new rid.
Metatypes cannot be annonymized.
- Returns
self
-
append_to_many
(name, model) Appends a model to the many relationship.
- Parameters
name (str) – name of the relationship or attribute
model (ModelBase) – model to append
- Returns
None
- Return type
None
-
connect_to_session
(session) Connect model to a session.
- Parameters
session (
SessionABC
) – theAqSession
- Returns
None
- Raises
SessionAlreadySet – if session is already set
NoSessionError – if session is not a SessionABC type
-
copy
(keep=None) Provides a deepcopy of the model, but annonymizes the primary and global keys unless class is a metatype (e.g. OperationType, SampleType, FieldType) or class name is found in list of ‘keep’.
By default, inventory classes such as Sample, Item, and Collection are ‘kept’.
This specific usecase is that when copying whole plans, that the integrity of the inventory used in the operations is maintained. These are the items that refer to physical inventory in the laboratory and are referred to by their rids, and so it is important to that any of these inventory are always maintain their rids. Meaning in the lab, their is only ONE instance of the inventory. In Trident and Aquarium, there is only ONE instance of inventory that is referred to by its rid.
Similarly, any metatype model must also maintain their rid.
- Parameters
keep (
Optional
[bool
]) – list of model classes (as a list of strings) to keep un-anonymous- Return type
- Returns
copied model
-
dump
(only=None, include=None, ignore=None, include_model_type=False, include_uri=False) Dump (serialize) the Aquarium model instance to JSON.
- Parameters
only (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – dump only the provided keysinclude (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – include the provided nested dump keysignore (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – ignore the provided keysinclude_model_type (
bool
) – if True, include the model class type for each entry using the __model__ keyinclude_uri (
bool
) – if True, include a URI using the session URL and the tableized model class name using the __uri__ key. If a session is not attached, look for the url namespace in the ModelBase.DEFAULT_NAMESPACE class attribute, as in http://aquarium.org/samples/10.
- Return type
dict
- Returns
serialized model instance
-
classmethod
find
(session, model_id) Finds a model instance by its model_id.
- Return type
-
find_callback
(model_name, model_id) Finds a model using the model interface and model_id.
Used to find models in model relationships.
- Return type
-
find_field_parent
(model_name, model_id) Callback for finding operation_type or sample_type.
If parent_class does not match the expected nested model name (OperationType or SampleType), callback will return None
-
get_deserialized
(name) Get deserialized data by name.
Deprecated since version 0.1.5a7: method will be removed in 0.2. Use self._get_deserialized_data[name] instead.
- Parameters
name – name of attribute
- Returns
-
initialize_field_value
(field_value=None, parent=None)[source] Updates or initializes a new
FieldValue
from this FieldType.- Parameters
field_value (FieldValue) – optional FieldValue to update with this FieldType
- Returns
updated FieldValue
- Return type
-
classmethod
interface
(session) Creates a model interface from this class and a session.
This method can be overridden in model definitions for special cases.
- Return type
Union
[QueryInterface
,BrowserInterface
]
-
is_deserialized
(name) Check if a given key has already been deserialized.
New in version 0.1.5a7: Method added
- Parameters
name (
str
) – name of the attribute- Return type
bool
- Returns
True if key has been deserialized.
-
classmethod
load
(*args, **kwargs) Deserialize the data to a model.
- Parameters
data (dict) – data to deserialize
- Returns
the deserialized model
- Return type
-
classmethod
load_from
(data, owner=None) Create a new model instance from loaded attributes.
‘obj’ should have a o
-
model_schema
alias of
pydent.marshaller.base.FieldTypeSchema
-
no_getter
(*_) Callback that always returns None.
-
refresh
() Refresh this model from data from the server.
- Returns
self
- Return type
self
-
reload
(data) Reload model attributes from new data.
- Parameters
data (dict) – data to update model instance
- Returns
model instance
- Return type
-
reset_field
(name) Reset the field descriptor to its placeholder value, returning the behavior.
New in version 0.1.5a7: Method added to reset deserialized attributes
- Parameters
name (
str
) – name of the attribute- Returns
None
-
property
session
The connected session instance.
-
property
uri
Return a URI for this model using the attached session url and tableized model name. For example, http://aquarium.org/samples/. If no session is attached, use the ModelBase.DEFAULT_NAMESPACE key for the url.
- Return type
str
- Returns
the instance URI
-
classmethod
where
(session, params) Finds a list of models by some parameters.
- Return type
Optional
[List
[ModelBase
]]
-
where_callback
(model_name, *args, **kwargs) Finds models using a model interface and a set of parameters.
Used to find models in model relationships.
- Return type
Optional
[List
[ModelBase
]]
-
-
class
pydent.models.
FieldValue
(name=None, role=None, parent_class=None, parent_id=None, field_type=None, sample=None, value=None, item=None, container=None)[source] Bases:
pydent.models.field_value_mixins.FieldMixin
,pydent.models.crud_mixin.JSONSaveMixin
,pydent.models.crud_mixin.JSONDeleteMixin
,pydent.base.ModelBase
A FieldValue model. One of the more complex models.
Changed in version 0.1.2: FieldValues no longer
have’wires_as_source’ or ‘wires_as_dest’ fields. Wires may only be accessed via plans only or via the FieldValue instance method ‘get_wires,’ which accesses the FieldValues operation and its Plan to obtain wires.
- Parameters
value –
sample –
container –
item –
-
_check_for_session
() Raises error if model is not connected to a session.
:raises NoSessionError
-
classmethod
_flatten_deserialized_data
(models, memo) Flattens all of the relationships found in the models, returning a rid: model dictionary.
- Return type
dict
-
_get_data
() Return the model’s data.
-
_get_deserialized_data
() Return the deserialized model data.
-
_model_schema
alias of
pydent.marshaller.base.FieldValueSchema
-
property
_primary_key
Returns the primary key (e.g. ‘id’) or the rid if id does not exist or is None.
-
_rid_dict
() Dictionary of all models attached to this model keyed by their rid.
-
add_data
(data) Initializes fake attributes that correspond to data.
-
anonymize
() Resets the primary key of the model and assigns a new rid.
Metatypes cannot be annonymized.
- Returns
self
-
append_to_many
(name, model) Appends a model to the many relationship.
- Parameters
name (str) – name of the relationship or attribute
model (ModelBase) – model to append
- Returns
None
- Return type
None
-
choose_item
(first=True)[source] Set the item associated with the field value.
-
compatible_items
()[source] Find items compatible with the field value.
-
connect_to_session
(session) Connect model to a session.
- Parameters
session (
SessionABC
) – theAqSession
- Returns
None
- Raises
SessionAlreadySet – if session is already set
NoSessionError – if session is not a SessionABC type
-
copy
(keep=None) Provides a deepcopy of the model, but annonymizes the primary and global keys unless class is a metatype (e.g. OperationType, SampleType, FieldType) or class name is found in list of ‘keep’.
By default, inventory classes such as Sample, Item, and Collection are ‘kept’.
This specific usecase is that when copying whole plans, that the integrity of the inventory used in the operations is maintained. These are the items that refer to physical inventory in the laboratory and are referred to by their rids, and so it is important to that any of these inventory are always maintain their rids. Meaning in the lab, their is only ONE instance of the inventory. In Trident and Aquarium, there is only ONE instance of inventory that is referred to by its rid.
Similarly, any metatype model must also maintain their rid.
- Parameters
keep (
Optional
[bool
]) – list of model classes (as a list of strings) to keep un-anonymous- Return type
- Returns
copied model
-
dump
(only=None, include=None, ignore=None, include_model_type=False, include_uri=False) Dump (serialize) the Aquarium model instance to JSON.
- Parameters
only (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – dump only the provided keysinclude (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – include the provided nested dump keysignore (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – ignore the provided keysinclude_model_type (
bool
) – if True, include the model class type for each entry using the __model__ keyinclude_uri (
bool
) – if True, include a URI using the session URL and the tableized model class name using the __uri__ key. If a session is not attached, look for the url namespace in the ModelBase.DEFAULT_NAMESPACE class attribute, as in http://aquarium.org/samples/10.
- Return type
dict
- Returns
serialized model instance
-
classmethod
find
(session, model_id) Finds a model instance by its model_id.
- Return type
-
find_callback
(model_name, model_id) Finds a model using the model interface and model_id.
Used to find models in model relationships.
- Return type
-
find_field_parent
(model_name, model_id) Callback for finding operation_type or sample_type.
If parent_class does not match the expected nested model name (OperationType or SampleType), callback will return None
-
get_deserialized
(name) Get deserialized data by name.
Deprecated since version 0.1.5a7: method will be removed in 0.2. Use self._get_deserialized_data[name] instead.
- Parameters
name – name of attribute
- Returns
-
get_sid
()[source] The FieldValues sample identifier.
-
classmethod
interface
(session) Creates a model interface from this class and a session.
This method can be overridden in model definitions for special cases.
- Return type
Union
[QueryInterface
,BrowserInterface
]
-
is_deserialized
(name) Check if a given key has already been deserialized.
New in version 0.1.5a7: Method added
- Parameters
name (
str
) – name of the attribute- Return type
bool
- Returns
True if key has been deserialized.
-
classmethod
load
(*args, **kwargs) Deserialize the data to a model.
- Parameters
data (dict) – data to deserialize
- Returns
the deserialized model
- Return type
-
classmethod
load_from
(data, owner=None) Create a new model instance from loaded attributes.
‘obj’ should have a o
-
model_schema
alias of
pydent.marshaller.base.FieldValueSchema
-
no_getter
(*_) Callback that always returns None.
-
refresh
() Refresh this model from data from the server.
- Returns
self
- Return type
self
-
reload
(data) Reload model attributes from new data.
- Parameters
data (dict) – data to update model instance
- Returns
model instance
- Return type
-
reset
()[source] Resets the inputs of the field_value.
-
reset_field
(name) Reset the field descriptor to its placeholder value, returning the behavior.
New in version 0.1.5a7: Method added to reset deserialized attributes
- Parameters
name (
str
) – name of the attribute- Returns
None
-
property
session
The connected session instance.
-
set_field_type
(field_type)[source] Sets properties from a field_type.
-
property
uri
Return a URI for this model using the attached session url and tableized model name. For example, http://aquarium.org/samples/. If no session is attached, use the ModelBase.DEFAULT_NAMESPACE key for the url.
- Return type
str
- Returns
the instance URI
-
classmethod
where
(session, params) Finds a list of models by some parameters.
- Return type
Optional
[List
[ModelBase
]]
-
where_callback
(model_name, *args, **kwargs) Finds models using a model interface and a set of parameters.
Used to find models in model relationships.
- Return type
Optional
[List
[ModelBase
]]
-
class
pydent.models.
Group
(**data)[source] Bases:
pydent.base.ModelBase
A Group model.
The model initializer.
- Parameters
data (dict) – data to add to the model
-
_check_for_session
() Raises error if model is not connected to a session.
:raises NoSessionError
-
classmethod
_flatten_deserialized_data
(models, memo) Flattens all of the relationships found in the models, returning a rid: model dictionary.
- Return type
dict
-
_get_data
() Return the model’s data.
-
_get_deserialized_data
() Return the deserialized model data.
-
_model_schema
alias of
pydent.marshaller.base.GroupSchema
-
property
_primary_key
Returns the primary key (e.g. ‘id’) or the rid if id does not exist or is None.
-
_rid_dict
() Dictionary of all models attached to this model keyed by their rid.
-
add_data
(data) Initializes fake attributes that correspond to data.
-
anonymize
() Resets the primary key of the model and assigns a new rid.
Metatypes cannot be annonymized.
- Returns
self
-
append_to_many
(name, model) Appends a model to the many relationship.
- Parameters
name (str) – name of the relationship or attribute
model (ModelBase) – model to append
- Returns
None
- Return type
None
-
connect_to_session
(session) Connect model to a session.
- Parameters
session (
SessionABC
) – theAqSession
- Returns
None
- Raises
SessionAlreadySet – if session is already set
NoSessionError – if session is not a SessionABC type
-
copy
(keep=None) Provides a deepcopy of the model, but annonymizes the primary and global keys unless class is a metatype (e.g. OperationType, SampleType, FieldType) or class name is found in list of ‘keep’.
By default, inventory classes such as Sample, Item, and Collection are ‘kept’.
This specific usecase is that when copying whole plans, that the integrity of the inventory used in the operations is maintained. These are the items that refer to physical inventory in the laboratory and are referred to by their rids, and so it is important to that any of these inventory are always maintain their rids. Meaning in the lab, their is only ONE instance of the inventory. In Trident and Aquarium, there is only ONE instance of inventory that is referred to by its rid.
Similarly, any metatype model must also maintain their rid.
- Parameters
keep (
Optional
[bool
]) – list of model classes (as a list of strings) to keep un-anonymous- Return type
- Returns
copied model
-
dump
(only=None, include=None, ignore=None, include_model_type=False, include_uri=False) Dump (serialize) the Aquarium model instance to JSON.
- Parameters
only (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – dump only the provided keysinclude (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – include the provided nested dump keysignore (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – ignore the provided keysinclude_model_type (
bool
) – if True, include the model class type for each entry using the __model__ keyinclude_uri (
bool
) – if True, include a URI using the session URL and the tableized model class name using the __uri__ key. If a session is not attached, look for the url namespace in the ModelBase.DEFAULT_NAMESPACE class attribute, as in http://aquarium.org/samples/10.
- Return type
dict
- Returns
serialized model instance
-
classmethod
find
(session, model_id) Finds a model instance by its model_id.
- Return type
-
find_callback
(model_name, model_id) Finds a model using the model interface and model_id.
Used to find models in model relationships.
- Return type
-
get_deserialized
(name) Get deserialized data by name.
Deprecated since version 0.1.5a7: method will be removed in 0.2. Use self._get_deserialized_data[name] instead.
- Parameters
name – name of attribute
- Returns
-
classmethod
interface
(session) Creates a model interface from this class and a session.
This method can be overridden in model definitions for special cases.
- Return type
Union
[QueryInterface
,BrowserInterface
]
-
is_deserialized
(name) Check if a given key has already been deserialized.
New in version 0.1.5a7: Method added
- Parameters
name (
str
) – name of the attribute- Return type
bool
- Returns
True if key has been deserialized.
-
classmethod
load
(*args, **kwargs) Deserialize the data to a model.
- Parameters
data (dict) – data to deserialize
- Returns
the deserialized model
- Return type
-
classmethod
load_from
(data, owner=None) Create a new model instance from loaded attributes.
‘obj’ should have a o
-
model_schema
alias of
pydent.marshaller.base.GroupSchema
-
no_getter
(*_) Callback that always returns None.
-
refresh
() Refresh this model from data from the server.
- Returns
self
- Return type
self
-
reload
(data) Reload model attributes from new data.
- Parameters
data (dict) – data to update model instance
- Returns
model instance
- Return type
-
reset_field
(name) Reset the field descriptor to its placeholder value, returning the behavior.
New in version 0.1.5a7: Method added to reset deserialized attributes
- Parameters
name (
str
) – name of the attribute- Returns
None
-
property
session
The connected session instance.
-
property
uri
Return a URI for this model using the attached session url and tableized model name. For example, http://aquarium.org/samples/. If no session is attached, use the ModelBase.DEFAULT_NAMESPACE key for the url.
- Return type
str
- Returns
the instance URI
-
classmethod
where
(session, params) Finds a list of models by some parameters.
- Return type
Optional
[List
[ModelBase
]]
-
where_callback
(model_name, *args, **kwargs) Finds models using a model interface and a set of parameters.
Used to find models in model relationships.
- Return type
Optional
[List
[ModelBase
]]
-
class
pydent.models.
Invoice
(**data)[source] Bases:
pydent.base.ModelBase
A Invoice model.
The model initializer.
- Parameters
data (dict) – data to add to the model
-
_check_for_session
() Raises error if model is not connected to a session.
:raises NoSessionError
-
classmethod
_flatten_deserialized_data
(models, memo) Flattens all of the relationships found in the models, returning a rid: model dictionary.
- Return type
dict
-
_get_data
() Return the model’s data.
-
_get_deserialized_data
() Return the deserialized model data.
-
_model_schema
alias of
pydent.marshaller.base.InvoiceSchema
-
property
_primary_key
Returns the primary key (e.g. ‘id’) or the rid if id does not exist or is None.
-
_rid_dict
() Dictionary of all models attached to this model keyed by their rid.
-
add_data
(data) Initializes fake attributes that correspond to data.
-
anonymize
() Resets the primary key of the model and assigns a new rid.
Metatypes cannot be annonymized.
- Returns
self
-
append_to_many
(name, model) Appends a model to the many relationship.
- Parameters
name (str) – name of the relationship or attribute
model (ModelBase) – model to append
- Returns
None
- Return type
None
-
connect_to_session
(session) Connect model to a session.
- Parameters
session (
SessionABC
) – theAqSession
- Returns
None
- Raises
SessionAlreadySet – if session is already set
NoSessionError – if session is not a SessionABC type
-
copy
(keep=None) Provides a deepcopy of the model, but annonymizes the primary and global keys unless class is a metatype (e.g. OperationType, SampleType, FieldType) or class name is found in list of ‘keep’.
By default, inventory classes such as Sample, Item, and Collection are ‘kept’.
This specific usecase is that when copying whole plans, that the integrity of the inventory used in the operations is maintained. These are the items that refer to physical inventory in the laboratory and are referred to by their rids, and so it is important to that any of these inventory are always maintain their rids. Meaning in the lab, their is only ONE instance of the inventory. In Trident and Aquarium, there is only ONE instance of inventory that is referred to by its rid.
Similarly, any metatype model must also maintain their rid.
- Parameters
keep (
Optional
[bool
]) – list of model classes (as a list of strings) to keep un-anonymous- Return type
- Returns
copied model
-
dump
(only=None, include=None, ignore=None, include_model_type=False, include_uri=False) Dump (serialize) the Aquarium model instance to JSON.
- Parameters
only (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – dump only the provided keysinclude (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – include the provided nested dump keysignore (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – ignore the provided keysinclude_model_type (
bool
) – if True, include the model class type for each entry using the __model__ keyinclude_uri (
bool
) – if True, include a URI using the session URL and the tableized model class name using the __uri__ key. If a session is not attached, look for the url namespace in the ModelBase.DEFAULT_NAMESPACE class attribute, as in http://aquarium.org/samples/10.
- Return type
dict
- Returns
serialized model instance
-
classmethod
find
(session, model_id) Finds a model instance by its model_id.
- Return type
-
find_callback
(model_name, model_id) Finds a model using the model interface and model_id.
Used to find models in model relationships.
- Return type
-
get_deserialized
(name) Get deserialized data by name.
Deprecated since version 0.1.5a7: method will be removed in 0.2. Use self._get_deserialized_data[name] instead.
- Parameters
name – name of attribute
- Returns
-
classmethod
interface
(session) Creates a model interface from this class and a session.
This method can be overridden in model definitions for special cases.
- Return type
Union
[QueryInterface
,BrowserInterface
]
-
is_deserialized
(name) Check if a given key has already been deserialized.
New in version 0.1.5a7: Method added
- Parameters
name (
str
) – name of the attribute- Return type
bool
- Returns
True if key has been deserialized.
-
classmethod
load
(*args, **kwargs) Deserialize the data to a model.
- Parameters
data (dict) – data to deserialize
- Returns
the deserialized model
- Return type
-
classmethod
load_from
(data, owner=None) Create a new model instance from loaded attributes.
‘obj’ should have a o
-
model_schema
alias of
pydent.marshaller.base.InvoiceSchema
-
no_getter
(*_) Callback that always returns None.
-
refresh
() Refresh this model from data from the server.
- Returns
self
- Return type
self
-
reload
(data) Reload model attributes from new data.
- Parameters
data (dict) – data to update model instance
- Returns
model instance
- Return type
-
reset_field
(name) Reset the field descriptor to its placeholder value, returning the behavior.
New in version 0.1.5a7: Method added to reset deserialized attributes
- Parameters
name (
str
) – name of the attribute- Returns
None
-
property
session
The connected session instance.
-
property
uri
Return a URI for this model using the attached session url and tableized model name. For example, http://aquarium.org/samples/. If no session is attached, use the ModelBase.DEFAULT_NAMESPACE key for the url.
- Return type
str
- Returns
the instance URI
-
classmethod
where
(session, params) Finds a list of models by some parameters.
- Return type
Optional
[List
[ModelBase
]]
-
where_callback
(model_name, *args, **kwargs) Finds models using a model interface and a set of parameters.
Used to find models in model relationships.
- Return type
Optional
[List
[ModelBase
]]
-
class
pydent.models.
Item
(sample_id=None, sample=None, object_type=None, object_type_id=None, location=None)[source] Bases:
pydent.models.data_associations.DataAssociatorMixin
,pydent.models.inventory.ItemLocationMixin
,pydent.base.ModelBase
A physical object in the lab, which a location and unique id.
-
_check_for_session
() Raises error if model is not connected to a session.
:raises NoSessionError
-
classmethod
_flatten_deserialized_data
(models, memo) Flattens all of the relationships found in the models, returning a rid: model dictionary.
- Return type
dict
-
_get_data
() Return the model’s data.
-
_get_deserialized_data
() Return the deserialized model data.
-
_model_schema
alias of
pydent.marshaller.base.ItemSchema
-
property
_primary_key
Returns the primary key (e.g. ‘id’) or the rid if id does not exist or is None.
-
_rid_dict
() Dictionary of all models attached to this model keyed by their rid.
-
add_data
(data) Initializes fake attributes that correspond to data.
-
anonymize
() Resets the primary key of the model and assigns a new rid.
Metatypes cannot be annonymized.
- Returns
self
-
append_to_many
(name, model) Appends a model to the many relationship.
- Parameters
name (str) – name of the relationship or attribute
model (ModelBase) – model to append
- Returns
None
- Return type
None
-
as_collection
()[source] Returns the Collection object with the ID of this Item, which must be a collection.
Returns None if this Item is not a collection.
-
associate
(key, value, upload=None, create_new=False, save=None) Adds a data association with the key and value to this object.
- Parameters
key (str) – Key of the association
value (dict | str | int | float) – a json serializable object
upload (File) – optional file to upload
create_new – if True (default) will create a new association instead of updating the existing association.
- Tuype create_new
bool
- Returns
newly created or updated data association
- Return type
-
associate_file
(key, value, file, job_id=None) Associate a file.
- Parameters
key (str or json) – association key
value (str or json) – association value
file (file object) – file to create
Upload
job_id (int) – optional job_id to associate the
Upload
- Returns
new data association
- Return type
-
associate_file_from_path
(key, value, filepath, job_id=None) Associate a file from a filepath.
- Parameters
key (str or json) – association key
value (str or json) – association value
filepath (str) – path to file to create
Upload
job_id (int) – optional job_id to associate the
Upload
- Returns
new data association
- Return type
-
connect_to_session
(session) Connect model to a session.
- Parameters
session (
SessionABC
) – theAqSession
- Returns
None
- Raises
SessionAlreadySet – if session is already set
NoSessionError – if session is not a SessionABC type
-
property
containing_collection
Returns the collection of which this Item is a part.
Returns the collection object if the Item is a part, otherwise returns None.
-
copy
(keep=None) Provides a deepcopy of the model, but annonymizes the primary and global keys unless class is a metatype (e.g. OperationType, SampleType, FieldType) or class name is found in list of ‘keep’.
By default, inventory classes such as Sample, Item, and Collection are ‘kept’.
This specific usecase is that when copying whole plans, that the integrity of the inventory used in the operations is maintained. These are the items that refer to physical inventory in the laboratory and are referred to by their rids, and so it is important to that any of these inventory are always maintain their rids. Meaning in the lab, their is only ONE instance of the inventory. In Trident and Aquarium, there is only ONE instance of inventory that is referred to by its rid.
Similarly, any metatype model must also maintain their rid.
- Parameters
keep (
Optional
[bool
]) – list of model classes (as a list of strings) to keep un-anonymous- Return type
- Returns
copied model
-
dump
(only=None, include=None, ignore=None, include_model_type=False, include_uri=False) Dump (serialize) the Aquarium model instance to JSON.
- Parameters
only (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – dump only the provided keysinclude (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – include the provided nested dump keysignore (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – ignore the provided keysinclude_model_type (
bool
) – if True, include the model class type for each entry using the __model__ keyinclude_uri (
bool
) – if True, include a URI using the session URL and the tableized model class name using the __uri__ key. If a session is not attached, look for the url namespace in the ModelBase.DEFAULT_NAMESPACE class attribute, as in http://aquarium.org/samples/10.
- Return type
dict
- Returns
serialized model instance
-
classmethod
find
(session, model_id) Finds a model instance by its model_id.
- Return type
-
find_callback
(model_name, model_id) Finds a model using the model interface and model_id.
Used to find models in model relationships.
- Return type
-
get_deserialized
(name) Get deserialized data by name.
Deprecated since version 0.1.5a7: method will be removed in 0.2. Use self._get_deserialized_data[name] instead.
- Parameters
name – name of attribute
- Returns
-
classmethod
interface
(session) Creates a model interface from this class and a session.
This method can be overridden in model definitions for special cases.
- Return type
Union
[QueryInterface
,BrowserInterface
]
-
property
is_collection
Returns True if this Item is a collection in a PartAssociation.
Note: this is not how Aquarium does this test in the collection? method.
-
is_deserialized
(name) Check if a given key has already been deserialized.
New in version 0.1.5a7: Method added
- Parameters
name (
str
) – name of the attribute- Return type
bool
- Returns
True if key has been deserialized.
-
classmethod
load
(*args, **kwargs) Deserialize the data to a model.
- Parameters
data (dict) – data to deserialize
- Returns
the deserialized model
- Return type
-
classmethod
load_from
(data, owner=None) Create a new model instance from loaded attributes.
‘obj’ should have a o
-
make
() Makes the Item on the Aquarium server.
Requires this Item to be connected to a session.
-
model_schema
alias of
pydent.marshaller.base.ItemSchema
-
no_getter
(*_) Callback that always returns None.
-
refresh
() Refresh this model from data from the server.
- Returns
self
- Return type
self
-
reload
(data) Reload model attributes from new data.
- Parameters
data (dict) – data to update model instance
- Returns
model instance
- Return type
-
reset_field
(name) Reset the field descriptor to its placeholder value, returning the behavior.
New in version 0.1.5a7: Method added to reset deserialized attributes
- Parameters
name (
str
) – name of the attribute- Returns
None
-
property
session
The connected session instance.
-
update
() Updates the item.
Will update the data associations and its location.
-
property
uri
Return a URI for this model using the attached session url and tableized model name. For example, http://aquarium.org/samples/. If no session is attached, use the ModelBase.DEFAULT_NAMESPACE key for the url.
- Return type
str
- Returns
the instance URI
-
classmethod
where
(session, params) Finds a list of models by some parameters.
- Return type
Optional
[List
[ModelBase
]]
-
where_callback
(model_name, *args, **kwargs) Finds models using a model interface and a set of parameters.
Used to find models in model relationships.
- Return type
Optional
[List
[ModelBase
]]
-
-
class
pydent.models.
Job
(**data)[source] Bases:
pydent.base.ModelBase
A Job model.
The model initializer.
- Parameters
data (dict) – data to add to the model
-
_check_for_session
() Raises error if model is not connected to a session.
:raises NoSessionError
-
classmethod
_flatten_deserialized_data
(models, memo) Flattens all of the relationships found in the models, returning a rid: model dictionary.
- Return type
dict
-
_get_data
() Return the model’s data.
-
_get_deserialized_data
() Return the deserialized model data.
-
_model_schema
alias of
pydent.marshaller.base.JobSchema
-
property
_primary_key
Returns the primary key (e.g. ‘id’) or the rid if id does not exist or is None.
-
_rid_dict
() Dictionary of all models attached to this model keyed by their rid.
-
add_data
(data) Initializes fake attributes that correspond to data.
-
anonymize
() Resets the primary key of the model and assigns a new rid.
Metatypes cannot be annonymized.
- Returns
self
-
append_to_many
(name, model) Appends a model to the many relationship.
- Parameters
name (str) – name of the relationship or attribute
model (ModelBase) – model to append
- Returns
None
- Return type
None
-
connect_to_session
(session) Connect model to a session.
- Parameters
session (
SessionABC
) – theAqSession
- Returns
None
- Raises
SessionAlreadySet – if session is already set
NoSessionError – if session is not a SessionABC type
-
copy
(keep=None) Provides a deepcopy of the model, but annonymizes the primary and global keys unless class is a metatype (e.g. OperationType, SampleType, FieldType) or class name is found in list of ‘keep’.
By default, inventory classes such as Sample, Item, and Collection are ‘kept’.
This specific usecase is that when copying whole plans, that the integrity of the inventory used in the operations is maintained. These are the items that refer to physical inventory in the laboratory and are referred to by their rids, and so it is important to that any of these inventory are always maintain their rids. Meaning in the lab, their is only ONE instance of the inventory. In Trident and Aquarium, there is only ONE instance of inventory that is referred to by its rid.
Similarly, any metatype model must also maintain their rid.
- Parameters
keep (
Optional
[bool
]) – list of model classes (as a list of strings) to keep un-anonymous- Return type
- Returns
copied model
-
dump
(only=None, include=None, ignore=None, include_model_type=False, include_uri=False) Dump (serialize) the Aquarium model instance to JSON.
- Parameters
only (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – dump only the provided keysinclude (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – include the provided nested dump keysignore (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – ignore the provided keysinclude_model_type (
bool
) – if True, include the model class type for each entry using the __model__ keyinclude_uri (
bool
) – if True, include a URI using the session URL and the tableized model class name using the __uri__ key. If a session is not attached, look for the url namespace in the ModelBase.DEFAULT_NAMESPACE class attribute, as in http://aquarium.org/samples/10.
- Return type
dict
- Returns
serialized model instance
-
classmethod
find
(session, model_id) Finds a model instance by its model_id.
- Return type
-
find_callback
(model_name, model_id) Finds a model using the model interface and model_id.
Used to find models in model relationships.
- Return type
-
get_deserialized
(name) Get deserialized data by name.
Deprecated since version 0.1.5a7: method will be removed in 0.2. Use self._get_deserialized_data[name] instead.
- Parameters
name – name of attribute
- Returns
-
classmethod
interface
(session) Creates a model interface from this class and a session.
This method can be overridden in model definitions for special cases.
- Return type
Union
[QueryInterface
,BrowserInterface
]
-
is_deserialized
(name) Check if a given key has already been deserialized.
New in version 0.1.5a7: Method added
- Parameters
name (
str
) – name of the attribute- Return type
bool
- Returns
True if key has been deserialized.
-
classmethod
load
(*args, **kwargs) Deserialize the data to a model.
- Parameters
data (dict) – data to deserialize
- Returns
the deserialized model
- Return type
-
classmethod
load_from
(data, owner=None) Create a new model instance from loaded attributes.
‘obj’ should have a o
-
model_schema
alias of
pydent.marshaller.base.JobSchema
-
no_getter
(*_) Callback that always returns None.
-
refresh
() Refresh this model from data from the server.
- Returns
self
- Return type
self
-
reload
(data) Reload model attributes from new data.
- Parameters
data (dict) – data to update model instance
- Returns
model instance
- Return type
-
reset_field
(name) Reset the field descriptor to its placeholder value, returning the behavior.
New in version 0.1.5a7: Method added to reset deserialized attributes
- Parameters
name (
str
) – name of the attribute- Returns
None
-
property
session
The connected session instance.
-
property
uri
Return a URI for this model using the attached session url and tableized model name. For example, http://aquarium.org/samples/. If no session is attached, use the ModelBase.DEFAULT_NAMESPACE key for the url.
- Return type
str
- Returns
the instance URI
-
classmethod
where
(session, params) Finds a list of models by some parameters.
- Return type
Optional
[List
[ModelBase
]]
-
where_callback
(model_name, *args, **kwargs) Finds models using a model interface and a set of parameters.
Used to find models in model relationships.
- Return type
Optional
[List
[ModelBase
]]
-
class
pydent.models.
JobAssociation
(**data)[source] Bases:
pydent.base.ModelBase
A JobAssociation model.
The model initializer.
- Parameters
data (dict) – data to add to the model
-
_check_for_session
() Raises error if model is not connected to a session.
:raises NoSessionError
-
classmethod
_flatten_deserialized_data
(models, memo) Flattens all of the relationships found in the models, returning a rid: model dictionary.
- Return type
dict
-
_get_data
() Return the model’s data.
-
_get_deserialized_data
() Return the deserialized model data.
-
_model_schema
alias of
pydent.marshaller.base.JobAssociationSchema
-
property
_primary_key
Returns the primary key (e.g. ‘id’) or the rid if id does not exist or is None.
-
_rid_dict
() Dictionary of all models attached to this model keyed by their rid.
-
add_data
(data) Initializes fake attributes that correspond to data.
-
anonymize
() Resets the primary key of the model and assigns a new rid.
Metatypes cannot be annonymized.
- Returns
self
-
append_to_many
(name, model) Appends a model to the many relationship.
- Parameters
name (str) – name of the relationship or attribute
model (ModelBase) – model to append
- Returns
None
- Return type
None
-
connect_to_session
(session) Connect model to a session.
- Parameters
session (
SessionABC
) – theAqSession
- Returns
None
- Raises
SessionAlreadySet – if session is already set
NoSessionError – if session is not a SessionABC type
-
copy
(keep=None) Provides a deepcopy of the model, but annonymizes the primary and global keys unless class is a metatype (e.g. OperationType, SampleType, FieldType) or class name is found in list of ‘keep’.
By default, inventory classes such as Sample, Item, and Collection are ‘kept’.
This specific usecase is that when copying whole plans, that the integrity of the inventory used in the operations is maintained. These are the items that refer to physical inventory in the laboratory and are referred to by their rids, and so it is important to that any of these inventory are always maintain their rids. Meaning in the lab, their is only ONE instance of the inventory. In Trident and Aquarium, there is only ONE instance of inventory that is referred to by its rid.
Similarly, any metatype model must also maintain their rid.
- Parameters
keep (
Optional
[bool
]) – list of model classes (as a list of strings) to keep un-anonymous- Return type
- Returns
copied model
-
dump
(only=None, include=None, ignore=None, include_model_type=False, include_uri=False) Dump (serialize) the Aquarium model instance to JSON.
- Parameters
only (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – dump only the provided keysinclude (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – include the provided nested dump keysignore (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – ignore the provided keysinclude_model_type (
bool
) – if True, include the model class type for each entry using the __model__ keyinclude_uri (
bool
) – if True, include a URI using the session URL and the tableized model class name using the __uri__ key. If a session is not attached, look for the url namespace in the ModelBase.DEFAULT_NAMESPACE class attribute, as in http://aquarium.org/samples/10.
- Return type
dict
- Returns
serialized model instance
-
classmethod
find
(session, model_id) Finds a model instance by its model_id.
- Return type
-
find_callback
(model_name, model_id) Finds a model using the model interface and model_id.
Used to find models in model relationships.
- Return type
-
get_deserialized
(name) Get deserialized data by name.
Deprecated since version 0.1.5a7: method will be removed in 0.2. Use self._get_deserialized_data[name] instead.
- Parameters
name – name of attribute
- Returns
-
classmethod
interface
(session) Creates a model interface from this class and a session.
This method can be overridden in model definitions for special cases.
- Return type
Union
[QueryInterface
,BrowserInterface
]
-
is_deserialized
(name) Check if a given key has already been deserialized.
New in version 0.1.5a7: Method added
- Parameters
name (
str
) – name of the attribute- Return type
bool
- Returns
True if key has been deserialized.
-
classmethod
load
(*args, **kwargs) Deserialize the data to a model.
- Parameters
data (dict) – data to deserialize
- Returns
the deserialized model
- Return type
-
classmethod
load_from
(data, owner=None) Create a new model instance from loaded attributes.
‘obj’ should have a o
-
model_schema
alias of
pydent.marshaller.base.JobAssociationSchema
-
no_getter
(*_) Callback that always returns None.
-
refresh
() Refresh this model from data from the server.
- Returns
self
- Return type
self
-
reload
(data) Reload model attributes from new data.
- Parameters
data (dict) – data to update model instance
- Returns
model instance
- Return type
-
reset_field
(name) Reset the field descriptor to its placeholder value, returning the behavior.
New in version 0.1.5a7: Method added to reset deserialized attributes
- Parameters
name (
str
) – name of the attribute- Returns
None
-
property
session
The connected session instance.
-
property
uri
Return a URI for this model using the attached session url and tableized model name. For example, http://aquarium.org/samples/. If no session is attached, use the ModelBase.DEFAULT_NAMESPACE key for the url.
- Return type
str
- Returns
the instance URI
-
classmethod
where
(session, params) Finds a list of models by some parameters.
- Return type
Optional
[List
[ModelBase
]]
-
where_callback
(model_name, *args, **kwargs) Finds models using a model interface and a set of parameters.
Used to find models in model relationships.
- Return type
Optional
[List
[ModelBase
]]
-
class
pydent.models.
Library
(**data)[source] Bases:
pydent.base.ModelBase
A Library model.
The model initializer.
- Parameters
data (dict) – data to add to the model
-
_check_for_session
() Raises error if model is not connected to a session.
:raises NoSessionError
-
classmethod
_flatten_deserialized_data
(models, memo) Flattens all of the relationships found in the models, returning a rid: model dictionary.
- Return type
dict
-
_get_data
() Return the model’s data.
-
_get_deserialized_data
() Return the deserialized model data.
-
_model_schema
alias of
pydent.marshaller.base.LibrarySchema
-
property
_primary_key
Returns the primary key (e.g. ‘id’) or the rid if id does not exist or is None.
-
_rid_dict
() Dictionary of all models attached to this model keyed by their rid.
-
add_data
(data) Initializes fake attributes that correspond to data.
-
anonymize
() Resets the primary key of the model and assigns a new rid.
Metatypes cannot be annonymized.
- Returns
self
-
append_to_many
(name, model) Appends a model to the many relationship.
- Parameters
name (str) – name of the relationship or attribute
model (ModelBase) – model to append
- Returns
None
- Return type
None
-
code
(accessor)[source] Reminant from previous API.
-
connect_to_session
(session) Connect model to a session.
- Parameters
session (
SessionABC
) – theAqSession
- Returns
None
- Raises
SessionAlreadySet – if session is already set
NoSessionError – if session is not a SessionABC type
-
copy
(keep=None) Provides a deepcopy of the model, but annonymizes the primary and global keys unless class is a metatype (e.g. OperationType, SampleType, FieldType) or class name is found in list of ‘keep’.
By default, inventory classes such as Sample, Item, and Collection are ‘kept’.
This specific usecase is that when copying whole plans, that the integrity of the inventory used in the operations is maintained. These are the items that refer to physical inventory in the laboratory and are referred to by their rids, and so it is important to that any of these inventory are always maintain their rids. Meaning in the lab, their is only ONE instance of the inventory. In Trident and Aquarium, there is only ONE instance of inventory that is referred to by its rid.
Similarly, any metatype model must also maintain their rid.
- Parameters
keep (
Optional
[bool
]) – list of model classes (as a list of strings) to keep un-anonymous- Return type
- Returns
copied model
-
dump
(only=None, include=None, ignore=None, include_model_type=False, include_uri=False) Dump (serialize) the Aquarium model instance to JSON.
- Parameters
only (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – dump only the provided keysinclude (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – include the provided nested dump keysignore (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – ignore the provided keysinclude_model_type (
bool
) – if True, include the model class type for each entry using the __model__ keyinclude_uri (
bool
) – if True, include a URI using the session URL and the tableized model class name using the __uri__ key. If a session is not attached, look for the url namespace in the ModelBase.DEFAULT_NAMESPACE class attribute, as in http://aquarium.org/samples/10.
- Return type
dict
- Returns
serialized model instance
-
classmethod
find
(session, model_id) Finds a model instance by its model_id.
- Return type
-
find_callback
(model_name, model_id) Finds a model using the model interface and model_id.
Used to find models in model relationships.
- Return type
-
get_deserialized
(name) Get deserialized data by name.
Deprecated since version 0.1.5a7: method will be removed in 0.2. Use self._get_deserialized_data[name] instead.
- Parameters
name – name of attribute
- Returns
-
classmethod
interface
(session) Creates a model interface from this class and a session.
This method can be overridden in model definitions for special cases.
- Return type
Union
[QueryInterface
,BrowserInterface
]
-
is_deserialized
(name) Check if a given key has already been deserialized.
New in version 0.1.5a7: Method added
- Parameters
name (
str
) – name of the attribute- Return type
bool
- Returns
True if key has been deserialized.
-
classmethod
load
(*args, **kwargs) Deserialize the data to a model.
- Parameters
data (dict) – data to deserialize
- Returns
the deserialized model
- Return type
-
classmethod
load_from
(data, owner=None) Create a new model instance from loaded attributes.
‘obj’ should have a o
-
model_schema
alias of
pydent.marshaller.base.LibrarySchema
-
no_getter
(*_) Callback that always returns None.
-
refresh
() Refresh this model from data from the server.
- Returns
self
- Return type
self
-
reload
(data) Reload model attributes from new data.
- Parameters
data (dict) – data to update model instance
- Returns
model instance
- Return type
-
reset_field
(name) Reset the field descriptor to its placeholder value, returning the behavior.
New in version 0.1.5a7: Method added to reset deserialized attributes
- Parameters
name (
str
) – name of the attribute- Returns
None
-
property
session
The connected session instance.
-
property
uri
Return a URI for this model using the attached session url and tableized model name. For example, http://aquarium.org/samples/. If no session is attached, use the ModelBase.DEFAULT_NAMESPACE key for the url.
- Return type
str
- Returns
the instance URI
-
classmethod
where
(session, params) Finds a list of models by some parameters.
- Return type
Optional
[List
[ModelBase
]]
-
where_callback
(model_name, *args, **kwargs) Finds models using a model interface and a set of parameters.
Used to find models in model relationships.
- Return type
Optional
[List
[ModelBase
]]
-
class
pydent.models.
Membership
(**data)[source] Bases:
pydent.base.ModelBase
The model initializer.
- Parameters
data (dict) – data to add to the model
-
_check_for_session
() Raises error if model is not connected to a session.
:raises NoSessionError
-
classmethod
_flatten_deserialized_data
(models, memo) Flattens all of the relationships found in the models, returning a rid: model dictionary.
- Return type
dict
-
_get_data
() Return the model’s data.
-
_get_deserialized_data
() Return the deserialized model data.
-
_model_schema
alias of
pydent.marshaller.base.MembershipSchema
-
property
_primary_key
Returns the primary key (e.g. ‘id’) or the rid if id does not exist or is None.
-
_rid_dict
() Dictionary of all models attached to this model keyed by their rid.
-
add_data
(data) Initializes fake attributes that correspond to data.
-
anonymize
() Resets the primary key of the model and assigns a new rid.
Metatypes cannot be annonymized.
- Returns
self
-
append_to_many
(name, model) Appends a model to the many relationship.
- Parameters
name (str) – name of the relationship or attribute
model (ModelBase) – model to append
- Returns
None
- Return type
None
-
connect_to_session
(session) Connect model to a session.
- Parameters
session (
SessionABC
) – theAqSession
- Returns
None
- Raises
SessionAlreadySet – if session is already set
NoSessionError – if session is not a SessionABC type
-
copy
(keep=None) Provides a deepcopy of the model, but annonymizes the primary and global keys unless class is a metatype (e.g. OperationType, SampleType, FieldType) or class name is found in list of ‘keep’.
By default, inventory classes such as Sample, Item, and Collection are ‘kept’.
This specific usecase is that when copying whole plans, that the integrity of the inventory used in the operations is maintained. These are the items that refer to physical inventory in the laboratory and are referred to by their rids, and so it is important to that any of these inventory are always maintain their rids. Meaning in the lab, their is only ONE instance of the inventory. In Trident and Aquarium, there is only ONE instance of inventory that is referred to by its rid.
Similarly, any metatype model must also maintain their rid.
- Parameters
keep (
Optional
[bool
]) – list of model classes (as a list of strings) to keep un-anonymous- Return type
- Returns
copied model
-
dump
(only=None, include=None, ignore=None, include_model_type=False, include_uri=False) Dump (serialize) the Aquarium model instance to JSON.
- Parameters
only (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – dump only the provided keysinclude (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – include the provided nested dump keysignore (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – ignore the provided keysinclude_model_type (
bool
) – if True, include the model class type for each entry using the __model__ keyinclude_uri (
bool
) – if True, include a URI using the session URL and the tableized model class name using the __uri__ key. If a session is not attached, look for the url namespace in the ModelBase.DEFAULT_NAMESPACE class attribute, as in http://aquarium.org/samples/10.
- Return type
dict
- Returns
serialized model instance
-
classmethod
find
(session, model_id) Finds a model instance by its model_id.
- Return type
-
find_callback
(model_name, model_id) Finds a model using the model interface and model_id.
Used to find models in model relationships.
- Return type
-
get_deserialized
(name) Get deserialized data by name.
Deprecated since version 0.1.5a7: method will be removed in 0.2. Use self._get_deserialized_data[name] instead.
- Parameters
name – name of attribute
- Returns
-
classmethod
interface
(session) Creates a model interface from this class and a session.
This method can be overridden in model definitions for special cases.
- Return type
Union
[QueryInterface
,BrowserInterface
]
-
is_deserialized
(name) Check if a given key has already been deserialized.
New in version 0.1.5a7: Method added
- Parameters
name (
str
) – name of the attribute- Return type
bool
- Returns
True if key has been deserialized.
-
classmethod
load
(*args, **kwargs) Deserialize the data to a model.
- Parameters
data (dict) – data to deserialize
- Returns
the deserialized model
- Return type
-
classmethod
load_from
(data, owner=None) Create a new model instance from loaded attributes.
‘obj’ should have a o
-
model_schema
alias of
pydent.marshaller.base.MembershipSchema
-
no_getter
(*_) Callback that always returns None.
-
refresh
() Refresh this model from data from the server.
- Returns
self
- Return type
self
-
reload
(data) Reload model attributes from new data.
- Parameters
data (dict) – data to update model instance
- Returns
model instance
- Return type
-
reset_field
(name) Reset the field descriptor to its placeholder value, returning the behavior.
New in version 0.1.5a7: Method added to reset deserialized attributes
- Parameters
name (
str
) – name of the attribute- Returns
None
-
property
session
The connected session instance.
-
property
uri
Return a URI for this model using the attached session url and tableized model name. For example, http://aquarium.org/samples/. If no session is attached, use the ModelBase.DEFAULT_NAMESPACE key for the url.
- Return type
str
- Returns
the instance URI
-
classmethod
where
(session, params) Finds a list of models by some parameters.
- Return type
Optional
[List
[ModelBase
]]
-
where_callback
(model_name, *args, **kwargs) Finds models using a model interface and a set of parameters.
Used to find models in model relationships.
- Return type
Optional
[List
[ModelBase
]]
-
class
pydent.models.
ObjectType
(**data)[source] Bases:
pydent.models.crud_mixin.SaveMixin
,pydent.base.ModelBase
A ObjectType model that represents the type of container an item is.
The model initializer.
- Parameters
data (dict) – data to add to the model
-
_check_for_session
() Raises error if model is not connected to a session.
:raises NoSessionError
-
classmethod
_flatten_deserialized_data
(models, memo) Flattens all of the relationships found in the models, returning a rid: model dictionary.
- Return type
dict
-
_get_data
() Return the model’s data.
-
_get_deserialized_data
() Return the deserialized model data.
-
_model_schema
alias of
pydent.marshaller.base.ObjectTypeSchema
-
property
_primary_key
Returns the primary key (e.g. ‘id’) or the rid if id does not exist or is None.
-
_rid_dict
() Dictionary of all models attached to this model keyed by their rid.
-
add_data
(data) Initializes fake attributes that correspond to data.
-
anonymize
() Resets the primary key of the model and assigns a new rid.
Metatypes cannot be annonymized.
- Returns
self
-
append_to_many
(name, model) Appends a model to the many relationship.
- Parameters
name (str) – name of the relationship or attribute
model (ModelBase) – model to append
- Returns
None
- Return type
None
-
connect_to_session
(session) Connect model to a session.
- Parameters
session (
SessionABC
) – theAqSession
- Returns
None
- Raises
SessionAlreadySet – if session is already set
NoSessionError – if session is not a SessionABC type
-
copy
(keep=None) Provides a deepcopy of the model, but annonymizes the primary and global keys unless class is a metatype (e.g. OperationType, SampleType, FieldType) or class name is found in list of ‘keep’.
By default, inventory classes such as Sample, Item, and Collection are ‘kept’.
This specific usecase is that when copying whole plans, that the integrity of the inventory used in the operations is maintained. These are the items that refer to physical inventory in the laboratory and are referred to by their rids, and so it is important to that any of these inventory are always maintain their rids. Meaning in the lab, their is only ONE instance of the inventory. In Trident and Aquarium, there is only ONE instance of inventory that is referred to by its rid.
Similarly, any metatype model must also maintain their rid.
- Parameters
keep (
Optional
[bool
]) – list of model classes (as a list of strings) to keep un-anonymous- Return type
- Returns
copied model
-
dump
(only=None, include=None, ignore=None, include_model_type=False, include_uri=False) Dump (serialize) the Aquarium model instance to JSON.
- Parameters
only (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – dump only the provided keysinclude (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – include the provided nested dump keysignore (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – ignore the provided keysinclude_model_type (
bool
) – if True, include the model class type for each entry using the __model__ keyinclude_uri (
bool
) – if True, include a URI using the session URL and the tableized model class name using the __uri__ key. If a session is not attached, look for the url namespace in the ModelBase.DEFAULT_NAMESPACE class attribute, as in http://aquarium.org/samples/10.
- Return type
dict
- Returns
serialized model instance
-
classmethod
find
(session, model_id) Finds a model instance by its model_id.
- Return type
-
find_callback
(model_name, model_id) Finds a model using the model interface and model_id.
Used to find models in model relationships.
- Return type
-
get_deserialized
(name) Get deserialized data by name.
Deprecated since version 0.1.5a7: method will be removed in 0.2. Use self._get_deserialized_data[name] instead.
- Parameters
name – name of attribute
- Returns
-
classmethod
interface
(session) Creates a model interface from this class and a session.
This method can be overridden in model definitions for special cases.
- Return type
Union
[QueryInterface
,BrowserInterface
]
-
is_deserialized
(name) Check if a given key has already been deserialized.
New in version 0.1.5a7: Method added
- Parameters
name (
str
) – name of the attribute- Return type
bool
- Returns
True if key has been deserialized.
-
classmethod
load
(*args, **kwargs) Deserialize the data to a model.
- Parameters
data (dict) – data to deserialize
- Returns
the deserialized model
- Return type
-
classmethod
load_from
(data, owner=None) Create a new model instance from loaded attributes.
‘obj’ should have a o
-
model_schema
alias of
pydent.marshaller.base.ObjectTypeSchema
-
new_item
(sample)[source] Create a new item.
New in version 0.1.5a13.
- Parameters
sample (
Union
[int
,Sample
]) – the sample id- Returns
the new item
-
no_getter
(*_) Callback that always returns None.
-
refresh
() Refresh this model from data from the server.
- Returns
self
- Return type
self
-
reload
(data) Reload model attributes from new data.
- Parameters
data (dict) – data to update model instance
- Returns
model instance
- Return type
-
reset_field
(name) Reset the field descriptor to its placeholder value, returning the behavior.
New in version 0.1.5a7: Method added to reset deserialized attributes
- Parameters
name (
str
) – name of the attribute- Returns
None
-
property
session
The connected session instance.
-
property
uri
Return a URI for this model using the attached session url and tableized model name. For example, http://aquarium.org/samples/. If no session is attached, use the ModelBase.DEFAULT_NAMESPACE key for the url.
- Return type
str
- Returns
the instance URI
-
classmethod
where
(session, params) Finds a list of models by some parameters.
- Return type
Optional
[List
[ModelBase
]]
-
where_callback
(model_name, *args, **kwargs) Finds models using a model interface and a set of parameters.
Used to find models in model relationships.
- Return type
Optional
[List
[ModelBase
]]
-
class
pydent.models.
Operation
(operation_type_id=None, operation_type=None, status=None, x=0, y=0)[source] Bases:
pydent.models.field_value_mixins.FieldValueInterface
,pydent.models.data_associations.DataAssociatorMixin
,pydent.base.ModelBase
A Operation model.
-
_check_for_session
() Raises error if model is not connected to a session.
:raises NoSessionError
-
classmethod
_flatten_deserialized_data
(models, memo) Flattens all of the relationships found in the models, returning a rid: model dictionary.
- Return type
dict
-
_get_data
() Return the model’s data.
-
_get_deserialized_data
() Return the deserialized model data.
-
_model_schema
alias of
pydent.marshaller.base.OperationSchema
-
property
_primary_key
Returns the primary key (e.g. ‘id’) or the rid if id does not exist or is None.
-
_rid_dict
() Dictionary of all models attached to this model keyed by their rid.
-
add_data
(data) Initializes fake attributes that correspond to data.
-
add_to_input_array
(name, sample=None, item=None, value=None, container=None)[source] Creates and adds a new input
FieldValue
. When setting values to items/samples/containers, the item/sample/container must be saved.- Parameters
name (string) – name of the FieldType/FieldValue
sample (Sample) – an existing Sample
item (Item) – an existing Item
value (string|integer) – a string or number value
container (ObjectType) – an existing ObjectType
- Returns
the newly created FieldValue
- Return type
-
add_to_output_array
(name, sample=None, item=None, value=None, container=None)[source] Creates and adds a new output
FieldValue
. When setting values to items/samples/containers, the item/sample/container must be saved.- Parameters
name (string) – name of the FieldType/FieldValue
sample (Sample) – an existing Sample
item (Item) – an existing Item
value (string|integer) – a string or number value
container (ObjectType) – an existing ObjectType
- Returns
the newly created FieldValue
- Return type
-
anonymize
() Resets the primary key of the model and assigns a new rid.
Metatypes cannot be annonymized.
- Returns
self
-
append_to_many
(name, model) Appends a model to the many relationship.
- Parameters
name (str) – name of the relationship or attribute
model (ModelBase) – model to append
- Returns
None
- Return type
None
-
associate
(key, value, upload=None, create_new=False, save=None) Adds a data association with the key and value to this object.
- Parameters
key (str) – Key of the association
value (dict | str | int | float) – a json serializable object
upload (File) – optional file to upload
create_new – if True (default) will create a new association instead of updating the existing association.
- Tuype create_new
bool
- Returns
newly created or updated data association
- Return type
-
associate_file
(key, value, file, job_id=None) Associate a file.
- Parameters
key (str or json) – association key
value (str or json) – association value
file (file object) – file to create
Upload
job_id (int) – optional job_id to associate the
Upload
- Returns
new data association
- Return type
-
associate_file_from_path
(key, value, filepath, job_id=None) Associate a file from a filepath.
- Parameters
key (str or json) – association key
value (str or json) – association value
filepath (str) – path to file to create
Upload
job_id (int) – optional job_id to associate the
Upload
- Returns
new data association
- Return type
-
connect_to_session
(session) Connect model to a session.
- Parameters
session (
SessionABC
) – theAqSession
- Returns
None
- Raises
SessionAlreadySet – if session is already set
NoSessionError – if session is not a SessionABC type
-
copy
(keep=None) Provides a deepcopy of the model, but annonymizes the primary and global keys unless class is a metatype (e.g. OperationType, SampleType, FieldType) or class name is found in list of ‘keep’.
By default, inventory classes such as Sample, Item, and Collection are ‘kept’.
This specific usecase is that when copying whole plans, that the integrity of the inventory used in the operations is maintained. These are the items that refer to physical inventory in the laboratory and are referred to by their rids, and so it is important to that any of these inventory are always maintain their rids. Meaning in the lab, their is only ONE instance of the inventory. In Trident and Aquarium, there is only ONE instance of inventory that is referred to by its rid.
Similarly, any metatype model must also maintain their rid.
- Parameters
keep (
Optional
[bool
]) – list of model classes (as a list of strings) to keep un-anonymous- Return type
- Returns
copied model
-
dump
(only=None, include=None, ignore=None, include_model_type=False, include_uri=False) Dump (serialize) the Aquarium model instance to JSON.
- Parameters
only (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – dump only the provided keysinclude (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – include the provided nested dump keysignore (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – ignore the provided keysinclude_model_type (
bool
) – if True, include the model class type for each entry using the __model__ keyinclude_uri (
bool
) – if True, include a URI using the session URL and the tableized model class name using the __uri__ key. If a session is not attached, look for the url namespace in the ModelBase.DEFAULT_NAMESPACE class attribute, as in http://aquarium.org/samples/10.
- Return type
dict
- Returns
serialized model instance
-
field_value
(name, role)[source] Returns
FieldValue
with name and role.Return None if not found.
-
field_value_array
(name, role)[source] Returns
FieldValue
array with name and role.
-
classmethod
find
(session, model_id) Finds a model instance by its model_id.
- Return type
-
find_callback
(model_name, model_id) Finds a model using the model interface and model_id.
Used to find models in model relationships.
- Return type
-
get_deserialized
(name) Get deserialized data by name.
Deprecated since version 0.1.5a7: method will be removed in 0.2. Use self._get_deserialized_data[name] instead.
- Parameters
name – name of attribute
- Returns
-
get_field_type
(name, role) Returns a
pydent.models.FieldType
by its name and role from the instance’s metaclass.- Parameters
name (basestring) – its name
role (basestring) – its role
- Returns
metatypes field type or None if not found
- Return type
FieldType | None
-
get_field_types
(name=None, role=None) Returns a list of
pydent.models.FieldType
by their name and role from the instance’s metaclass.- Parameters
name (basestring) – its name
role (basestring) – its role
- Returns
list of field types
- Return type
list
-
get_field_value
(name, role=None) Returns a
pydent.models.FieldValue
by its name and role.- Parameters
name (basestring) – its name
role (basestring) – its role
- Returns
the field value or None if not found
- Return type
FieldValue | None
-
get_field_value_array
(name, role=None) Returns a list of
pydent.models.FieldValue
by their name and role.- Parameters
name (basestring) – its name
role (basestring) – its role
- Returns
list of field values
- Return type
list
-
get_metatype
() Returns the instance’s metatype.
The metatype is either
pydent.models.SampleType
orpydent.models.OperationType
). The metatype class name is stored as METATYPE in the class definition.- Returns
the metatype
- Return type
-
get_routing
()[source] Returns the routing dictionary for this instance.
- Returns
routing dictionary
- Return type
dict
-
init_field_values
()[source] Initialize the
FieldValue
from theFieldType
of the parentOperation
type.
-
input
(name)[source] Returns the input
FieldValue
by name.
-
property
inputs
Return a list of all input
FieldValues
-
classmethod
interface
(session) Creates a model interface from this class and a session.
This method can be overridden in model definitions for special cases.
- Return type
Union
[QueryInterface
,BrowserInterface
]
-
is_deserialized
(name) Check if a given key has already been deserialized.
New in version 0.1.5a7: Method added
- Parameters
name (
str
) – name of the attribute- Return type
bool
- Returns
True if key has been deserialized.
-
classmethod
load
(*args, **kwargs) Deserialize the data to a model.
- Parameters
data (dict) – data to deserialize
- Returns
the deserialized model
- Return type
-
classmethod
load_from
(data, owner=None) Create a new model instance from loaded attributes.
‘obj’ should have a o
-
model_schema
alias of
pydent.marshaller.base.OperationSchema
-
new_field_value
(name, role=None, values_dict=None) Instantiates a new
pydent.models.FieldValue
from a name and role. The should be a field type with the name and role in the metatype. Optionally, a values dictionary may be provided with the following format:values_dict = { "value": None, "sample": mysample, "item": myitem, "object_type": None }
- Parameters
name (basestring) – its name
role (basestring) – its role
values_dict (dict) – values to set the new field value
- Returns
the new field value
- Return type
-
new_field_value_from_field_type
(field_type, values_dict=None) Instantiates a new
pydent.models.FieldValue
from a.pydent.models.FieldType
instance. Optionally, a values dictionary may be provided with the following format:values_dict = { "value": None, "sample": mysample, "item": myitem, "object_type": None }
- Parameters
field_type (FieldType) – field type to instantiate the field value
values_dict (dict) – values to set the new field value
- Returns
the new field value
- Return type
-
no_getter
(*_) Callback that always returns None.
-
output
(name)[source] Returns the output
FieldValue
by name.
-
property
outputs
Return a list of all output
FieldValues
-
refresh
() Refresh this model from data from the server.
- Returns
self
- Return type
self
-
reload
(data) Reload model attributes from new data.
- Parameters
data (dict) – data to update model instance
- Returns
model instance
- Return type
-
reset_field
(name) Reset the field descriptor to its placeholder value, returning the behavior.
New in version 0.1.5a7: Method added to reset deserialized attributes
- Parameters
name (
str
) – name of the attribute- Returns
None
-
safe_get_field_type
(fv) Safely returns the field value’s
pydent.models.FieldType
from the model.If the field value has no reference to the field type, its metatype (e.g.
pydent.models.SampleType
orpydent.models.OperationType
) is used to recover the field type.
-
property
session
The connected session instance.
-
set_field_value
(name, role, values) Sets a field value name and role using a dictionary, as in the following:
values = { "value": None, "sample": mysample, "item": myitem, "object_type": None }
-
set_field_value_array
(name, role, values_array) Sets an array of field values by name and role using an array of dictionaries, as in the following:
values_array = [{ "value": None, "sample": mysample, "item": myitem, "object_type": None }]
-
set_input
(name, sample=None, item=None, value=None, container=None, object_type=None)[source] Sets a input
FieldValue
to a value. When setting values to items/samples/containers, the item/sample/container must be saved.- Parameters
name (string) – name of the FieldValue/FieldType
sample (Sample) – an existing Sample
item (Item) – an existing Item
value (string|integer) – a string or number value
container (ObjectType) – an existing ObjectType
- Returns
the existing FieldValue modified
- Return type
-
set_input_array
(name, values)[source] Sets input
FieldValue
array using values. Values should be a list of dictionaries containing sample, item, container, or values keys. When setting values to items/samples/containers, the item/sample/container must be saved.- Parameters
name (string) – name of the FieldType/FieldValues being modified
values (list) – list of dictionary of values to set (e.g. [{“sample”: mysample}, {“item”: myitem}])
- Returns
the list of modified FieldValues
- Return type
list
-
set_output
(name, sample=None, item=None, value=None, container=None, object_type=None)[source] Sets a output
FieldValue
to a value. When setting values to items/samples/containers, the item/sample/container must be saved.- Parameters
name (string) – name of the FieldValue/FieldType
sample (Sample) – an existing Sample
item (Item) – an existing Item
value (string|integer) – a string or number value
container (ObjectType) – an existing ObjectType
- Returns
the existing FieldValue modified
- Return type
-
set_output_array
(name, values)[source] Sets output
FieldValue
array using values. Values should be a list of dictionaries containing sample, item, container, or values keys. When setting values to items/samples/containers, the item/sample/container must be saved.- Parameters
name (string) – name of the FieldType/FieldValues being modified
values (list) – list of dictionary of values to set (e.g. [{“sample”: mysample}, {“item”: myitem}])
- Returns
the list of modified FieldValues
- Return type
list
-
show
(pre='')[source] Print the operation nicely.
-
property
uri
Return a URI for this model using the attached session url and tableized model name. For example, http://aquarium.org/samples/. If no session is attached, use the ModelBase.DEFAULT_NAMESPACE key for the url.
- Return type
str
- Returns
the instance URI
-
classmethod
where
(session, params) Finds a list of models by some parameters.
- Return type
Optional
[List
[ModelBase
]]
-
where_callback
(model_name, *args, **kwargs) Finds models using a model interface and a set of parameters.
Used to find models in model relationships.
- Return type
Optional
[List
[ModelBase
]]
-
-
class
pydent.models.
OperationType
(**data)[source] Bases:
pydent.models.field_value_mixins.FieldTypeInterface
,pydent.models.crud_mixin.SaveMixin
,pydent.base.ModelBase
Represents an OperationType, which is the definition of a protocol in Aquarium.
The model initializer.
- Parameters
data (dict) – data to add to the model
-
_check_for_session
() Raises error if model is not connected to a session.
:raises NoSessionError
-
classmethod
_flatten_deserialized_data
(models, memo) Flattens all of the relationships found in the models, returning a rid: model dictionary.
- Return type
dict
-
_get_data
() Return the model’s data.
-
_get_deserialized_data
() Return the deserialized model data.
-
_model_schema
alias of
pydent.marshaller.base.OperationTypeSchema
-
property
_primary_key
Returns the primary key (e.g. ‘id’) or the rid if id does not exist or is None.
-
_rid_dict
() Dictionary of all models attached to this model keyed by their rid.
-
add_data
(data) Initializes fake attributes that correspond to data.
-
anonymize
() Resets the primary key of the model and assigns a new rid.
Metatypes cannot be annonymized.
- Returns
self
-
append_to_many
(name, model) Appends a model to the many relationship.
- Parameters
name (str) – name of the relationship or attribute
model (ModelBase) – model to append
- Returns
None
- Return type
None
-
connect_to_session
(session) Connect model to a session.
- Parameters
session (
SessionABC
) – theAqSession
- Returns
None
- Raises
SessionAlreadySet – if session is already set
NoSessionError – if session is not a SessionABC type
-
copy
(keep=None) Provides a deepcopy of the model, but annonymizes the primary and global keys unless class is a metatype (e.g. OperationType, SampleType, FieldType) or class name is found in list of ‘keep’.
By default, inventory classes such as Sample, Item, and Collection are ‘kept’.
This specific usecase is that when copying whole plans, that the integrity of the inventory used in the operations is maintained. These are the items that refer to physical inventory in the laboratory and are referred to by their rids, and so it is important to that any of these inventory are always maintain their rids. Meaning in the lab, their is only ONE instance of the inventory. In Trident and Aquarium, there is only ONE instance of inventory that is referred to by its rid.
Similarly, any metatype model must also maintain their rid.
- Parameters
keep (
Optional
[bool
]) – list of model classes (as a list of strings) to keep un-anonymous- Return type
- Returns
copied model
-
dump
(only=None, include=None, ignore=None, include_model_type=False, include_uri=False) Dump (serialize) the Aquarium model instance to JSON.
- Parameters
only (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – dump only the provided keysinclude (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – include the provided nested dump keysignore (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – ignore the provided keysinclude_model_type (
bool
) – if True, include the model class type for each entry using the __model__ keyinclude_uri (
bool
) – if True, include a URI using the session URL and the tableized model class name using the __uri__ key. If a session is not attached, look for the url namespace in the ModelBase.DEFAULT_NAMESPACE class attribute, as in http://aquarium.org/samples/10.
- Return type
dict
- Returns
serialized model instance
-
field_type
(name, role)[source] Returns a
pydent.models.FieldType
by its name and role.- Parameters
name (basestring) – its name
role (basestring) – its role
- Returns
the field type or None if not found
- Return type
FieldType | None
-
classmethod
find
(session, model_id) Finds a model instance by its model_id.
- Return type
-
find_callback
(model_name, model_id) Finds a model using the model interface and model_id.
Used to find models in model relationships.
- Return type
-
get_deserialized
(name) Get deserialized data by name.
Deprecated since version 0.1.5a7: method will be removed in 0.2. Use self._get_deserialized_data[name] instead.
- Parameters
name – name of attribute
- Returns
-
classmethod
interface
(session) Creates a model interface from this class and a session.
This method can be overridden in model definitions for special cases.
- Return type
Union
[QueryInterface
,BrowserInterface
]
-
is_deserialized
(name) Check if a given key has already been deserialized.
New in version 0.1.5a7: Method added
- Parameters
name (
str
) – name of the attribute- Return type
bool
- Returns
True if key has been deserialized.
-
classmethod
load
(*args, **kwargs) Deserialize the data to a model.
- Parameters
data (dict) – data to deserialize
- Returns
the deserialized model
- Return type
-
classmethod
load_from
(data, owner=None) Create a new model instance from loaded attributes.
‘obj’ should have a o
-
model_schema
alias of
pydent.marshaller.base.OperationTypeSchema
-
no_getter
(*_) Callback that always returns None.
-
refresh
() Refresh this model from data from the server.
- Returns
self
- Return type
self
-
reload
(data) Reload model attributes from new data.
- Parameters
data (dict) – data to update model instance
- Returns
model instance
- Return type
-
reset_field
(name) Reset the field descriptor to its placeholder value, returning the behavior.
New in version 0.1.5a7: Method added to reset deserialized attributes
- Parameters
name (
str
) – name of the attribute- Returns
None
-
save
()[source] Saves the Operation Type to the Aquarium server.
Requires this Operation Type to be connected to a session.
-
property
session
The connected session instance.
-
property
uri
Return a URI for this model using the attached session url and tableized model name. For example, http://aquarium.org/samples/. If no session is attached, use the ModelBase.DEFAULT_NAMESPACE key for the url.
- Return type
str
- Returns
the instance URI
-
classmethod
where
(session, params) Finds a list of models by some parameters.
- Return type
Optional
[List
[ModelBase
]]
-
where_callback
(model_name, *args, **kwargs) Finds models using a model interface and a set of parameters.
Used to find models in model relationships.
- Return type
Optional
[List
[ModelBase
]]
-
class
pydent.models.
PartAssociation
(part_id=None, collection_id=None, row=None, column=None)[source] Bases:
pydent.models.crud_mixin.JSONSaveMixin
,pydent.base.ModelBase
Represents a PartAssociation linking a part to a collection.
Collections contain many parts, each of which can refer to a different sample.
-
_check_for_session
() Raises error if model is not connected to a session.
:raises NoSessionError
-
classmethod
_flatten_deserialized_data
(models, memo) Flattens all of the relationships found in the models, returning a rid: model dictionary.
- Return type
dict
-
_get_data
() Return the model’s data.
-
_get_deserialized_data
() Return the deserialized model data.
-
_model_schema
alias of
pydent.marshaller.base.PartAssociationSchema
-
property
_primary_key
Returns the primary key (e.g. ‘id’) or the rid if id does not exist or is None.
-
_rid_dict
() Dictionary of all models attached to this model keyed by their rid.
-
add_data
(data) Initializes fake attributes that correspond to data.
-
anonymize
() Resets the primary key of the model and assigns a new rid.
Metatypes cannot be annonymized.
- Returns
self
-
append_to_many
(name, model) Appends a model to the many relationship.
- Parameters
name (str) – name of the relationship or attribute
model (ModelBase) – model to append
- Returns
None
- Return type
None
-
connect_to_session
(session) Connect model to a session.
- Parameters
session (
SessionABC
) – theAqSession
- Returns
None
- Raises
SessionAlreadySet – if session is already set
NoSessionError – if session is not a SessionABC type
-
copy
(keep=None) Provides a deepcopy of the model, but annonymizes the primary and global keys unless class is a metatype (e.g. OperationType, SampleType, FieldType) or class name is found in list of ‘keep’.
By default, inventory classes such as Sample, Item, and Collection are ‘kept’.
This specific usecase is that when copying whole plans, that the integrity of the inventory used in the operations is maintained. These are the items that refer to physical inventory in the laboratory and are referred to by their rids, and so it is important to that any of these inventory are always maintain their rids. Meaning in the lab, their is only ONE instance of the inventory. In Trident and Aquarium, there is only ONE instance of inventory that is referred to by its rid.
Similarly, any metatype model must also maintain their rid.
- Parameters
keep (
Optional
[bool
]) – list of model classes (as a list of strings) to keep un-anonymous- Return type
- Returns
copied model
-
dump
(only=None, include=None, ignore=None, include_model_type=False, include_uri=False) Dump (serialize) the Aquarium model instance to JSON.
- Parameters
only (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – dump only the provided keysinclude (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – include the provided nested dump keysignore (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – ignore the provided keysinclude_model_type (
bool
) – if True, include the model class type for each entry using the __model__ keyinclude_uri (
bool
) – if True, include a URI using the session URL and the tableized model class name using the __uri__ key. If a session is not attached, look for the url namespace in the ModelBase.DEFAULT_NAMESPACE class attribute, as in http://aquarium.org/samples/10.
- Return type
dict
- Returns
serialized model instance
-
classmethod
find
(session, model_id) Finds a model instance by its model_id.
- Return type
-
find_callback
(model_name, model_id) Finds a model using the model interface and model_id.
Used to find models in model relationships.
- Return type
-
get_deserialized
(name) Get deserialized data by name.
Deprecated since version 0.1.5a7: method will be removed in 0.2. Use self._get_deserialized_data[name] instead.
- Parameters
name – name of attribute
- Returns
-
classmethod
interface
(session) Creates a model interface from this class and a session.
This method can be overridden in model definitions for special cases.
- Return type
Union
[QueryInterface
,BrowserInterface
]
-
is_deserialized
(name) Check if a given key has already been deserialized.
New in version 0.1.5a7: Method added
- Parameters
name (
str
) – name of the attribute- Return type
bool
- Returns
True if key has been deserialized.
-
classmethod
load
(*args, **kwargs) Deserialize the data to a model.
- Parameters
data (dict) – data to deserialize
- Returns
the deserialized model
- Return type
-
classmethod
load_from
(data, owner=None) Create a new model instance from loaded attributes.
‘obj’ should have a o
-
model_schema
alias of
pydent.marshaller.base.PartAssociationSchema
-
no_getter
(*_) Callback that always returns None.
-
refresh
() Refresh this model from data from the server.
- Returns
self
- Return type
self
-
reload
(data) Reload model attributes from new data.
- Parameters
data (dict) – data to update model instance
- Returns
model instance
- Return type
-
reset_field
(name) Reset the field descriptor to its placeholder value, returning the behavior.
New in version 0.1.5a7: Method added to reset deserialized attributes
- Parameters
name (
str
) – name of the attribute- Returns
None
-
property
session
The connected session instance.
-
property
uri
Return a URI for this model using the attached session url and tableized model name. For example, http://aquarium.org/samples/. If no session is attached, use the ModelBase.DEFAULT_NAMESPACE key for the url.
- Return type
str
- Returns
the instance URI
-
classmethod
where
(session, params) Finds a list of models by some parameters.
- Return type
Optional
[List
[ModelBase
]]
-
where_callback
(model_name, *args, **kwargs) Finds models using a model interface and a set of parameters.
Used to find models in model relationships.
- Return type
Optional
[List
[ModelBase
]]
-
-
class
pydent.models.
Plan
(name='MyPlan', status='planning')[source] Bases:
pydent.models.data_associations.DataAssociatorMixin
,pydent.models.crud_mixin.SaveMixin
,pydent.models.crud_mixin.DeleteMixin
,pydent.base.ModelBase
A Plan model.
-
_check_for_session
() Raises error if model is not connected to a session.
:raises NoSessionError
-
classmethod
_flatten_deserialized_data
(models, memo) Flattens all of the relationships found in the models, returning a rid: model dictionary.
- Return type
dict
-
_get_data
() Return the model’s data.
-
_get_deserialized_data
() Return the deserialized model data.
-
_get_wire_dict
(wires)[source] Return all wires in the plan grouped by the wire identifier.
-
_model_schema
alias of
pydent.marshaller.base.PlanSchema
-
property
_primary_key
Returns the primary key (e.g. ‘id’) or the rid if id does not exist or is None.
-
_rid_dict
() Dictionary of all models attached to this model keyed by their rid.
-
add_data
(data) Initializes fake attributes that correspond to data.
-
add_operation
(operation)[source] Adds an operation to the Plan.
- Parameters
operation (Operation) – Operation to add
- Returns
None
- Return type
None
-
add_operations
(operations)[source] Adds multiple operations to the Plan.
- Parameters
operations (list) – list of Operations
- Returns
None
- Return type
None
-
anonymize
() Resets the primary key of the model and assigns a new rid.
Metatypes cannot be annonymized.
- Returns
self
-
append_to_many
(name, model) Appends a model to the many relationship.
- Parameters
name (str) – name of the relationship or attribute
model (ModelBase) – model to append
- Returns
None
- Return type
None
-
associate
(key, value, upload=None, create_new=False, save=None) Adds a data association with the key and value to this object.
- Parameters
key (str) – Key of the association
value (dict | str | int | float) – a json serializable object
upload (File) – optional file to upload
create_new – if True (default) will create a new association instead of updating the existing association.
- Tuype create_new
bool
- Returns
newly created or updated data association
- Return type
-
associate_file
(key, value, file, job_id=None) Associate a file.
- Parameters
key (str or json) – association key
value (str or json) – association value
file (file object) – file to create
Upload
job_id (int) – optional job_id to associate the
Upload
- Returns
new data association
- Return type
-
associate_file_from_path
(key, value, filepath, job_id=None) Associate a file from a filepath.
- Parameters
key (str or json) – association key
value (str or json) – association value
filepath (str) – path to file to create
Upload
job_id (int) – optional job_id to associate the
Upload
- Returns
new data association
- Return type
-
connect_to_session
(session) Connect model to a session.
- Parameters
session (
SessionABC
) – theAqSession
- Returns
None
- Raises
SessionAlreadySet – if session is already set
NoSessionError – if session is not a SessionABC type
-
copy
(keep=None) Provides a deepcopy of the model, but annonymizes the primary and global keys unless class is a metatype (e.g. OperationType, SampleType, FieldType) or class name is found in list of ‘keep’.
By default, inventory classes such as Sample, Item, and Collection are ‘kept’.
This specific usecase is that when copying whole plans, that the integrity of the inventory used in the operations is maintained. These are the items that refer to physical inventory in the laboratory and are referred to by their rids, and so it is important to that any of these inventory are always maintain their rids. Meaning in the lab, their is only ONE instance of the inventory. In Trident and Aquarium, there is only ONE instance of inventory that is referred to by its rid.
Similarly, any metatype model must also maintain their rid.
- Parameters
keep (
Optional
[bool
]) – list of model classes (as a list of strings) to keep un-anonymous- Return type
- Returns
copied model
-
download_files
(outdir=None, overwrite=True)[source] Downloads all uploads associated with the plan. Downloads happen ansynchrounously.
- Parameters
outdir – output directory for downloaded files
overwrite – whether to overwrite files if they exist
- Returns
None
-
dump
(only=None, include=None, ignore=None, include_model_type=False, include_uri=False) Dump (serialize) the Aquarium model instance to JSON.
- Parameters
only (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – dump only the provided keysinclude (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – include the provided nested dump keysignore (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – ignore the provided keysinclude_model_type (
bool
) – if True, include the model class type for each entry using the __model__ keyinclude_uri (
bool
) – if True, include a URI using the session URL and the tableized model class name using the __uri__ key. If a session is not attached, look for the url namespace in the ModelBase.DEFAULT_NAMESPACE class attribute, as in http://aquarium.org/samples/10.
- Return type
dict
- Returns
serialized model instance
-
estimate_cost
()[source] Estimates the cost of the plan on the Aquarium server. This is necessary before plan submission.
- Returns
cost
- Return type
dict
-
classmethod
find
(session, model_id) Finds a model instance by its model_id.
- Return type
-
find_callback
(model_name, model_id) Finds a model using the model interface and model_id.
Used to find models in model relationships.
- Return type
-
find_wires
(src, dest)[source] Retrieves the wire between a source and destination FieldValues.
- Parameters
src (FieldValue) – source FieldValue
dest (FieldValue) – destination FieldValue
- Returns
array of wires between src and dest FieldValues (determined by rid)
- Return type
array of wires
-
get_deserialized
(name) Get deserialized data by name.
Deprecated since version 0.1.5a7: method will be removed in 0.2. Use self._get_deserialized_data[name] instead.
- Parameters
name – name of attribute
- Returns
-
classmethod
interface
(session)[source] Creates a model interface from this class and a session.
This method can be overridden in model definitions for special cases.
-
is_deserialized
(name) Check if a given key has already been deserialized.
New in version 0.1.5a7: Method added
- Parameters
name (
str
) – name of the attribute- Return type
bool
- Returns
True if key has been deserialized.
-
classmethod
load
(*args, **kwargs) Deserialize the data to a model.
- Parameters
data (dict) – data to deserialize
- Returns
the deserialized model
- Return type
-
classmethod
load_from
(data, owner=None) Create a new model instance from loaded attributes.
‘obj’ should have a o
-
model_schema
alias of
pydent.marshaller.base.PlanSchema
-
no_getter
(*_) Callback that always returns None.
-
refresh
() Refresh this model from data from the server.
- Returns
self
- Return type
self
-
reload
(data) Reload model attributes from new data.
- Parameters
data (dict) – data to update model instance
- Returns
model instance
- Return type
-
replan
()[source] Copies or replans the plan.
Returns a plan copy
-
reset_field
(name) Reset the field descriptor to its placeholder value, returning the behavior.
New in version 0.1.5a7: Method added to reset deserialized attributes
- Parameters
name (
str
) – name of the attribute- Returns
None
-
property
session
The connected session instance.
-
show
()[source] Print the plan nicely.
-
step
()[source] Steps a plan.
-
submit
(user, budget)[source] Submits the Plan to the Aquarium server.
-
to_save_json
()[source] Returns the json representation of the plan for saving and creating Plans on the Aquarium server.
- Returns
JSON
- Return type
dict
-
property
uri
Return a URI for this model using the attached session url and tableized model name. For example, http://aquarium.org/samples/. If no session is attached, use the ModelBase.DEFAULT_NAMESPACE key for the url.
- Return type
str
- Returns
the instance URI
-
validate
(raise_error=True)[source] Validates the plan.
- Parameters
raise_error (boolean) – If True, raises an AquariumModelException. If false, returns the error messages.
- Returns
list of error messages
- Return type
array
-
classmethod
where
(session, params) Finds a list of models by some parameters.
- Return type
Optional
[List
[ModelBase
]]
-
where_callback
(model_name, *args, **kwargs) Finds models using a model interface and a set of parameters.
Used to find models in model relationships.
- Return type
Optional
[List
[ModelBase
]]
-
wire
(src, dest)[source] Creates a new wire between src and dest FieldValues. Returns the new wire if it does not exist in the plan. If the wire already exists and error_if_exists is True, then the existing wire is returned. Else an exception is raised.
- Parameters
src (FieldValue) – source field value (the input of the wire)
dest (FieldValue) – destination field value (the output of the wire)
error_if_exists (boolean) – Raise an error if the Wire already exists in the plan.
- Returns
Newly created wire or existing wire (if exists and error_if_exists == False)
- Return type
-
-
class
pydent.models.
PlanAssociation
(plan_id=None, operation_id=None)[source] Bases:
pydent.base.ModelBase
A PlanAssociation model.
The model initializer.
- Parameters
data (dict) – data to add to the model
-
_check_for_session
() Raises error if model is not connected to a session.
:raises NoSessionError
-
classmethod
_flatten_deserialized_data
(models, memo) Flattens all of the relationships found in the models, returning a rid: model dictionary.
- Return type
dict
-
_get_data
() Return the model’s data.
-
_get_deserialized_data
() Return the deserialized model data.
-
_model_schema
alias of
pydent.marshaller.base.PlanAssociationSchema
-
property
_primary_key
Returns the primary key (e.g. ‘id’) or the rid if id does not exist or is None.
-
_rid_dict
() Dictionary of all models attached to this model keyed by their rid.
-
add_data
(data) Initializes fake attributes that correspond to data.
-
anonymize
() Resets the primary key of the model and assigns a new rid.
Metatypes cannot be annonymized.
- Returns
self
-
append_to_many
(name, model) Appends a model to the many relationship.
- Parameters
name (str) – name of the relationship or attribute
model (ModelBase) – model to append
- Returns
None
- Return type
None
-
connect_to_session
(session) Connect model to a session.
- Parameters
session (
SessionABC
) – theAqSession
- Returns
None
- Raises
SessionAlreadySet – if session is already set
NoSessionError – if session is not a SessionABC type
-
copy
(keep=None) Provides a deepcopy of the model, but annonymizes the primary and global keys unless class is a metatype (e.g. OperationType, SampleType, FieldType) or class name is found in list of ‘keep’.
By default, inventory classes such as Sample, Item, and Collection are ‘kept’.
This specific usecase is that when copying whole plans, that the integrity of the inventory used in the operations is maintained. These are the items that refer to physical inventory in the laboratory and are referred to by their rids, and so it is important to that any of these inventory are always maintain their rids. Meaning in the lab, their is only ONE instance of the inventory. In Trident and Aquarium, there is only ONE instance of inventory that is referred to by its rid.
Similarly, any metatype model must also maintain their rid.
- Parameters
keep (
Optional
[bool
]) – list of model classes (as a list of strings) to keep un-anonymous- Return type
- Returns
copied model
-
dump
(only=None, include=None, ignore=None, include_model_type=False, include_uri=False) Dump (serialize) the Aquarium model instance to JSON.
- Parameters
only (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – dump only the provided keysinclude (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – include the provided nested dump keysignore (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – ignore the provided keysinclude_model_type (
bool
) – if True, include the model class type for each entry using the __model__ keyinclude_uri (
bool
) – if True, include a URI using the session URL and the tableized model class name using the __uri__ key. If a session is not attached, look for the url namespace in the ModelBase.DEFAULT_NAMESPACE class attribute, as in http://aquarium.org/samples/10.
- Return type
dict
- Returns
serialized model instance
-
classmethod
find
(session, model_id) Finds a model instance by its model_id.
- Return type
-
find_callback
(model_name, model_id) Finds a model using the model interface and model_id.
Used to find models in model relationships.
- Return type
-
get_deserialized
(name) Get deserialized data by name.
Deprecated since version 0.1.5a7: method will be removed in 0.2. Use self._get_deserialized_data[name] instead.
- Parameters
name – name of attribute
- Returns
-
classmethod
interface
(session) Creates a model interface from this class and a session.
This method can be overridden in model definitions for special cases.
- Return type
Union
[QueryInterface
,BrowserInterface
]
-
is_deserialized
(name) Check if a given key has already been deserialized.
New in version 0.1.5a7: Method added
- Parameters
name (
str
) – name of the attribute- Return type
bool
- Returns
True if key has been deserialized.
-
classmethod
load
(*args, **kwargs) Deserialize the data to a model.
- Parameters
data (dict) – data to deserialize
- Returns
the deserialized model
- Return type
-
classmethod
load_from
(data, owner=None) Create a new model instance from loaded attributes.
‘obj’ should have a o
-
model_schema
alias of
pydent.marshaller.base.PlanAssociationSchema
-
no_getter
(*_) Callback that always returns None.
-
refresh
() Refresh this model from data from the server.
- Returns
self
- Return type
self
-
reload
(data) Reload model attributes from new data.
- Parameters
data (dict) – data to update model instance
- Returns
model instance
- Return type
-
reset_field
(name) Reset the field descriptor to its placeholder value, returning the behavior.
New in version 0.1.5a7: Method added to reset deserialized attributes
- Parameters
name (
str
) – name of the attribute- Returns
None
-
property
session
The connected session instance.
-
property
uri
Return a URI for this model using the attached session url and tableized model name. For example, http://aquarium.org/samples/. If no session is attached, use the ModelBase.DEFAULT_NAMESPACE key for the url.
- Return type
str
- Returns
the instance URI
-
classmethod
where
(session, params) Finds a list of models by some parameters.
- Return type
Optional
[List
[ModelBase
]]
-
where_callback
(model_name, *args, **kwargs) Finds models using a model interface and a set of parameters.
Used to find models in model relationships.
- Return type
Optional
[List
[ModelBase
]]
-
class
pydent.models.
Sample
(name=None, project=None, description=None, sample_type=None, sample_type_id=None, properties=None, field_values=None)[source] Bases:
pydent.models.field_value_mixins.FieldValueInterface
,pydent.base.ModelBase
A Sample model.
- Parameters
name –
project –
description –
sample_type_id –
properties –
-
_check_for_session
() Raises error if model is not connected to a session.
:raises NoSessionError
-
classmethod
_flatten_deserialized_data
(models, memo) Flattens all of the relationships found in the models, returning a rid: model dictionary.
- Return type
dict
-
_get_data
() Return the model’s data.
-
_get_deserialized_data
() Return the deserialized model data.
-
_model_schema
alias of
pydent.marshaller.base.SampleSchema
-
property
_primary_key
Returns the primary key (e.g. ‘id’) or the rid if id does not exist or is None.
-
_rid_dict
() Dictionary of all models attached to this model keyed by their rid.
-
add_data
(data) Initializes fake attributes that correspond to data.
-
anonymize
() Resets the primary key of the model and assigns a new rid.
Metatypes cannot be annonymized.
- Returns
self
-
append_to_many
(name, model) Appends a model to the many relationship.
- Parameters
name (str) – name of the relationship or attribute
model (ModelBase) – model to append
- Returns
None
- Return type
None
-
connect_to_session
(session) Connect model to a session.
- Parameters
session (
SessionABC
) – theAqSession
- Returns
None
- Raises
SessionAlreadySet – if session is already set
NoSessionError – if session is not a SessionABC type
-
copy
()[source] Return a copy of this sample.
-
create
()[source] Creates this sample in the Aquarium instance if the sample has all fields required by the sample type. Uses is_savable to check for missing fields.
Changed in version 0.1.5a17: Raises AquariumModelError if sample is missing required properties
- Return type
List
[Sample
]- Returns
the list of saved samples
- Raises
AquariumModelError – if required FieldValues are missing.
-
dump
(only=None, include=None, ignore=None, include_model_type=False, include_uri=False) Dump (serialize) the Aquarium model instance to JSON.
- Parameters
only (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – dump only the provided keysinclude (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – include the provided nested dump keysignore (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – ignore the provided keysinclude_model_type (
bool
) – if True, include the model class type for each entry using the __model__ keyinclude_uri (
bool
) – if True, include a URI using the session URL and the tableized model class name using the __uri__ key. If a session is not attached, look for the url namespace in the ModelBase.DEFAULT_NAMESPACE class attribute, as in http://aquarium.org/samples/10.
- Return type
dict
- Returns
serialized model instance
-
field_value
(name)[source] Returns the
FieldValue
associated with the sample by its name. If the there is more than one FieldValue with the same name (as in field_value arrays), it will return the first FieldValue. See the.Sample.field_value_array()
method.- Parameters
name (str) – name of the field value
- Returns
the field value
- Return type
-
classmethod
find
(session, model_id) Finds a model instance by its model_id.
- Return type
-
find_callback
(model_name, model_id) Finds a model using the model interface and model_id.
Used to find models in model relationships.
- Return type
-
get_deserialized
(name) Get deserialized data by name.
Deprecated since version 0.1.5a7: method will be removed in 0.2. Use self._get_deserialized_data[name] instead.
- Parameters
name – name of attribute
- Returns
-
get_field_type
(name, role) Returns a
pydent.models.FieldType
by its name and role from the instance’s metaclass.- Parameters
name (basestring) – its name
role (basestring) – its role
- Returns
metatypes field type or None if not found
- Return type
FieldType | None
-
get_field_types
(name=None, role=None) Returns a list of
pydent.models.FieldType
by their name and role from the instance’s metaclass.- Parameters
name (basestring) – its name
role (basestring) – its role
- Returns
list of field types
- Return type
list
-
get_field_value
(name, role=None) Returns a
pydent.models.FieldValue
by its name and role.- Parameters
name (basestring) – its name
role (basestring) – its role
- Returns
the field value or None if not found
- Return type
FieldValue | None
-
get_field_value_array
(name, role=None) Returns a list of
pydent.models.FieldValue
by their name and role.- Parameters
name (basestring) – its name
role (basestring) – its role
- Returns
list of field values
- Return type
list
-
get_metatype
() Returns the instance’s metatype.
The metatype is either
pydent.models.SampleType
orpydent.models.OperationType
). The metatype class name is stored as METATYPE in the class definition.- Returns
the metatype
- Return type
-
get_routing
() Returns the routing dictionary for this instance.
- Returns
routing dictionary
- Return type
dict
-
property
identifier
Return the identifier used by Aquarium in autocompletes.
-
classmethod
interface
(session) Creates a model interface from this class and a session.
This method can be overridden in model definitions for special cases.
- Return type
Union
[QueryInterface
,BrowserInterface
]
-
is_deserialized
(name) Check if a given key has already been deserialized.
New in version 0.1.5a7: Method added
- Parameters
name (
str
) – name of the attribute- Return type
bool
- Returns
True if key has been deserialized.
-
is_savable
(do_raise=True)[source] - Checks whether this sample has fields required by the sample type.
If so, the sample can be saved or updated.
New in version 0.1.5a17.
- Parameters
do_raise (
bool
) – raise an exception when required field values are missing- Return type
Tuple
[bool
,List
[str
]]- Returns
a boolean whether there are errors, and list of error messages
- Raises
AquariumModelError – if do_raise is True and required fields are missing
-
classmethod
load
(*args, **kwargs) Deserialize the data to a model.
- Parameters
data (dict) – data to deserialize
- Returns
the deserialized model
- Return type
-
classmethod
load_from
(data, owner=None) Create a new model instance from loaded attributes.
‘obj’ should have a o
-
merge
()[source] Merge sample by name. If a sample with the same name and sample_type_id is found on the server, update that model and save the updated data to the server. Else, create a new sample on the server.
- Parameters
sample – sample to merge.
- Returns
True if merged, False otherwise
-
model_schema
alias of
pydent.marshaller.base.SampleSchema
-
new_field_value
(name, role=None, values_dict=None) Instantiates a new
pydent.models.FieldValue
from a name and role. The should be a field type with the name and role in the metatype. Optionally, a values dictionary may be provided with the following format:values_dict = { "value": None, "sample": mysample, "item": myitem, "object_type": None }
- Parameters
name (basestring) – its name
role (basestring) – its role
values_dict (dict) – values to set the new field value
- Returns
the new field value
- Return type
-
new_field_value_from_field_type
(field_type, values_dict=None) Instantiates a new
pydent.models.FieldValue
from a.pydent.models.FieldType
instance. Optionally, a values dictionary may be provided with the following format:values_dict = { "value": None, "sample": mysample, "item": myitem, "object_type": None }
- Parameters
field_type (FieldType) – field type to instantiate the field value
values_dict (dict) – values to set the new field value
- Returns
the new field value
- Return type
-
no_getter
(*_) Callback that always returns None.
-
refresh
() Refresh this model from data from the server.
- Returns
self
- Return type
self
-
reload
(data) Reload model attributes from new data.
- Parameters
data (dict) – data to update model instance
- Returns
model instance
- Return type
-
reset_field
(name) Reset the field descriptor to its placeholder value, returning the behavior.
New in version 0.1.5a7: Method added to reset deserialized attributes
- Parameters
name (
str
) – name of the attribute- Returns
None
-
safe_get_field_type
(fv) Safely returns the field value’s
pydent.models.FieldType
from the model.If the field value has no reference to the field type, its metatype (e.g.
pydent.models.SampleType
orpydent.models.OperationType
) is used to recover the field type.
-
save
()[source] Saves the sample, either by creating a new sample (if id=None) or updating the existing sample on the server.
Changed in version 0.1.5a17: Raises AquariumModelError if sample is missing required properties
- Returns
-
property
session
The connected session instance.
-
set_field_value
(name, role, values) Sets a field value name and role using a dictionary, as in the following:
values = { "value": None, "sample": mysample, "item": myitem, "object_type": None }
-
set_field_value_array
(name, role, values_array) Sets an array of field values by name and role using an array of dictionaries, as in the following:
values_array = [{ "value": None, "sample": mysample, "item": myitem, "object_type": None }]
-
update
()[source] Updates the sample on the server.
Changed in version 0.1.5a17: Raises AquariumModelError if sample is missing required properties
- Return type
Sample
- Returns
-
update_properties
(prop_dict)[source] Update the FieldValues properties for this sample.
- Parameters
prop_dict – values to update
- Returns
self
- Return type
-
property
uri
Return a URI for this model using the attached session url and tableized model name. For example, http://aquarium.org/samples/. If no session is attached, use the ModelBase.DEFAULT_NAMESPACE key for the url.
- Return type
str
- Returns
the instance URI
-
classmethod
where
(session, params) Finds a list of models by some parameters.
- Return type
Optional
[List
[ModelBase
]]
-
where_callback
(model_name, *args, **kwargs) Finds models using a model interface and a set of parameters.
Used to find models in model relationships.
- Return type
Optional
[List
[ModelBase
]]
-
class
pydent.models.
SampleType
(**data)[source] Bases:
pydent.models.field_value_mixins.FieldTypeInterface
,pydent.models.crud_mixin.JSONSaveMixin
,pydent.base.ModelBase
A SampleType model.
The model initializer.
- Parameters
data (dict) – data to add to the model
-
_check_for_session
() Raises error if model is not connected to a session.
:raises NoSessionError
-
classmethod
_flatten_deserialized_data
(models, memo) Flattens all of the relationships found in the models, returning a rid: model dictionary.
- Return type
dict
-
_get_data
() Return the model’s data.
-
_get_deserialized_data
() Return the deserialized model data.
-
_model_schema
alias of
pydent.marshaller.base.SampleTypeSchema
-
property
_primary_key
Returns the primary key (e.g. ‘id’) or the rid if id does not exist or is None.
-
_rid_dict
() Dictionary of all models attached to this model keyed by their rid.
-
add_data
(data) Initializes fake attributes that correspond to data.
-
anonymize
() Resets the primary key of the model and assigns a new rid.
Metatypes cannot be annonymized.
- Returns
self
-
append_to_many
(name, model) Appends a model to the many relationship.
- Parameters
name (str) – name of the relationship or attribute
model (ModelBase) – model to append
- Returns
None
- Return type
None
-
connect_to_session
(session) Connect model to a session.
- Parameters
session (
SessionABC
) – theAqSession
- Returns
None
- Raises
SessionAlreadySet – if session is already set
NoSessionError – if session is not a SessionABC type
-
copy
(keep=None) Provides a deepcopy of the model, but annonymizes the primary and global keys unless class is a metatype (e.g. OperationType, SampleType, FieldType) or class name is found in list of ‘keep’.
By default, inventory classes such as Sample, Item, and Collection are ‘kept’.
This specific usecase is that when copying whole plans, that the integrity of the inventory used in the operations is maintained. These are the items that refer to physical inventory in the laboratory and are referred to by their rids, and so it is important to that any of these inventory are always maintain their rids. Meaning in the lab, their is only ONE instance of the inventory. In Trident and Aquarium, there is only ONE instance of inventory that is referred to by its rid.
Similarly, any metatype model must also maintain their rid.
- Parameters
keep (
Optional
[bool
]) – list of model classes (as a list of strings) to keep un-anonymous- Return type
- Returns
copied model
-
dump
(only=None, include=None, ignore=None, include_model_type=False, include_uri=False) Dump (serialize) the Aquarium model instance to JSON.
- Parameters
only (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – dump only the provided keysinclude (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – include the provided nested dump keysignore (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – ignore the provided keysinclude_model_type (
bool
) – if True, include the model class type for each entry using the __model__ keyinclude_uri (
bool
) – if True, include a URI using the session URL and the tableized model class name using the __uri__ key. If a session is not attached, look for the url namespace in the ModelBase.DEFAULT_NAMESPACE class attribute, as in http://aquarium.org/samples/10.
- Return type
dict
- Returns
serialized model instance
-
field_type
(name, role=None)[source] Returns a
pydent.models.FieldType
by its name and role.- Parameters
name (basestring) – its name
role (basestring) – its role
- Returns
the field type or None if not found
- Return type
FieldType | None
-
classmethod
find
(session, model_id) Finds a model instance by its model_id.
- Return type
-
find_callback
(model_name, model_id) Finds a model using the model interface and model_id.
Used to find models in model relationships.
- Return type
-
get_deserialized
(name) Get deserialized data by name.
Deprecated since version 0.1.5a7: method will be removed in 0.2. Use self._get_deserialized_data[name] instead.
- Parameters
name – name of attribute
- Returns
-
classmethod
interface
(session) Creates a model interface from this class and a session.
This method can be overridden in model definitions for special cases.
- Return type
Union
[QueryInterface
,BrowserInterface
]
-
is_deserialized
(name) Check if a given key has already been deserialized.
New in version 0.1.5a7: Method added
- Parameters
name (
str
) – name of the attribute- Return type
bool
- Returns
True if key has been deserialized.
-
classmethod
load
(*args, **kwargs) Deserialize the data to a model.
- Parameters
data (dict) – data to deserialize
- Returns
the deserialized model
- Return type
-
classmethod
load_from
(data, owner=None) Create a new model instance from loaded attributes.
‘obj’ should have a o
-
model_schema
alias of
pydent.marshaller.base.SampleTypeSchema
-
no_getter
(*_) Callback that always returns None.
-
refresh
() Refresh this model from data from the server.
- Returns
self
- Return type
self
-
reload
(data) Reload model attributes from new data.
- Parameters
data (dict) – data to update model instance
- Returns
model instance
- Return type
-
reset_field
(name) Reset the field descriptor to its placeholder value, returning the behavior.
New in version 0.1.5a7: Method added to reset deserialized attributes
- Parameters
name (
str
) – name of the attribute- Returns
None
-
property
session
The connected session instance.
-
property
uri
Return a URI for this model using the attached session url and tableized model name. For example, http://aquarium.org/samples/. If no session is attached, use the ModelBase.DEFAULT_NAMESPACE key for the url.
- Return type
str
- Returns
the instance URI
-
classmethod
where
(session, params) Finds a list of models by some parameters.
- Return type
Optional
[List
[ModelBase
]]
-
where_callback
(model_name, *args, **kwargs) Finds models using a model interface and a set of parameters.
Used to find models in model relationships.
- Return type
Optional
[List
[ModelBase
]]
-
class
pydent.models.
Upload
(job_id=None, file=None)[source] Bases:
pydent.base.ModelBase
An Upload model.
Create a new upload.
- Parameters
job_id (int) – job id to associate the upload to
file (file object) – file to upload
-
_check_for_session
() Raises error if model is not connected to a session.
:raises NoSessionError
-
static
_download_file_from_url
(url, outpath)[source] Downloads a file from a url.
- Parameters
url (str) – url of file
outpath (str) – filepath of out file
- Returns
http response
- Return type
str
-
static
_download_files
(uploads, outdir, overwrite)[source] Downloads uploaded file from list of
Upload
models.- Parameters
uploads (list) – list of Uploads
outdir (str) – path to output directory to save downloaded files (defaults to current directory)
overwrite (bool) – if True, will overwrite existing files (default: True)
- Returns
list of filepaths
- Return type
list
-
classmethod
_flatten_deserialized_data
(models, memo) Flattens all of the relationships found in the models, returning a rid: model dictionary.
- Return type
dict
-
_get_data
() Return the model’s data.
-
_get_deserialized_data
() Return the deserialized model data.
-
_model_schema
alias of
pydent.marshaller.base.UploadSchema
-
property
_primary_key
Returns the primary key (e.g. ‘id’) or the rid if id does not exist or is None.
-
_rid_dict
() Dictionary of all models attached to this model keyed by their rid.
-
add_data
(data) Initializes fake attributes that correspond to data.
-
anonymize
() Resets the primary key of the model and assigns a new rid.
Metatypes cannot be annonymized.
- Returns
self
-
append_to_many
(name, model) Appends a model to the many relationship.
- Parameters
name (str) – name of the relationship or attribute
model (ModelBase) – model to append
- Returns
None
- Return type
None
-
static
async_download
(uploads, outdir=None, overwrite=True)[source] Asynchronously downloads from list of
Upload
models.- Parameters
uploads (list) – list of Uploads
outdir (str) – path to output directory to save downloaded files
overwrite (bool) – if True, will overwrite existing files
- Returns
list of filepaths
- Return type
list
-
connect_to_session
(session) Connect model to a session.
- Parameters
session (
SessionABC
) – theAqSession
- Returns
None
- Raises
SessionAlreadySet – if session is already set
NoSessionError – if session is not a SessionABC type
-
copy
(keep=None) Provides a deepcopy of the model, but annonymizes the primary and global keys unless class is a metatype (e.g. OperationType, SampleType, FieldType) or class name is found in list of ‘keep’.
By default, inventory classes such as Sample, Item, and Collection are ‘kept’.
This specific usecase is that when copying whole plans, that the integrity of the inventory used in the operations is maintained. These are the items that refer to physical inventory in the laboratory and are referred to by their rids, and so it is important to that any of these inventory are always maintain their rids. Meaning in the lab, their is only ONE instance of the inventory. In Trident and Aquarium, there is only ONE instance of inventory that is referred to by its rid.
Similarly, any metatype model must also maintain their rid.
- Parameters
keep (
Optional
[bool
]) – list of model classes (as a list of strings) to keep un-anonymous- Return type
- Returns
copied model
-
create
()[source] Save the upload to the server.
-
property
data
Return the data associated with the upload.
-
download
(outdir=None, filename=None, overwrite=True)[source] Downloads the uploaded file to the specified output directory. If no output directory is specified, the file will be downloaded to the current directory.
- Parameters
outdir (
Optional
[str
]) – path of directory of output file (default is current directory)outfile – filename of output file (defaults to upload_filename)
overwrite (
bool
) – whether to overwrite file if it already exists
- Returns
filepath of the downloaded file
-
dump
(only=None, include=None, ignore=None, include_model_type=False, include_uri=False) Dump (serialize) the Aquarium model instance to JSON.
- Parameters
only (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – dump only the provided keysinclude (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – include the provided nested dump keysignore (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – ignore the provided keysinclude_model_type (
bool
) – if True, include the model class type for each entry using the __model__ keyinclude_uri (
bool
) – if True, include a URI using the session URL and the tableized model class name using the __uri__ key. If a session is not attached, look for the url namespace in the ModelBase.DEFAULT_NAMESPACE class attribute, as in http://aquarium.org/samples/10.
- Return type
dict
- Returns
serialized model instance
-
fetch
(outdir=None, filename=None, overwrite=True)[source] Alias for download
- Parameters
outdir (
Optional
[str
]) – path of directory of output file (default is current directory)outfile – filename of output file (defaults to upload_filename)
overwrite (
bool
) – whether to overwrite file if it already exists
- Returns
filepath of the downloaded file
-
classmethod
find
(session, model_id) Finds a model instance by its model_id.
- Return type
-
find_callback
(model_name, model_id) Finds a model using the model interface and model_id.
Used to find models in model relationships.
- Return type
-
get_deserialized
(name) Get deserialized data by name.
Deprecated since version 0.1.5a7: method will be removed in 0.2. Use self._get_deserialized_data[name] instead.
- Parameters
name – name of attribute
- Returns
-
classmethod
interface
(session) Creates a model interface from this class and a session.
This method can be overridden in model definitions for special cases.
- Return type
Union
[QueryInterface
,BrowserInterface
]
-
is_deserialized
(name) Check if a given key has already been deserialized.
New in version 0.1.5a7: Method added
- Parameters
name (
str
) – name of the attribute- Return type
bool
- Returns
True if key has been deserialized.
-
classmethod
load
(*args, **kwargs) Deserialize the data to a model.
- Parameters
data (dict) – data to deserialize
- Returns
the deserialized model
- Return type
-
classmethod
load_from
(data, owner=None) Create a new model instance from loaded attributes.
‘obj’ should have a o
-
model_schema
alias of
pydent.marshaller.base.UploadSchema
-
no_getter
(*_) Callback that always returns None.
-
refresh
() Refresh this model from data from the server.
- Returns
self
- Return type
self
-
reload
(data) Reload model attributes from new data.
- Parameters
data (dict) – data to update model instance
- Returns
model instance
- Return type
-
reset_field
(name) Reset the field descriptor to its placeholder value, returning the behavior.
New in version 0.1.5a7: Method added to reset deserialized attributes
- Parameters
name (
str
) – name of the attribute- Returns
None
-
property
session
The connected session instance.
-
property
uri
Return a URI for this model using the attached session url and tableized model name. For example, http://aquarium.org/samples/. If no session is attached, use the ModelBase.DEFAULT_NAMESPACE key for the url.
- Return type
str
- Returns
the instance URI
-
classmethod
where
(session, params) Finds a list of models by some parameters.
- Return type
Optional
[List
[ModelBase
]]
-
where_callback
(model_name, *args, **kwargs) Finds models using a model interface and a set of parameters.
Used to find models in model relationships.
- Return type
Optional
[List
[ModelBase
]]
-
class
pydent.models.
User
[source] Bases:
pydent.base.ModelBase
A User model.
The model initializer.
- Parameters
data (dict) – data to add to the model
-
_check_for_session
() Raises error if model is not connected to a session.
:raises NoSessionError
-
classmethod
_flatten_deserialized_data
(models, memo) Flattens all of the relationships found in the models, returning a rid: model dictionary.
- Return type
dict
-
_get_data
() Return the model’s data.
-
_get_deserialized_data
() Return the deserialized model data.
-
_model_schema
alias of
pydent.marshaller.base.UserSchema
-
property
_primary_key
Returns the primary key (e.g. ‘id’) or the rid if id does not exist or is None.
-
_rid_dict
() Dictionary of all models attached to this model keyed by their rid.
-
add_data
(data) Initializes fake attributes that correspond to data.
-
anonymize
() Resets the primary key of the model and assigns a new rid.
Metatypes cannot be annonymized.
- Returns
self
-
append_to_many
(name, model) Appends a model to the many relationship.
- Parameters
name (str) – name of the relationship or attribute
model (ModelBase) – model to append
- Returns
None
- Return type
None
-
connect_to_session
(session) Connect model to a session.
- Parameters
session (
SessionABC
) – theAqSession
- Returns
None
- Raises
SessionAlreadySet – if session is already set
NoSessionError – if session is not a SessionABC type
-
copy
(keep=None) Provides a deepcopy of the model, but annonymizes the primary and global keys unless class is a metatype (e.g. OperationType, SampleType, FieldType) or class name is found in list of ‘keep’.
By default, inventory classes such as Sample, Item, and Collection are ‘kept’.
This specific usecase is that when copying whole plans, that the integrity of the inventory used in the operations is maintained. These are the items that refer to physical inventory in the laboratory and are referred to by their rids, and so it is important to that any of these inventory are always maintain their rids. Meaning in the lab, their is only ONE instance of the inventory. In Trident and Aquarium, there is only ONE instance of inventory that is referred to by its rid.
Similarly, any metatype model must also maintain their rid.
- Parameters
keep (
Optional
[bool
]) – list of model classes (as a list of strings) to keep un-anonymous- Return type
- Returns
copied model
-
dump
(only=None, include=None, ignore=None, include_model_type=False, include_uri=False) Dump (serialize) the Aquarium model instance to JSON.
- Parameters
only (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – dump only the provided keysinclude (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – include the provided nested dump keysignore (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – ignore the provided keysinclude_model_type (
bool
) – if True, include the model class type for each entry using the __model__ keyinclude_uri (
bool
) – if True, include a URI using the session URL and the tableized model class name using the __uri__ key. If a session is not attached, look for the url namespace in the ModelBase.DEFAULT_NAMESPACE class attribute, as in http://aquarium.org/samples/10.
- Return type
dict
- Returns
serialized model instance
-
classmethod
find
(session, model_id) Finds a model instance by its model_id.
- Return type
-
find_callback
(model_name, model_id) Finds a model using the model interface and model_id.
Used to find models in model relationships.
- Return type
-
get_deserialized
(name) Get deserialized data by name.
Deprecated since version 0.1.5a7: method will be removed in 0.2. Use self._get_deserialized_data[name] instead.
- Parameters
name – name of attribute
- Returns
-
classmethod
interface
(session) Creates a model interface from this class and a session.
This method can be overridden in model definitions for special cases.
- Return type
Union
[QueryInterface
,BrowserInterface
]
-
is_deserialized
(name) Check if a given key has already been deserialized.
New in version 0.1.5a7: Method added
- Parameters
name (
str
) – name of the attribute- Return type
bool
- Returns
True if key has been deserialized.
-
classmethod
load
(*args, **kwargs) Deserialize the data to a model.
- Parameters
data (dict) – data to deserialize
- Returns
the deserialized model
- Return type
-
classmethod
load_from
(data, owner=None) Create a new model instance from loaded attributes.
‘obj’ should have a o
-
model_schema
alias of
pydent.marshaller.base.UserSchema
-
no_getter
(*_) Callback that always returns None.
-
refresh
() Refresh this model from data from the server.
- Returns
self
- Return type
self
-
reload
(data) Reload model attributes from new data.
- Parameters
data (dict) – data to update model instance
- Returns
model instance
- Return type
-
reset_field
(name) Reset the field descriptor to its placeholder value, returning the behavior.
New in version 0.1.5a7: Method added to reset deserialized attributes
- Parameters
name (
str
) – name of the attribute- Returns
None
-
property
session
The connected session instance.
-
property
uri
Return a URI for this model using the attached session url and tableized model name. For example, http://aquarium.org/samples/. If no session is attached, use the ModelBase.DEFAULT_NAMESPACE key for the url.
- Return type
str
- Returns
the instance URI
-
classmethod
where
(session, params) Finds a list of models by some parameters.
- Return type
Optional
[List
[ModelBase
]]
-
where_callback
(model_name, *args, **kwargs) Finds models using a model interface and a set of parameters.
Used to find models in model relationships.
- Return type
Optional
[List
[ModelBase
]]
-
class
pydent.models.
UserBudgetAssociation
[source] Bases:
pydent.base.ModelBase
An association model between a User and a Budget.
The model initializer.
- Parameters
data (dict) – data to add to the model
-
_check_for_session
() Raises error if model is not connected to a session.
:raises NoSessionError
-
classmethod
_flatten_deserialized_data
(models, memo) Flattens all of the relationships found in the models, returning a rid: model dictionary.
- Return type
dict
-
_get_data
() Return the model’s data.
-
_get_deserialized_data
() Return the deserialized model data.
-
_model_schema
alias of
pydent.marshaller.base.UserBudgetAssociationSchema
-
property
_primary_key
Returns the primary key (e.g. ‘id’) or the rid if id does not exist or is None.
-
_rid_dict
() Dictionary of all models attached to this model keyed by their rid.
-
add_data
(data) Initializes fake attributes that correspond to data.
-
anonymize
() Resets the primary key of the model and assigns a new rid.
Metatypes cannot be annonymized.
- Returns
self
-
append_to_many
(name, model) Appends a model to the many relationship.
- Parameters
name (str) – name of the relationship or attribute
model (ModelBase) – model to append
- Returns
None
- Return type
None
-
connect_to_session
(session) Connect model to a session.
- Parameters
session (
SessionABC
) – theAqSession
- Returns
None
- Raises
SessionAlreadySet – if session is already set
NoSessionError – if session is not a SessionABC type
-
copy
(keep=None) Provides a deepcopy of the model, but annonymizes the primary and global keys unless class is a metatype (e.g. OperationType, SampleType, FieldType) or class name is found in list of ‘keep’.
By default, inventory classes such as Sample, Item, and Collection are ‘kept’.
This specific usecase is that when copying whole plans, that the integrity of the inventory used in the operations is maintained. These are the items that refer to physical inventory in the laboratory and are referred to by their rids, and so it is important to that any of these inventory are always maintain their rids. Meaning in the lab, their is only ONE instance of the inventory. In Trident and Aquarium, there is only ONE instance of inventory that is referred to by its rid.
Similarly, any metatype model must also maintain their rid.
- Parameters
keep (
Optional
[bool
]) – list of model classes (as a list of strings) to keep un-anonymous- Return type
- Returns
copied model
-
dump
(only=None, include=None, ignore=None, include_model_type=False, include_uri=False) Dump (serialize) the Aquarium model instance to JSON.
- Parameters
only (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – dump only the provided keysinclude (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – include the provided nested dump keysignore (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – ignore the provided keysinclude_model_type (
bool
) – if True, include the model class type for each entry using the __model__ keyinclude_uri (
bool
) – if True, include a URI using the session URL and the tableized model class name using the __uri__ key. If a session is not attached, look for the url namespace in the ModelBase.DEFAULT_NAMESPACE class attribute, as in http://aquarium.org/samples/10.
- Return type
dict
- Returns
serialized model instance
-
classmethod
find
(session, model_id) Finds a model instance by its model_id.
- Return type
-
find_callback
(model_name, model_id) Finds a model using the model interface and model_id.
Used to find models in model relationships.
- Return type
-
get_deserialized
(name) Get deserialized data by name.
Deprecated since version 0.1.5a7: method will be removed in 0.2. Use self._get_deserialized_data[name] instead.
- Parameters
name – name of attribute
- Returns
-
classmethod
interface
(session) Creates a model interface from this class and a session.
This method can be overridden in model definitions for special cases.
- Return type
Union
[QueryInterface
,BrowserInterface
]
-
is_deserialized
(name) Check if a given key has already been deserialized.
New in version 0.1.5a7: Method added
- Parameters
name (
str
) – name of the attribute- Return type
bool
- Returns
True if key has been deserialized.
-
classmethod
load
(*args, **kwargs) Deserialize the data to a model.
- Parameters
data (dict) – data to deserialize
- Returns
the deserialized model
- Return type
-
classmethod
load_from
(data, owner=None) Create a new model instance from loaded attributes.
‘obj’ should have a o
-
model_schema
alias of
pydent.marshaller.base.UserBudgetAssociationSchema
-
no_getter
(*_) Callback that always returns None.
-
refresh
() Refresh this model from data from the server.
- Returns
self
- Return type
self
-
reload
(data) Reload model attributes from new data.
- Parameters
data (dict) – data to update model instance
- Returns
model instance
- Return type
-
reset_field
(name) Reset the field descriptor to its placeholder value, returning the behavior.
New in version 0.1.5a7: Method added to reset deserialized attributes
- Parameters
name (
str
) – name of the attribute- Returns
None
-
property
session
The connected session instance.
-
property
uri
Return a URI for this model using the attached session url and tableized model name. For example, http://aquarium.org/samples/. If no session is attached, use the ModelBase.DEFAULT_NAMESPACE key for the url.
- Return type
str
- Returns
the instance URI
-
classmethod
where
(session, params) Finds a list of models by some parameters.
- Return type
Optional
[List
[ModelBase
]]
-
where_callback
(model_name, *args, **kwargs) Finds models using a model interface and a set of parameters.
Used to find models in model relationships.
- Return type
Optional
[List
[ModelBase
]]
-
class
pydent.models.
Wire
(source=None, destination=None)[source] Bases:
pydent.models.crud_mixin.DeleteMixin
,pydent.base.ModelBase
A Wire model.
-
_check_for_session
() Raises error if model is not connected to a session.
:raises NoSessionError
-
classmethod
_flatten_deserialized_data
(models, memo) Flattens all of the relationships found in the models, returning a rid: model dictionary.
- Return type
dict
-
_get_data
() Return the model’s data.
-
_get_deserialized_data
() Return the deserialized model data.
-
_model_schema
alias of
pydent.marshaller.base.WireSchema
-
property
_primary_key
Returns the primary key (e.g. ‘id’) or the rid if id does not exist or is None.
-
_rid_dict
() Dictionary of all models attached to this model keyed by their rid.
-
add_data
(data) Initializes fake attributes that correspond to data.
-
anonymize
() Resets the primary key of the model and assigns a new rid.
Metatypes cannot be annonymized.
- Returns
self
-
append_to_many
(name, model) Appends a model to the many relationship.
- Parameters
name (str) – name of the relationship or attribute
model (ModelBase) – model to append
- Returns
None
- Return type
None
-
connect_to_session
(session) Connect model to a session.
- Parameters
session (
SessionABC
) – theAqSession
- Returns
None
- Raises
SessionAlreadySet – if session is already set
NoSessionError – if session is not a SessionABC type
-
copy
(keep=None) Provides a deepcopy of the model, but annonymizes the primary and global keys unless class is a metatype (e.g. OperationType, SampleType, FieldType) or class name is found in list of ‘keep’.
By default, inventory classes such as Sample, Item, and Collection are ‘kept’.
This specific usecase is that when copying whole plans, that the integrity of the inventory used in the operations is maintained. These are the items that refer to physical inventory in the laboratory and are referred to by their rids, and so it is important to that any of these inventory are always maintain their rids. Meaning in the lab, their is only ONE instance of the inventory. In Trident and Aquarium, there is only ONE instance of inventory that is referred to by its rid.
Similarly, any metatype model must also maintain their rid.
- Parameters
keep (
Optional
[bool
]) – list of model classes (as a list of strings) to keep un-anonymous- Return type
- Returns
copied model
-
delete
()[source] Permanently deletes the wire instance on the Aquarium server.
- Returns
- Return type
-
does_wire
(source, destination)[source] Checks whether this Wire is a wire between the source and destination FieldValues.
If any of the source or destination FieldValues are None, returns False.
-
dump
(only=None, include=None, ignore=None, include_model_type=False, include_uri=False) Dump (serialize) the Aquarium model instance to JSON.
- Parameters
only (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – dump only the provided keysinclude (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – include the provided nested dump keysignore (
Union
[str
,List
[str
],Tuple
[str
],Dict
[str
,Any
],None
]) – ignore the provided keysinclude_model_type (
bool
) – if True, include the model class type for each entry using the __model__ keyinclude_uri (
bool
) – if True, include a URI using the session URL and the tableized model class name using the __uri__ key. If a session is not attached, look for the url namespace in the ModelBase.DEFAULT_NAMESPACE class attribute, as in http://aquarium.org/samples/10.
- Return type
dict
- Returns
serialized model instance
-
classmethod
find
(session, model_id) Finds a model instance by its model_id.
- Return type
-
find_callback
(model_name, model_id) Finds a model using the model interface and model_id.
Used to find models in model relationships.
- Return type
-
get_deserialized
(name) Get deserialized data by name.
Deprecated since version 0.1.5a7: method will be removed in 0.2. Use self._get_deserialized_data[name] instead.
- Parameters
name – name of attribute
- Returns
-
classmethod
interface
(session) Creates a model interface from this class and a session.
This method can be overridden in model definitions for special cases.
- Return type
Union
[QueryInterface
,BrowserInterface
]
-
is_deserialized
(name) Check if a given key has already been deserialized.
New in version 0.1.5a7: Method added
- Parameters
name (
str
) – name of the attribute- Return type
bool
- Returns
True if key has been deserialized.
-
classmethod
load
(*args, **kwargs) Deserialize the data to a model.
- Parameters
data (dict) – data to deserialize
- Returns
the deserialized model
- Return type
-
classmethod
load_from
(data, owner=None) Create a new model instance from loaded attributes.
‘obj’ should have a o
-
model_schema
alias of
pydent.marshaller.base.WireSchema
-
no_getter
(*_) Callback that always returns None.
-
refresh
() Refresh this model from data from the server.
- Returns
self
- Return type
self
-
reload
(data) Reload model attributes from new data.
- Parameters
data (dict) – data to update model instance
- Returns
model instance
- Return type
-
reset_field
(name) Reset the field descriptor to its placeholder value, returning the behavior.
New in version 0.1.5a7: Method added to reset deserialized attributes
- Parameters
name (
str
) – name of the attribute- Returns
None
-
property
session
The connected session instance.
-
show
(pre='')[source] Show the wire nicely.
-
property
uri
Return a URI for this model using the attached session url and tableized model name. For example, http://aquarium.org/samples/. If no session is attached, use the ModelBase.DEFAULT_NAMESPACE key for the url.
- Return type
str
- Returns
the instance URI
-
classmethod
where
(session, params) Finds a list of models by some parameters.
- Return type
Optional
[List
[ModelBase
]]
-
where_callback
(model_name, *args, **kwargs) Finds models using a model interface and a set of parameters.
Used to find models in model relationships.
- Return type
Optional
[List
[ModelBase
]]
-