caosdb.apiutils module

API-Utils:

Some simplified functions for generation of records etc.

class caosdb.apiutils.CaosDBPythonEntity

Bases: object

add_parent(parent_id=None, parent_name=None)
add_property(name, value, is_reference=False, overwrite=False, datatype=None)

overwrite: Use this if you definitely only want one property with that name (set to True).

attribute_as_list(name)

This is a workaround for the problem that lists containing only one element are indistinguishable from simple types in this representation.

get_parent_names()
resolve_references(deep=False, visited={})
set_id(idx)
set_property(name, value, is_reference=False, overwrite=False, datatype=None)

overwrite: Use this if you definitely only want one property with that name (set to True).

class caosdb.apiutils.CaosDBPythonFile

Bases: caosdb.apiutils.CaosDBPythonEntity

get_File(target=None)
class caosdb.apiutils.CaosDBPythonProperty

Bases: caosdb.apiutils.CaosDBPythonEntity

class caosdb.apiutils.CaosDBPythonRecord

Bases: caosdb.apiutils.CaosDBPythonEntity

class caosdb.apiutils.CaosDBPythonRecordType

Bases: caosdb.apiutils.CaosDBPythonEntity

caosdb.apiutils.apply_to_ids(entities, func)

Apply a function to all ids.

All ids means the ids of the entities themselves but also to all parents, properties and referenced entities.

Parameters
  • entities (list of Entity) –

  • func (function with one parameter.) –

caosdb.apiutils.compare_entities(old_entity: caosdb.common.models.Entity, new_entity: caosdb.common.models.Entity)

Compare two entites.

Return a tuple of dictionaries, the first index belongs to additional information for old entity, the second index belongs to additional information for new entity.

Additional information means in detail: - Additional parents (a list under key “parents”) - Information about properties:

  • Each property lists either an additional property or a property with a changed: - … datatype - … importance or - … value (not implemented yet) In case of changed information the value listed under the respective key shows the value that is stored in the respective entity.

caosdb.apiutils.convert_to_entity(python_object, **kwargs)
caosdb.apiutils.convert_to_python_object(entity)
caosdb.apiutils.create_id_query(ids)
caosdb.apiutils.describe_diff(olddiff, newdiff, name=None, as_update=True)
caosdb.apiutils.getBranchIn(folder)

returns the current branch of the git repository in the given folder.

The command “git branch” is called in the given folder and the output is returned

caosdb.apiutils.getCommitIn(folder)

returns the commit hash in of the git repository in the given folder.

The command “git log -1 –format=%h” is called in the given folder and the output is returned

caosdb.apiutils.getDiffIn(folder, save_dir=None)

returns the name of a file where the out put of “git diff” in the given folder is stored.

caosdb.apiutils.getOriginUrlIn(folder)

return the Fetch URL of the git repository in the given folder.

caosdb.apiutils.get_type_of_entity_with(id_)
caosdb.apiutils.id_query(ids)
caosdb.apiutils.new_record(record_type, name=None, description=None, tempid=None, insert=False, **kwargs)

Function to simplify the creation of Records.

record_type: The name of the RecordType to use for this record.

(ids should also work.)

name: Name of the new Record. kwargs: Key-value-pairs for the properties of this Record.

Returns: The newly created Record.

Of course this functions requires an open database connection!

caosdb.apiutils.resolve_reference(prop: caosdb.common.models.Property)

resolves the value of a reference property

The integer value is replaced with the entity object. If the property is not a reference, then the function returns without change.

caosdb.apiutils.retrieve_entities_with_ids(entities)
caosdb.apiutils.retrieve_entity_with_id(eid)