spinedb_api.db_mapping
This module defines the DatabaseMapping
class, the main mean to communicate with a Spine DB.
If you’re planning to use this class, it is probably a good idea to first familiarize yourself a little bit with the
DB mapping schema.
Module Contents
Classes
Enables communication with a Spine DB. |
- class spinedb_api.db_mapping.DatabaseMapping(db_url, username=None, upgrade=False, backup_url='', codename=None, create=False, apply_filters=True, memory=False, sqlite_timeout=1800)[source]
Bases:
spinedb_api.db_mapping_query_mixin.DatabaseMappingQueryMixin
,spinedb_api.db_mapping_commit_mixin.DatabaseMappingCommitMixin
,spinedb_api.db_mapping_base.DatabaseMappingBase
Enables communication with a Spine DB.
The DB is incrementally mapped into memory as data is requested/modified, following the DB mapping schema.
Data is typically retrieved using
get_item()
orget_items()
. If the requested data is already in memory, it is returned from there; otherwise it is fetched from the DB, stored in memory, and then returned. In other words, the data is fetched from the DB exactly once.For convenience, we also provide specialized ‘get’ methods for each item type, e.g.,
get_entity_item()
andget_entity_items()
.Data is added via
add_item()
; updated viaupdate_item()
; removed viaremove_item()
; and restored viarestore_item()
. All the above methods modify the in-memory mapping (not the DB itself). These methods also fetch data from the DB into the in-memory mapping to perform the necessary integrity checks (unique and foreign key constraints).For convenience, we also provide specialized ‘add’, ‘update’, ‘remove’, and ‘restore’ methods for each item type, e.g.,
add_entity_item()
,update_entity_item()
,remove_entity_item()
,restore_entity_item()
.Modifications to the in-memory mapping are committed (written) to the DB via
commit_session()
, or rolled back (discarded) viarollback_session()
.The DB fetch status is reset via
refresh_session()
. This allows new items in the DB (added by other clients in the meantime) to be retrieved as well.You can also control the fetching process via
fetch_more()
and/orfetch_all()
. For example, you can callfetch_more()
in a dedicated thread while you do some work on the main thread. This will nicely place items in the in-memory mapping so you can access them later, without the overhead of fetching them from the DB.The
query()
method is also provided as an alternative way to retrieve data from the DB while bypassing the in-memory mapping entirely.You can use this class as a context manager, e.g.:
with DatabaseMapping(db_url) as db_map: # Do stuff with db_map ...
- Parameters:
db_url (str or
URL
) – A URL in RFC-1738 format pointing to the database to be mapped, or to a DB server.username (str, optional) – A user name. If not given, it gets replaced by the string anon.
upgrade (bool, optional) – Whether the DB at the given url should be upgraded to the most recent version.
backup_url (str, optional) – A URL to backup the DB before upgrading.
codename (str, optional) – A name to identify this object in your application.
create (bool, optional) – Whether to create a new Spine DB at the given url if it’s not already one.
apply_filters (bool, optional) – Whether to apply filters in the url’s query segment.
memory (bool, optional) – Whether to use a SQLite memory DB as replacement for the original one.
sqlite_timeout (int, optional) – The number of seconds to wait before raising SQLite connection errors.
- static get_upgrade_db_prompt_data(url, create=False)[source]
Returns data to prompt the user what to do if the DB at the given url is not the latest version. If it is, then returns None.
- Parameters:
- Returns:
The title of the prompt str: The text of the prompt dict: Mapping different options, to kwargs to pass to DatabaseMapping constructor in order to apply them dict or None: Mapping different options, to additional notes int or None: The preferred option if any
- Return type:
- get_item(item_type, fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns an item matching the arguments, or None if none found.
Example:
with DatabaseMapping(db_url) as db_map: prince = db_map.get_item("entity", entity_class_name="musician", name="Prince")
- Parameters:
item_type (str) – One of
alternative
,scenario
,scenario_alternative
,entity_class
,superclass_subclass
,entity
,entity_group
,entity_alternative
,parameter_value_list
,list_value
,parameter_definition
,parameter_value
,metadata
,entity_metadata
,parameter_value_metadata
.fetch (bool, optional) – Whether to fetch the DB in case the item is not found in memory.
skip_removed (bool, optional) – Whether to ignore removed items.
**kwargs – Fields and values for one the unique keys as specified for the item type in DB mapping schema.
- Returns:
PublicItem
or None
- get_items(item_type, fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns all the items of one type.
- Parameters:
item_type (str) – One of
alternative
,scenario
,scenario_alternative
,entity_class
,superclass_subclass
,entity
,entity_group
,entity_alternative
,parameter_value_list
,list_value
,parameter_definition
,parameter_value
,metadata
,entity_metadata
,parameter_value_metadata
.fetch (bool, optional) – Whether to fetch the DB before returning the items.
skip_removed (bool, optional) – Whether to ignore removed items.
**kwargs – Fields and values for one the unique keys as specified for the item type in DB mapping schema.
- Returns:
The items.
- Return type:
list(
PublicItem
)
- add_item(item_type, check=True, **kwargs)[source]
Adds an item to the in-memory mapping.
Example:
with DatabaseMapping(db_url) as db_map: db_map.add_item("entity_class", name="musician") db_map.add_item("entity", entity_class_name="musician", name="Prince")
- Parameters:
item_type (str) – One of
alternative
,scenario
,scenario_alternative
,entity_class
,superclass_subclass
,entity
,entity_group
,entity_alternative
,parameter_value_list
,list_value
,parameter_definition
,parameter_value
,metadata
,entity_metadata
,parameter_value_metadata
.**kwargs – Fields and values as specified for the item type in DB mapping schema.
- Returns:
The added item and any errors.
- Return type:
tuple(
PublicItem
or None, str)
- add_items(item_type, *items, check=True, strict=False)[source]
Adds many items to the in-memory mapping.
- Parameters:
item_type (str) – One of
alternative
,scenario
,scenario_alternative
,entity_class
,superclass_subclass
,entity
,entity_group
,entity_alternative
,parameter_value_list
,list_value
,parameter_definition
,parameter_value
,metadata
,entity_metadata
,parameter_value_metadata
.*items (Iterable(dict)) – One or more
dict
objects mapping fields to values of the item type, as specified in DB mapping schema.strict (bool) – Whether or not the method should raise
SpineIntegrityError
if the insertion of one of the items violates an integrity constraint.
- Returns:
items successfully added and found violations.
- Return type:
tuple(list(
PublicItem
),list(str))
- update_item(item_type, check=True, **kwargs)[source]
Updates an item in the in-memory mapping.
Example:
with DatabaseMapping(db_url) as db_map: prince = db_map.get_item("entity", entity_class_name="musician", name="Prince") db_map.update_item( "entity", id=prince["id"], name="the Artist", description="Formerly known as Prince." )
- Parameters:
item_type (str) – One of
alternative
,scenario
,scenario_alternative
,entity_class
,superclass_subclass
,entity
,entity_group
,entity_alternative
,parameter_value_list
,list_value
,parameter_definition
,parameter_value
,metadata
,entity_metadata
,parameter_value_metadata
.id (int) – The id of the item to update.
**kwargs – Fields to update and their new values as specified for the item type in DB mapping schema.
- Returns:
The updated item and any errors.
- Return type:
tuple(
PublicItem
or None, str)
- update_items(item_type, *items, check=True, strict=False)[source]
Updates many items in the in-memory mapping.
- Parameters:
item_type (str) – One of
alternative
,scenario
,scenario_alternative
,entity_class
,superclass_subclass
,entity
,entity_group
,entity_alternative
,parameter_value_list
,list_value
,parameter_definition
,parameter_value
,metadata
,entity_metadata
,parameter_value_metadata
.*items (Iterable(dict)) – One or more
dict
objects mapping fields to values of the item type, as specified in DB mapping schema and including the id.strict (bool) – Whether or not the method should raise
SpineIntegrityError
if the update of one of the items violates an integrity constraint.
- Returns:
items successfully updated and found violations.
- Return type:
tuple(list(
PublicItem
),list(str))
- add_update_item(item_type, check=True, **kwargs)[source]
Adds an item to the in-memory mapping if it doesn’t exist; otherwise updates the current one.
- Parameters:
item_type (str) – One of
alternative
,scenario
,scenario_alternative
,entity_class
,superclass_subclass
,entity
,entity_group
,entity_alternative
,parameter_value_list
,list_value
,parameter_definition
,parameter_value
,metadata
,entity_metadata
,parameter_value_metadata
.**kwargs – Fields and values as specified for the item type in DB mapping schema.
- Returns:
- The added item if any,
the updated item if any, and any errors.
- Return type:
tuple(
PublicItem
or None,PublicItem
or None, str)
- add_update_items(item_type, *items, check=True, strict=False)[source]
Adds or updates many items into the in-memory mapping.
- Parameters:
item_type (str) – One of
alternative
,scenario
,scenario_alternative
,entity_class
,superclass_subclass
,entity
,entity_group
,entity_alternative
,parameter_value_list
,list_value
,parameter_definition
,parameter_value
,metadata
,entity_metadata
,parameter_value_metadata
.*items (Iterable(dict)) – One or more
dict
objects mapping fields to values of the item type, as specified in DB mapping schema.strict (bool) – Whether or not the method should raise
SpineIntegrityError
if the insertion of one of the items violates an integrity constraint.
- Returns:
- items successfully added,
items successfully updated, and found violations.
- Return type:
tuple(list(
PublicItem
),list(PublicItem
),list(str))
- remove_item(item_type, id_, check=True)[source]
Removes an item from the in-memory mapping.
Example:
with DatabaseMapping(db_url) as db_map: prince = db_map.get_item("entity", entity_class_name="musician", name="Prince") db_map.remove_item("entity", prince["id"])
- Parameters:
item_type (str) – One of
alternative
,scenario
,scenario_alternative
,entity_class
,superclass_subclass
,entity
,entity_group
,entity_alternative
,parameter_value_list
,list_value
,parameter_definition
,parameter_value
,metadata
,entity_metadata
,parameter_value_metadata
.id (int) – The id of the item to remove.
- Returns:
The removed item and any errors.
- Return type:
tuple(
PublicItem
or None, str)
- remove_items(item_type, *ids, check=True, strict=False)[source]
Removes many items from the in-memory mapping.
- Parameters:
item_type (str) – One of
alternative
,scenario
,scenario_alternative
,entity_class
,superclass_subclass
,entity
,entity_group
,entity_alternative
,parameter_value_list
,list_value
,parameter_definition
,parameter_value
,metadata
,entity_metadata
,parameter_value_metadata
.*ids (Iterable(int)) – Ids of items to be removed.
strict (bool) – Whether or not the method should raise
SpineIntegrityError
if the update of one of the items violates an integrity constraint.
- Returns:
items successfully removed and found violations.
- Return type:
tuple(list(
PublicItem
),list(str))
- restore_item(item_type, id_)[source]
Restores a previously removed item into the in-memory mapping.
Example:
with DatabaseMapping(db_url) as db_map: prince = db_map.get_item("entity", skip_remove=False, entity_class_name="musician", name="Prince") db_map.restore_item("entity", prince["id"])
- Parameters:
item_type (str) – One of
alternative
,scenario
,scenario_alternative
,entity_class
,superclass_subclass
,entity
,entity_group
,entity_alternative
,parameter_value_list
,list_value
,parameter_definition
,parameter_value
,metadata
,entity_metadata
,parameter_value_metadata
.id (int) – The id of the item to restore.
- Returns:
The restored item if any.
- Return type:
tuple(
PublicItem
or None, str)
- restore_items(item_type, *ids)[source]
Restores many previously removed items into the in-memory mapping.
- Parameters:
item_type (str) – One of
alternative
,scenario
,scenario_alternative
,entity_class
,superclass_subclass
,entity
,entity_group
,entity_alternative
,parameter_value_list
,list_value
,parameter_definition
,parameter_value
,metadata
,entity_metadata
,parameter_value_metadata
.*ids (Iterable(int)) – Ids of items to be removed.
- Returns:
the restored items.
- Return type:
list(
PublicItem
)
- purge_items(item_type)[source]
Removes all items of one type.
- Parameters:
item_type (str) – One of
alternative
,scenario
,scenario_alternative
,entity_class
,superclass_subclass
,entity
,entity_group
,entity_alternative
,parameter_value_list
,list_value
,parameter_definition
,parameter_value
,metadata
,entity_metadata
,parameter_value_metadata
.- Returns:
True if any data was removed, False otherwise.
- Return type:
- fetch_more(item_type, offset=0, limit=None, **kwargs)[source]
Fetches items from the DB into the in-memory mapping, incrementally.
- Parameters:
item_type (str) – One of
alternative
,scenario
,scenario_alternative
,entity_class
,superclass_subclass
,entity
,entity_group
,entity_alternative
,parameter_value_list
,list_value
,parameter_definition
,parameter_value
,metadata
,entity_metadata
,parameter_value_metadata
.offset (int) – The initial row.
limit (int) – The maximum number of rows to fetch.
**kwargs – Fields and values for one the unique keys as specified for the item type in DB mapping schema.
- Returns:
The items fetched.
- Return type:
list(
PublicItem
)
- fetch_all(*item_types)[source]
Fetches items from the DB into the in-memory mapping. Unlike
fetch_more()
, this method fetches entire tables.- Parameters:
*item_types (Iterable(str)) – One or more of
alternative
,scenario
,scenario_alternative
,entity_class
,superclass_subclass
,entity
,entity_group
,entity_alternative
,parameter_value_list
,list_value
,parameter_definition
,parameter_value
,metadata
,entity_metadata
,parameter_value_metadata
. If none given, then the entire DB is fetched.
- query(*args, **kwargs)[source]
Returns a
Query
object to execute against the mapped DB.To perform custom
SELECT
statements, call this method with one or more of the documented subquery properties ofDatabaseMappingQueryMixin
returningAlias
objetcs. For example, to select the entity class withid
equal to 1:from spinedb_api import DatabaseMapping url = 'sqlite:///spine.db' ... db_map = DatabaseMapping(url) db_map.query(db_map.entity_class_sq).filter_by(id=1).one_or_none()
To perform more complex queries, just use the
Query
interface (which is a close clone of SQL Alchemy’sQuery
). For example, to select all entity class names and the names of their entities concatenated in a comma-separated string:from sqlalchemy import func db_map.query( db_map.entity_class_sq.c.name, func.group_concat(db_map.entity_sq.c.name) ).filter( db_map.entity_sq.c.class_id == db_map.entity_class_sq.c.id ).group_by(db_map.entity_class_sq.c.name).all()
- Returns:
The resulting query.
- Return type:
Query
- commit_session(comment, apply_compatibility_transforms=True)[source]
Commits the changes from the in-memory mapping to the database.
- has_external_commits()[source]
Tests whether the database has had commits from other sources than this mapping.
- Returns:
True if database has external commits, False otherwise
- Return type:
- close()[source]
Closes this DB mapping. This is only needed if you’re keeping a long-lived session. For instance:
class MyDBMappingWrapper: def __init__(self, url): self._db_map = DatabaseMapping(url) # More methods that do stuff with self._db_map def __del__(self): self._db_map.close()
Otherwise, the usage as context manager is recommended:
with DatabaseMapping(url) as db_map: # Do stuff with db_map ... # db_map.close() is automatically called when leaving this block
- get_alternative_item(fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns an alternative item matching the arguments, or None if none found.
- get_scenario_item(fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns a scenario item matching the arguments, or None if none found.
- get_scenario_alternative_item(fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns a scenario_alternative item matching the arguments, or None if none found.
- Parameters:
- Returns:
PublicItem
or None
- get_entity_class_item(fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns an entity_class item matching the arguments, or None if none found.
- get_superclass_subclass_item(fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns a superclass_subclass item matching the arguments, or None if none found.
- get_entity_item(fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns an entity item matching the arguments, or None if none found.
- Parameters:
fetch (bool, optional) – Whether to fetch the DB in case the item is not found in memory.
skip_removed (bool, optional) – Whether to ignore removed items.
name (str) – The entity name.
entity_class_name (str) – The entity class name.
entity_byname (tuple) – A tuple with the entity name as single element if the entity is zero-dimensional,or the element names if it is multi-dimensional.
- Returns:
PublicItem
or None
- get_entity_group_item(fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns an entity_group item matching the arguments, or None if none found.
- Parameters:
- Returns:
PublicItem
or None
- get_entity_alternative_item(fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns an entity_alternative item matching the arguments, or None if none found.
- Parameters:
fetch (bool, optional) – Whether to fetch the DB in case the item is not found in memory.
skip_removed (bool, optional) – Whether to ignore removed items.
entity_byname (tuple) – A tuple with the entity name as single element if the entity is zero-dimensional, or the element names if the entity is multi-dimensional.
entity_class_name (str) – The entity class name.
alternative_name (str) – The alternative name.
- Returns:
PublicItem
or None
- get_parameter_value_list_item(fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns a parameter_value_list item matching the arguments, or None if none found.
- get_list_value_item(fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns a list_value item matching the arguments, or None if none found.
- Parameters:
- Returns:
PublicItem
or None
- get_parameter_definition_item(fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns a parameter_definition item matching the arguments, or None if none found.
- get_parameter_value_item(fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns a parameter_value item matching the arguments, or None if none found.
- Parameters:
fetch (bool, optional) – Whether to fetch the DB in case the item is not found in memory.
skip_removed (bool, optional) – Whether to ignore removed items.
parameter_definition_name (str) – The parameter name.
entity_byname (tuple) – A tuple with the entity name as single element if the entity is zero-dimensional, or the element names if the entity is multi-dimensional.
entity_class_name (str) – The entity class name.
alternative_name (str, optional) – The alternative name - defaults to ‘Base’.
- Returns:
PublicItem
or None
- get_metadata_item(fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns a metadata item matching the arguments, or None if none found.
- get_entity_metadata_item(fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns an entity_metadata item matching the arguments, or None if none found.
- Parameters:
fetch (bool, optional) – Whether to fetch the DB in case the item is not found in memory.
skip_removed (bool, optional) – Whether to ignore removed items.
metadata_value (str) – The metadata entry value.
entity_byname (tuple) – A tuple with the entity name as single element if the entity is zero-dimensional, or the element names if the entity is multi-dimensional.
entity_class_name (str) – The entity class name.
metadata_name (str) – The metadata entry name.
- Returns:
PublicItem
or None
- get_parameter_value_metadata_item(fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns a parameter_value_metadata item matching the arguments, or None if none found.
- Parameters:
fetch (bool, optional) – Whether to fetch the DB in case the item is not found in memory.
skip_removed (bool, optional) – Whether to ignore removed items.
metadata_value (str) – The metadata entry value.
metadata_name (str) – The metadata entry name.
alternative_name (str) – The alternative name.
entity_byname (tuple) – A tuple with the entity name as single element if the entity is zero-dimensional, or the element names if the entity is multi-dimensional.
entity_class_name (str) – The entity class name.
parameter_definition_name (str) – The parameter name.
- Returns:
PublicItem
or None
- get_alternative_items(fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns all alternative items.
- get_scenario_items(fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns all scenario items.
- get_scenario_alternative_items(fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns all scenario_alternative items.
- Parameters:
- Returns:
The items.
- Return type:
list(
PublicItem
)
- get_entity_class_items(fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns all entity_class items.
- get_superclass_subclass_items(fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns all superclass_subclass items.
- get_entity_items(fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns all entity items.
- Parameters:
fetch (bool, optional) – Whether to fetch the DB before returning the items.
skip_removed (bool, optional) – Whether to ignore removed items.
name (str) – The entity name.
entity_class_name (str) – The entity class name.
entity_byname (tuple) – A tuple with the entity name as single element if the entity is zero-dimensional,or the element names if it is multi-dimensional.
- Returns:
The items.
- Return type:
list(
PublicItem
)
- get_entity_group_items(fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns all entity_group items.
- Parameters:
- Returns:
The items.
- Return type:
list(
PublicItem
)
- get_entity_alternative_items(fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns all entity_alternative items.
- Parameters:
fetch (bool, optional) – Whether to fetch the DB before returning the items.
skip_removed (bool, optional) – Whether to ignore removed items.
entity_byname (tuple) – A tuple with the entity name as single element if the entity is zero-dimensional, or the element names if the entity is multi-dimensional.
entity_class_name (str) – The entity class name.
alternative_name (str) – The alternative name.
- Returns:
The items.
- Return type:
list(
PublicItem
)
- get_parameter_value_list_items(fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns all parameter_value_list items.
- get_list_value_items(fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns all list_value items.
- Parameters:
- Returns:
The items.
- Return type:
list(
PublicItem
)
- get_parameter_definition_items(fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns all parameter_definition items.
- get_parameter_value_items(fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns all parameter_value items.
- Parameters:
fetch (bool, optional) – Whether to fetch the DB before returning the items.
skip_removed (bool, optional) – Whether to ignore removed items.
parameter_definition_name (str) – The parameter name.
entity_byname (tuple) – A tuple with the entity name as single element if the entity is zero-dimensional, or the element names if the entity is multi-dimensional.
entity_class_name (str) – The entity class name.
alternative_name (str, optional) – The alternative name - defaults to ‘Base’.
- Returns:
The items.
- Return type:
list(
PublicItem
)
- get_metadata_items(fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns all metadata items.
- get_entity_metadata_items(fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns all entity_metadata items.
- Parameters:
fetch (bool, optional) – Whether to fetch the DB before returning the items.
skip_removed (bool, optional) – Whether to ignore removed items.
metadata_value (str) – The metadata entry value.
entity_byname (tuple) – A tuple with the entity name as single element if the entity is zero-dimensional, or the element names if the entity is multi-dimensional.
entity_class_name (str) – The entity class name.
metadata_name (str) – The metadata entry name.
- Returns:
The items.
- Return type:
list(
PublicItem
)
- get_parameter_value_metadata_items(fetch=True, skip_removed=True, **kwargs)[source]
Finds and returns all parameter_value_metadata items.
- Parameters:
fetch (bool, optional) – Whether to fetch the DB before returning the items.
skip_removed (bool, optional) – Whether to ignore removed items.
metadata_value (str) – The metadata entry value.
metadata_name (str) – The metadata entry name.
alternative_name (str) – The alternative name.
entity_byname (tuple) – A tuple with the entity name as single element if the entity is zero-dimensional, or the element names if the entity is multi-dimensional.
entity_class_name (str) – The entity class name.
parameter_definition_name (str) – The parameter name.
- Returns:
The items.
- Return type:
list(
PublicItem
)
- add_alternative_item(check=True, **kwargs)[source]
Adds an alternative item to the in-memory mapping.
- add_scenario_alternative_item(check=True, **kwargs)[source]
Adds a scenario_alternative item to the in-memory mapping.
- add_entity_class_item(check=True, **kwargs)[source]
Adds an entity_class item to the in-memory mapping.
- Parameters:
name (str) – The class name.
dimension_name_list (tuple, optional) – The dimension names for a multi-dimensional class.
description (str, optional) – The class description.
display_icon (int, optional) – An integer representing an icon within your application.
display_order (int, optional) – Not in use at the moment.
hidden (int, optional) – Not in use at the moment.
active_by_default (bool, optional) – Default activity for the entity alternatives of the class.
- Returns:
The added item and any errors.
- Return type:
tuple(
PublicItem
or None, str)
- add_superclass_subclass_item(check=True, **kwargs)[source]
Adds a superclass_subclass item to the in-memory mapping.
- add_entity_item(check=True, **kwargs)[source]
Adds an entity item to the in-memory mapping.
- Parameters:
entity_class_name (str) – The entity class name.
name (str) – The entity name.
element_name_list (tuple) – The element names if the entity is multi-dimensional.
entity_byname (tuple) – A tuple with the entity name as single element if the entity is zero-dimensional,or the element names if it is multi-dimensional.
description (str, optional) – The entity description.
- Returns:
The added item and any errors.
- Return type:
tuple(
PublicItem
or None, str)
- add_entity_group_item(check=True, **kwargs)[source]
Adds an entity_group item to the in-memory mapping.
- add_entity_alternative_item(check=True, **kwargs)[source]
Adds an entity_alternative item to the in-memory mapping.
- Parameters:
entity_class_name (str) – The entity class name.
entity_byname (tuple) – A tuple with the entity name as single element if the entity is zero-dimensional, or the element names if the entity is multi-dimensional.
alternative_name (str) – The alternative name.
active (bool, optional) – Whether the entity is active in the alternative - defaults to True.
- Returns:
The added item and any errors.
- Return type:
tuple(
PublicItem
or None, str)
- add_parameter_value_list_item(check=True, **kwargs)[source]
Adds a parameter_value_list item to the in-memory mapping.
- Parameters:
name (str) – The parameter value list name.
- Returns:
The added item and any errors.
- Return type:
tuple(
PublicItem
or None, str)
- add_parameter_definition_item(check=True, **kwargs)[source]
Adds a parameter_definition item to the in-memory mapping.
- Parameters:
entity_class_name (str) – The entity class name.
name (str) – The parameter name.
default_value (bytes, optional) – The default value.
default_type (str, optional) – The default value type.
parameter_value_list_name (str, optional) – The parameter value list name if any.
description (str, optional) – The parameter description.
- Returns:
The added item and any errors.
- Return type:
tuple(
PublicItem
or None, str)
- add_parameter_value_item(check=True, **kwargs)[source]
Adds a parameter_value item to the in-memory mapping.
- Parameters:
entity_class_name (str) – The entity class name.
parameter_definition_name (str) – The parameter name.
entity_byname (tuple) – A tuple with the entity name as single element if the entity is zero-dimensional, or the element names if the entity is multi-dimensional.
value (bytes) – The value.
type (str, optional) – The value type.
alternative_name (str, optional) – The alternative name - defaults to ‘Base’.
- Returns:
The added item and any errors.
- Return type:
tuple(
PublicItem
or None, str)
- add_entity_metadata_item(check=True, **kwargs)[source]
Adds an entity_metadata item to the in-memory mapping.
- Parameters:
entity_class_name (str) – The entity class name.
entity_byname (tuple) – A tuple with the entity name as single element if the entity is zero-dimensional, or the element names if the entity is multi-dimensional.
metadata_name (str) – The metadata entry name.
metadata_value (str) – The metadata entry value.
- Returns:
The added item and any errors.
- Return type:
tuple(
PublicItem
or None, str)
- add_parameter_value_metadata_item(check=True, **kwargs)[source]
Adds a parameter_value_metadata item to the in-memory mapping.
- Parameters:
entity_class_name (str) – The entity class name.
parameter_definition_name (str) – The parameter name.
entity_byname (tuple) – A tuple with the entity name as single element if the entity is zero-dimensional, or the element names if the entity is multi-dimensional.
alternative_name (str) – The alternative name.
metadata_name (str) – The metadata entry name.
metadata_value (str) – The metadata entry value.
- Returns:
The added item and any errors.
- Return type:
tuple(
PublicItem
or None, str)
- update_alternative_item(check=True, **kwargs)[source]
Updates an alternative item in the in-memory mapping.
- update_scenario_item(check=True, **kwargs)[source]
Updates a scenario item in the in-memory mapping.
- update_scenario_alternative_item(check=True, **kwargs)[source]
Updates a scenario_alternative item in the in-memory mapping.
- update_entity_class_item(check=True, **kwargs)[source]
Updates an entity_class item in the in-memory mapping.
- Parameters:
id (int) – The id of the item to update.
name (str) – The class name.
dimension_name_list (tuple, optional) – The dimension names for a multi-dimensional class.
description (str, optional) – The class description.
display_icon (int, optional) – An integer representing an icon within your application.
display_order (int, optional) – Not in use at the moment.
hidden (int, optional) – Not in use at the moment.
active_by_default (bool, optional) – Default activity for the entity alternatives of the class.
- Returns:
The updated item and any errors.
- Return type:
tuple(
PublicItem
or None, str)
- update_superclass_subclass_item(check=True, **kwargs)[source]
Updates a superclass_subclass item in the in-memory mapping.
- update_entity_item(check=True, **kwargs)[source]
Updates an entity item in the in-memory mapping.
- Parameters:
id (int) – The id of the item to update.
entity_class_name (str) – The entity class name.
name (str) – The entity name.
element_name_list (tuple) – The element names if the entity is multi-dimensional.
entity_byname (tuple) – A tuple with the entity name as single element if the entity is zero-dimensional,or the element names if it is multi-dimensional.
description (str, optional) – The entity description.
- Returns:
The updated item and any errors.
- Return type:
tuple(
PublicItem
or None, str)
- update_entity_group_item(check=True, **kwargs)[source]
Updates an entity_group item in the in-memory mapping.
- update_entity_alternative_item(check=True, **kwargs)[source]
Updates an entity_alternative item in the in-memory mapping.
- Parameters:
id (int) – The id of the item to update.
entity_class_name (str) – The entity class name.
entity_byname (tuple) – A tuple with the entity name as single element if the entity is zero-dimensional, or the element names if the entity is multi-dimensional.
alternative_name (str) – The alternative name.
active (bool, optional) – Whether the entity is active in the alternative - defaults to True.
- Returns:
The updated item and any errors.
- Return type:
tuple(
PublicItem
or None, str)
- update_parameter_value_list_item(check=True, **kwargs)[source]
Updates a parameter_value_list item in the in-memory mapping.
- update_list_value_item(check=True, **kwargs)[source]
Updates a list_value item in the in-memory mapping.
- Parameters:
- Returns:
The updated item and any errors.
- Return type:
tuple(
PublicItem
or None, str)
- update_parameter_definition_item(check=True, **kwargs)[source]
Updates a parameter_definition item in the in-memory mapping.
- Parameters:
id (int) – The id of the item to update.
entity_class_name (str) – The entity class name.
name (str) – The parameter name.
default_value (bytes, optional) – The default value.
default_type (str, optional) – The default value type.
parameter_value_list_name (str, optional) – The parameter value list name if any.
description (str, optional) – The parameter description.
- Returns:
The updated item and any errors.
- Return type:
tuple(
PublicItem
or None, str)
- update_parameter_value_item(check=True, **kwargs)[source]
Updates a parameter_value item in the in-memory mapping.
- Parameters:
id (int) – The id of the item to update.
entity_class_name (str) – The entity class name.
parameter_definition_name (str) – The parameter name.
entity_byname (tuple) – A tuple with the entity name as single element if the entity is zero-dimensional, or the element names if the entity is multi-dimensional.
value (bytes) – The value.
type (str, optional) – The value type.
alternative_name (str, optional) – The alternative name - defaults to ‘Base’.
- Returns:
The updated item and any errors.
- Return type:
tuple(
PublicItem
or None, str)
- update_metadata_item(check=True, **kwargs)[source]
Updates a metadata item in the in-memory mapping.
- update_entity_metadata_item(check=True, **kwargs)[source]
Updates an entity_metadata item in the in-memory mapping.
- Parameters:
id (int) – The id of the item to update.
entity_class_name (str) – The entity class name.
entity_byname (tuple) – A tuple with the entity name as single element if the entity is zero-dimensional, or the element names if the entity is multi-dimensional.
metadata_name (str) – The metadata entry name.
metadata_value (str) – The metadata entry value.
- Returns:
The updated item and any errors.
- Return type:
tuple(
PublicItem
or None, str)
- update_parameter_value_metadata_item(check=True, **kwargs)[source]
Updates a parameter_value_metadata item in the in-memory mapping.
- Parameters:
id (int) – The id of the item to update.
entity_class_name (str) – The entity class name.
parameter_definition_name (str) – The parameter name.
entity_byname (tuple) – A tuple with the entity name as single element if the entity is zero-dimensional, or the element names if the entity is multi-dimensional.
alternative_name (str) – The alternative name.
metadata_name (str) – The metadata entry name.
metadata_value (str) – The metadata entry value.
- Returns:
The updated item and any errors.
- Return type:
tuple(
PublicItem
or None, str)
- add_update_alternative_item(check=True, **kwargs)[source]
Adds an alternative item to the in-memory mapping if it doesn’t exist; otherwise updates the current one.
- add_update_scenario_item(check=True, **kwargs)[source]
Adds a scenario item to the in-memory mapping if it doesn’t exist; otherwise updates the current one.
- add_update_scenario_alternative_item(check=True, **kwargs)[source]
Adds a scenario_alternative item to the in-memory mapping if it doesn’t exist; otherwise updates the current one.
- add_update_entity_class_item(check=True, **kwargs)[source]
Adds an entity_class item to the in-memory mapping if it doesn’t exist; otherwise updates the current one.
- Parameters:
name (str) – The class name.
dimension_name_list (tuple, optional) – The dimension names for a multi-dimensional class.
description (str, optional) – The class description.
display_icon (int, optional) – An integer representing an icon within your application.
display_order (int, optional) – Not in use at the moment.
hidden (int, optional) – Not in use at the moment.
active_by_default (bool, optional) – Default activity for the entity alternatives of the class.
- Returns:
- The added item if any,
the updated item if any, and any errors.
- Return type:
tuple(
PublicItem
or None,PublicItem
or None, str)
- add_update_superclass_subclass_item(check=True, **kwargs)[source]
Adds a superclass_subclass item to the in-memory mapping if it doesn’t exist; otherwise updates the current one.
- add_update_entity_item(check=True, **kwargs)[source]
Adds an entity item to the in-memory mapping if it doesn’t exist; otherwise updates the current one.
- Parameters:
entity_class_name (str) – The entity class name.
name (str) – The entity name.
element_name_list (tuple) – The element names if the entity is multi-dimensional.
entity_byname (tuple) – A tuple with the entity name as single element if the entity is zero-dimensional,or the element names if it is multi-dimensional.
description (str, optional) – The entity description.
- Returns:
- The added item if any,
the updated item if any, and any errors.
- Return type:
tuple(
PublicItem
or None,PublicItem
or None, str)
- add_update_entity_group_item(check=True, **kwargs)[source]
Adds an entity_group item to the in-memory mapping if it doesn’t exist; otherwise updates the current one.
- add_update_entity_alternative_item(check=True, **kwargs)[source]
Adds an entity_alternative item to the in-memory mapping if it doesn’t exist; otherwise updates the current one.
- Parameters:
entity_class_name (str) – The entity class name.
entity_byname (tuple) – A tuple with the entity name as single element if the entity is zero-dimensional, or the element names if the entity is multi-dimensional.
alternative_name (str) – The alternative name.
active (bool, optional) – Whether the entity is active in the alternative - defaults to True.
- Returns:
- The added item if any,
the updated item if any, and any errors.
- Return type:
tuple(
PublicItem
or None,PublicItem
or None, str)
- add_update_parameter_value_list_item(check=True, **kwargs)[source]
Adds a parameter_value_list item to the in-memory mapping if it doesn’t exist; otherwise updates the current one.
- Parameters:
name (str) – The parameter value list name.
- Returns:
- The added item if any,
the updated item if any, and any errors.
- Return type:
tuple(
PublicItem
or None,PublicItem
or None, str)
- add_update_list_value_item(check=True, **kwargs)[source]
Adds a list_value item to the in-memory mapping if it doesn’t exist; otherwise updates the current one.
- Parameters:
- Returns:
- The added item if any,
the updated item if any, and any errors.
- Return type:
tuple(
PublicItem
or None,PublicItem
or None, str)
- add_update_parameter_definition_item(check=True, **kwargs)[source]
Adds a parameter_definition item to the in-memory mapping if it doesn’t exist; otherwise updates the current one.
- Parameters:
entity_class_name (str) – The entity class name.
name (str) – The parameter name.
default_value (bytes, optional) – The default value.
default_type (str, optional) – The default value type.
parameter_value_list_name (str, optional) – The parameter value list name if any.
description (str, optional) – The parameter description.
- Returns:
- The added item if any,
the updated item if any, and any errors.
- Return type:
tuple(
PublicItem
or None,PublicItem
or None, str)
- add_update_parameter_value_item(check=True, **kwargs)[source]
Adds a parameter_value item to the in-memory mapping if it doesn’t exist; otherwise updates the current one.
- Parameters:
entity_class_name (str) – The entity class name.
parameter_definition_name (str) – The parameter name.
entity_byname (tuple) – A tuple with the entity name as single element if the entity is zero-dimensional, or the element names if the entity is multi-dimensional.
value (bytes) – The value.
type (str, optional) – The value type.
alternative_name (str, optional) – The alternative name - defaults to ‘Base’.
- Returns:
- The added item if any,
the updated item if any, and any errors.
- Return type:
tuple(
PublicItem
or None,PublicItem
or None, str)
- add_update_metadata_item(check=True, **kwargs)[source]
Adds a metadata item to the in-memory mapping if it doesn’t exist; otherwise updates the current one.
- add_update_entity_metadata_item(check=True, **kwargs)[source]
Adds an entity_metadata item to the in-memory mapping if it doesn’t exist; otherwise updates the current one.
- Parameters:
entity_class_name (str) – The entity class name.
entity_byname (tuple) – A tuple with the entity name as single element if the entity is zero-dimensional, or the element names if the entity is multi-dimensional.
metadata_name (str) – The metadata entry name.
metadata_value (str) – The metadata entry value.
- Returns:
- The added item if any,
the updated item if any, and any errors.
- Return type:
tuple(
PublicItem
or None,PublicItem
or None, str)
- add_update_parameter_value_metadata_item(check=True, **kwargs)[source]
Adds a parameter_value_metadata item to the in-memory mapping if it doesn’t exist; otherwise updates the current one.
- Parameters:
entity_class_name (str) – The entity class name.
parameter_definition_name (str) – The parameter name.
entity_byname (tuple) – A tuple with the entity name as single element if the entity is zero-dimensional, or the element names if the entity is multi-dimensional.
alternative_name (str) – The alternative name.
metadata_name (str) – The metadata entry name.
metadata_value (str) – The metadata entry value.
- Returns:
- The added item if any,
the updated item if any, and any errors.
- Return type:
tuple(
PublicItem
or None,PublicItem
or None, str)
- remove_alternative_item(id)[source]
Removes a alternative item from the in-memory mapping.
- Parameters:
id (int) – the id of the item to remove.
- Returns:
The removed item if any.
- Return type:
tuple(
PublicItem
or None, str)
- remove_scenario_item(id)[source]
Removes a scenario item from the in-memory mapping.
- Parameters:
id (int) – the id of the item to remove.
- Returns:
The removed item if any.
- Return type:
tuple(
PublicItem
or None, str)
- remove_scenario_alternative_item(id)[source]
Removes a scenario_alternative item from the in-memory mapping.
- Parameters:
id (int) – the id of the item to remove.
- Returns:
The removed item if any.
- Return type:
tuple(
PublicItem
or None, str)
- remove_entity_class_item(id)[source]
Removes a entity_class item from the in-memory mapping.
- Parameters:
id (int) – the id of the item to remove.
- Returns:
The removed item if any.
- Return type:
tuple(
PublicItem
or None, str)
- remove_superclass_subclass_item(id)[source]
Removes a superclass_subclass item from the in-memory mapping.
- Parameters:
id (int) – the id of the item to remove.
- Returns:
The removed item if any.
- Return type:
tuple(
PublicItem
or None, str)
- remove_entity_item(id)[source]
Removes a entity item from the in-memory mapping.
- Parameters:
id (int) – the id of the item to remove.
- Returns:
The removed item if any.
- Return type:
tuple(
PublicItem
or None, str)
- remove_entity_group_item(id)[source]
Removes a entity_group item from the in-memory mapping.
- Parameters:
id (int) – the id of the item to remove.
- Returns:
The removed item if any.
- Return type:
tuple(
PublicItem
or None, str)
- remove_entity_alternative_item(id)[source]
Removes a entity_alternative item from the in-memory mapping.
- Parameters:
id (int) – the id of the item to remove.
- Returns:
The removed item if any.
- Return type:
tuple(
PublicItem
or None, str)
- remove_parameter_value_list_item(id)[source]
Removes a parameter_value_list item from the in-memory mapping.
- Parameters:
id (int) – the id of the item to remove.
- Returns:
The removed item if any.
- Return type:
tuple(
PublicItem
or None, str)
- remove_list_value_item(id)[source]
Removes a list_value item from the in-memory mapping.
- Parameters:
id (int) – the id of the item to remove.
- Returns:
The removed item if any.
- Return type:
tuple(
PublicItem
or None, str)
- remove_parameter_definition_item(id)[source]
Removes a parameter_definition item from the in-memory mapping.
- Parameters:
id (int) – the id of the item to remove.
- Returns:
The removed item if any.
- Return type:
tuple(
PublicItem
or None, str)
- remove_parameter_value_item(id)[source]
Removes a parameter_value item from the in-memory mapping.
- Parameters:
id (int) – the id of the item to remove.
- Returns:
The removed item if any.
- Return type:
tuple(
PublicItem
or None, str)
- remove_metadata_item(id)[source]
Removes a metadata item from the in-memory mapping.
- Parameters:
id (int) – the id of the item to remove.
- Returns:
The removed item if any.
- Return type:
tuple(
PublicItem
or None, str)
- remove_entity_metadata_item(id)[source]
Removes a entity_metadata item from the in-memory mapping.
- Parameters:
id (int) – the id of the item to remove.
- Returns:
The removed item if any.
- Return type:
tuple(
PublicItem
or None, str)
- remove_parameter_value_metadata_item(id)[source]
Removes a parameter_value_metadata item from the in-memory mapping.
- Parameters:
id (int) – the id of the item to remove.
- Returns:
The removed item if any.
- Return type:
tuple(
PublicItem
or None, str)
- restore_alternative_item(id)[source]
Restores a previously removed alternative item into the in-memory mapping.
- Parameters:
id (int) – the id of the item to restore.
- Returns:
The restored item if any.
- Return type:
tuple(
PublicItem
or None, str)
- restore_scenario_item(id)[source]
Restores a previously removed scenario item into the in-memory mapping.
- Parameters:
id (int) – the id of the item to restore.
- Returns:
The restored item if any.
- Return type:
tuple(
PublicItem
or None, str)
- restore_scenario_alternative_item(id)[source]
Restores a previously removed scenario_alternative item into the in-memory mapping.
- Parameters:
id (int) – the id of the item to restore.
- Returns:
The restored item if any.
- Return type:
tuple(
PublicItem
or None, str)
- restore_entity_class_item(id)[source]
Restores a previously removed entity_class item into the in-memory mapping.
- Parameters:
id (int) – the id of the item to restore.
- Returns:
The restored item if any.
- Return type:
tuple(
PublicItem
or None, str)
- restore_superclass_subclass_item(id)[source]
Restores a previously removed superclass_subclass item into the in-memory mapping.
- Parameters:
id (int) – the id of the item to restore.
- Returns:
The restored item if any.
- Return type:
tuple(
PublicItem
or None, str)
- restore_entity_item(id)[source]
Restores a previously removed entity item into the in-memory mapping.
- Parameters:
id (int) – the id of the item to restore.
- Returns:
The restored item if any.
- Return type:
tuple(
PublicItem
or None, str)
- restore_entity_group_item(id)[source]
Restores a previously removed entity_group item into the in-memory mapping.
- Parameters:
id (int) – the id of the item to restore.
- Returns:
The restored item if any.
- Return type:
tuple(
PublicItem
or None, str)
- restore_entity_alternative_item(id)[source]
Restores a previously removed entity_alternative item into the in-memory mapping.
- Parameters:
id (int) – the id of the item to restore.
- Returns:
The restored item if any.
- Return type:
tuple(
PublicItem
or None, str)
- restore_parameter_value_list_item(id)[source]
Restores a previously removed parameter_value_list item into the in-memory mapping.
- Parameters:
id (int) – the id of the item to restore.
- Returns:
The restored item if any.
- Return type:
tuple(
PublicItem
or None, str)
- restore_list_value_item(id)[source]
Restores a previously removed list_value item into the in-memory mapping.
- Parameters:
id (int) – the id of the item to restore.
- Returns:
The restored item if any.
- Return type:
tuple(
PublicItem
or None, str)
- restore_parameter_definition_item(id)[source]
Restores a previously removed parameter_definition item into the in-memory mapping.
- Parameters:
id (int) – the id of the item to restore.
- Returns:
The restored item if any.
- Return type:
tuple(
PublicItem
or None, str)
- restore_parameter_value_item(id)[source]
Restores a previously removed parameter_value item into the in-memory mapping.
- Parameters:
id (int) – the id of the item to restore.
- Returns:
The restored item if any.
- Return type:
tuple(
PublicItem
or None, str)
- restore_metadata_item(id)[source]
Restores a previously removed metadata item into the in-memory mapping.
- Parameters:
id (int) – the id of the item to restore.
- Returns:
The restored item if any.
- Return type:
tuple(
PublicItem
or None, str)