ayon_api.entity_hub module¶
- class Attributes(attrib_keys, values=<UNKNOWN_VALUE>)[source]¶
Bases:
object
Object representing attribs of entity.
- Todos:
This could be enhanced to know attribute schema and validate values based on the schema.
- Parameters:
attrib_keys (
Iterable[str]
) – Keys that are available in attribs of the entity.values (
Union[None, Dict[str, Any]]
) – Values of attributes.
- property changes¶
Attribute value changes.
- Returns:
Key mapping with new values.
- Return type:
Dict[str, Any]
- get(key, default=None)[source]¶
Get value of attribute.
- Parameters:
key (
str
) – Attribute name.default (
Any
) – Default value to return when attribute was not found.
- get_attribute(key)[source]¶
Access to attribute object.
- Parameters:
key (
str
) – Name of attribute.- Returns:
Object of attribute value.
- Return type:
- Raises:
KeyError – When attribute is not available.
- class BaseEntity(entity_id=None, parent_id=<UNKNOWN_VALUE>, name=<UNKNOWN_VALUE>, attribs=<UNKNOWN_VALUE>, data=<UNKNOWN_VALUE>, thumbnail_id=<UNKNOWN_VALUE>, active=<UNKNOWN_VALUE>, entity_hub=None, created=None)[source]¶
Bases:
ABC
Object representation of entity from server which is capturing changes.
All data on created object are expected as “current data” on server entity unless the entity has set ‘created’ to ‘True’. So if new data should be stored to server entity then fill entity with server data first and then change them.
Calling ‘lock’ method will mark entity as “saved” and all changes made on entity are set as “current data” on server.
- Parameters:
entity_id (
Union[str, None]
) – Id of the entity. New id is created if not passed.parent_id (
Union[str, None]
) – Id of parent entity.name (
str
) – Name of entity.attribs (
Dict[str, Any]
) – Attribute values.data (
Dict[str, Any]
) – Entity data (custom data).thumbnail_id (
Union[str, None]
) – Id of entity’s thumbnail.active (
bool
) – Is entity active.entity_hub (
EntityHub
) – Object of entity hub which created object of the entity.created (
Optional[bool]
) – Entity is new. When ‘None’ is passed the value is defined based on value of ‘entity_id’.
- add_child(child)[source]¶
Add child entity.
- Parameters:
child (
BaseEntity
) – Child object to add.- Raises:
TypeError – When child object has invalid type to be children.
- property attribs¶
Entity attributes based on server configuration.
- Returns:
- Attributes object handling changes and values of
attributes on entity.
- Return type:
- abstract property changes¶
Receive entity changes.
- Returns:
- All values that have changed on
entity. New entity must return None.
- Return type:
Union[Dict[str, Any], None]
- property children¶
Access to children objects.
- Returns:
Children iterator.
- Return type:
Union[List[BaseEntity], Type[UNKNOWN_VALUE]]
- property children_ids¶
Access to children objects.
- Todos:
- Children should be maybe handled by EntityHub instead of entities
themselves. That would simplify ‘set_entity_parent’, ‘unset_entity_parent’ and other logic related to changing hierarchy.
- Returns:
Children iterator.
- Return type:
Union[List[str], Type[UNKNOWN_VALUE]]
- property created¶
Entity is new.
- Returns:
Entity is newly created.
- Return type:
bool
- property data¶
Entity custom data that are not stored by any deterministic model.
- Be aware that ‘data’ can’t be queried using GraphQl and cannot be
updated partially.
- Returns:
Custom data on entity.
- Return type:
- abstract property entity_type¶
Entity type coresponding to server.
- Returns:
Entity type.
- Return type:
EntityType
- fill_children_ids(children_ids)[source]¶
Fill children ids on entity.
Warning
This is not an api call but is called from entity hub.
- abstract classmethod from_entity_data(entity_data, entity_hub)[source]¶
Create entity based on queried data from server.
- Parameters:
entity_data (
Dict[str, Any]
) – Entity data from server.entity_hub (
EntityHub
) – Hub which handle the entity.
- Returns:
Object of the class.
- Return type:
- get_children(allow_query=True)[source]¶
Access to children objects.
- Returns:
Children iterator.
- Return type:
Union[List[BaseEntity], Type[UNKNOWN_VALUE]]
- get_children_ids(allow_query=True)[source]¶
Access to children objects.
- Todos:
- Children should be maybe handled by EntityHub instead of entities
themselves. That would simplify ‘set_entity_parent’, ‘unset_entity_parent’ and other logic related to changing hierarchy.
- Returns:
Children iterator.
- Return type:
Union[List[str], Type[UNKNOWN_VALUE]]
- get_parent(allow_query=True)[source]¶
Parent entity.
- Returns:
Parent object.
- Return type:
Union[BaseEntity, None]
- get_parent_id()[source]¶
Parent entity id.
- Returns:
Id of parent entity or none if is not set.
- Return type:
Union[str, None]
- get_thumbnail_id()[source]¶
Thumbnail id of entity.
- Returns:
Id of parent entity or none if is not set.
- Return type:
Union[str, None]
- property has_cached_immutable_hierarchy¶
- property id¶
Access to entity id under which is entity available on server.
- Returns:
Entity id.
- Return type:
str
- property immutable_for_hierarchy¶
Entity is immutable for hierarchy changes.
Hierarchy changes can be considered as change of name or parents.
- Returns:
Entity is immutable for hierarchy changes.
- Return type:
bool
- property name¶
- property orig_parent_id¶
- property parent¶
Parent entity.
- Returns:
Parent object.
- Return type:
Union[BaseEntity, None]
- abstract property parent_entity_types¶
Entity type coresponding to server.
- Returns:
Possible entity types of parent.
- Return type:
Iterable[str]
- property parent_id¶
Parent entity id.
- Returns:
Id of parent entity or none if is not set.
- Return type:
Union[str, None]
- property project_name¶
Quick access to project from entity hub.
- Returns:
Name of project under which entity lives.
- Return type:
str
- remove_child(child)[source]¶
Remove child entity.
Is ignored if child is not in children.
- Parameters:
child (
Union[str, BaseEntity]
) – Child object or child id to remove.
- property removed¶
- reset_immutable_for_hierarchy_cache(bottom_to_top=True)[source]¶
Clear cache of immutable hierarchy property.
This is used when entity changed parent or a child was added.
- Parameters:
bottom_to_top (
bool
) – Reset cache from top hierarchy to bottom or from bottom hierarchy to top.
- set_parent(parent)[source]¶
Change parent object.
- Parameters:
parent (
BaseEntity
) – New parent for entity.- Raises:
TypeError – If validation of parent does not pass.
- set_parent_id(parent_id)[source]¶
Change parent by id.
- Parameters:
parent_id (
Union[str, None]
) – Id of new parent for entity.- Raises:
ValueError – If parent was not found by id.
TypeError – If validation of parent does not pass.
- set_thumbnail_id(thumbnail_id)[source]¶
Change thumbnail id.
- Parameters:
thumbnail_id (
Union[str, None]
) – Id of thumbnail for entity.
- property thumbnail_id¶
Thumbnail id of entity.
- Returns:
Id of parent entity or none if is not set.
- Return type:
Union[str, None]
- class EntityData(*args, **kwargs)[source]¶
Bases:
dict
Wrapper for ‘data’ key on entity.
Data on entity are arbitrary data that are not stored in any deterministic model. It is possible to store any data that can be parsed to json.
It is not possible to store ‘None’ to root key. In that case the key is not stored, and removed if existed on entity. To be able to store ‘None’ value use nested data structure:
{ "sceneInfo": { "description": None, "camera": "camera1" } }
- get_changes()[source]¶
Changes in entity data.
Removed keys have value set to ‘None’.
- Returns:
Key mapping with changed values.
- Return type:
dict[str, Any]
- class EntityHub(project_name, connection=None, allow_data_changes=None)[source]¶
Bases:
object
Helper to create, update or remove entities in project.
The hub is a guide to operation with folder entities and update of project. Project entity must already exist on server (can be only updated).
Object is caching entities queried from server. They won’t be required once they were queried, so it is recommended to create new hub or clear cache frequently.
- Todos:
- Listen to server events about entity changes to be able update already
queried entities.
- Parameters:
project_name (
str
) – Name of project where changes will happen.connection (
ServerAPI
) – Connection to server with logged user.allow_data_changes (
bool
) – This option gives ability to change ‘data’ key on entities. This is not recommended as ‘data’ may be use for secure information and would also slow down server queries. Content of ‘data’ key can’t be received only GraphQl.
- add_entity(entity)[source]¶
Add entity to hub cache.
- Parameters:
entity (
BaseEntity
) – Entity that should be added to hub’s cache.
- add_folder(folder)[source]¶
Create folder object and add it to entity hub.
- Parameters:
folder (
Dict[str, Any]
) – Folder entity data.- Returns:
Added folder entity.
- Return type:
- add_new_folder(*args, created=True, **kwargs)[source]¶
Create folder object and add it to entity hub.
- Parameters:
folder_type (
str
) – Type of folder. Folder type must be available in config of project folder types.entity_id (
Union[str, None]
) – Id of the entity. New id is created if not passed.parent_id (
Union[str, None]
) – Id of parent entity.name (
str
) – Name of entity.label (
Optional[str]
) – Folder label.path (
Optional[str]
) – Folder path. Path consist of all parent names with slash(‘/’) used as separator.attribs (
Dict[str, Any]
) – Attribute values.data (
Dict[str, Any]
) – Entity data (custom data).thumbnail_id (
Union[str, None]
) – Id of entity’s thumbnail.active (
bool
) – Is entity active.created (
Optional[bool]
) – Entity is new. When ‘None’ is passed the value is defined based on value of ‘entity_id’.
- Returns:
Added folder entity.
- Return type:
- add_new_task(*args, created=True, **kwargs)[source]¶
Create folder object and add it to entity hub.
- Parameters:
task_type (
str
) – Type of task. Task type must be available in config of project folder types.entity_id (
Union[str, None]
) – Id of the entity. New id is created if not passed.parent_id (
Union[str, None]
) – Id of parent entity.name (
str
) – Name of entity.label (
Optional[str]
) – Folder label.attribs (
Dict[str, Any]
) – Attribute values.data (
Dict[str, Any]
) – Entity data (custom data).thumbnail_id (
Union[str, None]
) – Id of entity’s thumbnail.active (
bool
) – Is entity active.created (
Optional[bool]
) – Entity is new. When ‘None’ is passed the value is defined based on value of ‘entity_id’.
- Returns:
Added task entity.
- Return type:
- add_task(task)[source]¶
Create task object and add it to entity hub.
- Parameters:
task (
Dict[str, Any]
) – Task entity data.- Returns:
Added task entity.
- Return type:
- property allow_data_changes¶
Entity hub allows changes of ‘data’ key on entities.
Data are private and not all users may have access to them. Also to get ‘data’ for entity is required to use REST api calls, which means to query each entity on-by-one from server.
- Returns:
Data changes are allowed.
- Return type:
bool
- property entities¶
Iterator over available entities.
- Returns:
All queried/created entities cached in hub.
- Return type:
Iterator[BaseEntity]
- fill_project_from_server()[source]¶
Query project data from server and create project entity.
This method will invalidate previous object of Project entity.
- Returns:
Entity that was updated with server data.
- Return type:
- Raises:
ValueError – When project was not found on server.
- folder_path_reseted(folder_id)[source]¶
Method called from ‘FolderEntity’ on path reset.
This should reset cache of folder paths on all children entities.
The path cache is always propagated from top to bottom so if an entity has not cached path it means that any children can’t have it cached.
- get_attributes_for_type(entity_type)[source]¶
Get attributes available for a type.
Attributes are based on entity types.
- Todos:
Use attribute schema to validate values on entities.
- Parameters:
entity_type (
EntityType
) – Entity type for which should be attributes received.- Returns:
- Attribute schemas that are available
for entered entity type.
- Return type:
Dict[str, Dict[str, Any]]
- get_entity_by_id(entity_id)[source]¶
Receive entity by its id without entity type.
The entity must be already existing in cached objects.
- Parameters:
entity_id (
str
) – Id of entity.- Returns:
Entity object or None.
- Return type:
Union[BaseEntity, None]
- get_folder_by_id(entity_id, allow_query=True)[source]¶
Get folder entity by id.
- Parameters:
entity_id (
str
) – Id of folder entity.allow_query (
bool
) – Try to query entity from server if is not available in cache.
- Returns:
Object of folder or ‘None’.
- Return type:
Union[FolderEntity, None]
- get_or_query_entity_by_id(entity_id, entity_types)[source]¶
Get or query entity based on it’s id and possible entity types.
This is a helper function when entity id is known but entity type may have multiple possible options.
- Parameters:
entity_id (
str
) – Entity id.entity_types (
Iterable[str]
) – Possible entity types that can the id represent. e.g. ‘[“folder”, “project”]’
- get_task_by_id(entity_id, allow_query=True)[source]¶
Get task entity by id.
- Parameters:
entity_id (
str
) – Id of task entity.allow_query (
bool
) – Try to query entity from server if is not available in cache.
- Returns:
Object of folder or ‘None’.
- Return type:
Union[TaskEntity, None]
- property path_start_with_slash¶
Folder path should start with slash.
This changed in 0.6.x server version.
- Returns:
Path starts with slash.
- Return type:
bool
- property project_entity¶
Project entity.
- Returns:
Project entity.
- Return type:
- property project_name¶
Project name which is maintained by hub.
- Returns:
Name of project.
- Return type:
str
- class FolderEntity(folder_type, *args, label=None, path=None, tags=None, status=<UNKNOWN_VALUE>, **kwargs)[source]¶
Bases:
BaseEntity
Entity representing a folder on AYON server.
- Parameters:
folder_type (
str
) – Type of folder. Folder type must be available in config of project folder types.entity_id (
Union[str, None]
) – Id of the entity. New id is created if not passed.parent_id (
Union[str, None]
) – Id of parent entity.name (
str
) – Name of entity.attribs (
Dict[str, Any]
) – Attribute values.data (
Dict[str, Any]
) – Entity data (custom data).thumbnail_id (
Union[str, None]
) – Id of entity’s thumbnail.active (
bool
) – Is entity active.label (
Optional[str]
) – Folder label.path (
Optional[str]
) – Folder path. Path consist of all parent names with slash(‘/’) used as separator.entity_hub (
EntityHub
) – Object of entity hub which created object of the entity.created (
Optional[bool]
) – Entity is new. When ‘None’ is passed the value is defined based on value of ‘entity_id’.
- property changes¶
Receive entity changes.
- Returns:
- All values that have changed on
entity. New entity must return None.
- Return type:
Union[Dict[str, Any], None]
- entity_type = 'folder'¶
- property folder_type¶
- classmethod from_entity_data(folder, entity_hub)[source]¶
Create entity based on queried data from server.
- Parameters:
entity_data (
Dict[str, Any]
) – Entity data from server.entity_hub (
EntityHub
) – Hub which handle the entity.
- Returns:
Object of the class.
- Return type:
- get_status()[source]¶
Folder status.
- Returns:
Folder status or ‘UNKNOWN_VALUE’.
- Return type:
Union[str, UNKNOWN_VALUE]
- property has_published_content¶
- property label¶
- parent_entity_types = ['folder', 'project']¶
- property path¶
- property status¶
Folder status.
- Returns:
Folder status or ‘UNKNOWN_VALUE’.
- Return type:
Union[str, UNKNOWN_VALUE]
- property tags¶
Folder tags.
- Returns:
Folder tags.
- Return type:
list[str]
- class ProjectEntity(project_code, library, folder_types, task_types, statuses, *args, **kwargs)[source]¶
Bases:
BaseEntity
Entity representing project on AYON server.
- Parameters:
project_code (
str
) – Project code.library (
bool
) – Is project library project.folder_types (
list[dict[str, Any]]
) – Folder types definition.task_types (
list[dict[str, Any]]
) – Task types definition.entity_id (
Optional[str]
) – Id of the entity. New id is created if not passed.parent_id (
Union[str, None]
) – Id of parent entity.name (
str
) – Name of entity.attribs (
Dict[str, Any]
) – Attribute values.data (
Dict[str, Any]
) – Entity data (custom data).thumbnail_id (
Union[str, None]
) – Id of entity’s thumbnail.active (
bool
) – Is entity active.entity_hub (
EntityHub
) – Object of entity hub which created object of the entity.created (
Optional[bool]
) – Entity is new. When ‘None’ is passed the value is defined based on value of ‘entity_id’.
- property changes¶
Receive entity changes.
- Returns:
- All values that have changed on
entity. New entity must return None.
- Return type:
Union[Dict[str, Any], None]
- default_folder_type_icon = 'folder'¶
- default_task_type_icon = 'task_alt'¶
- entity_type = 'project'¶
- property folder_types¶
- classmethod from_entity_data(project, entity_hub)[source]¶
Create entity based on queried data from server.
- Parameters:
entity_data (
Dict[str, Any]
) – Entity data from server.entity_hub (
EntityHub
) – Hub which handle the entity.
- Returns:
Object of the class.
- Return type:
- get_parent(*args, **kwargs)[source]¶
Parent entity.
- Returns:
Parent object.
- Return type:
Union[BaseEntity, None]
- get_status_by_slugified_name(name)[source]¶
Find status by name.
- Parameters:
name (
str
) – Status name.- Returns:
Status object or None.
- Return type:
Union[ProjectStatus, None]
- property parent¶
Parent entity.
- Returns:
Parent object.
- Return type:
Union[BaseEntity, None]
- parent_entity_types = []¶
- set_parent(parent)[source]¶
Change parent object.
- Parameters:
parent (
BaseEntity
) – New parent for entity.- Raises:
TypeError – If validation of parent does not pass.
- property statuses¶
- property task_types¶
- class ProjectStatus(name, short_name=None, state=None, icon=None, color=None, scope=None, index=None, project_statuses=None, is_new=None)[source]¶
Bases:
object
Project status class.
- Parameters:
name (
str
) – Name of the status. e.g. ‘In progress’short_name (
Optional[str]
) – Short name of the status. e.g. ‘IP’state (
Optional[StatusState]
) – A state of the status.icon (
Optional[str]
) – Icon of the status. e.g. ‘play_arrow’.color (
Optional[str]
) – Color of the status. e.g. ‘#eeeeee’.scope (
Optional[Iterable[str]]
) – Scope of the status. e.g. [‘folder’].index (
Optional[int]
) – Index of the status.project_statuses (
Optional[_ProjectStatuses]
) – Project statuses wrapper.
- property changed¶
Status has changed.
- Returns:
Status has changed.
- Return type:
bool
- property color¶
Get color of project status.
- Returns:
Status color.
- Return type:
str
- color_regex = re.compile('#([a-f0-9]{6})$')¶
- default_color = '#eeeeee'¶
- default_state = 'in_progress'¶
- classmethod from_data(data, index=None, project_statuses=None)[source]¶
Create project status from data.
- Parameters:
data (
dict[str, str]
) – Status data.index (
Optional[int]
) – Status index.project_statuses (
Optional[ProjectStatuses]
) – Project statuses object which wraps the status for a project.
- get_index()[source]¶
Get index of status.
- Returns:
- Index of status or None if status is not under
project.
- Return type:
Union[int, None]
- get_project_statuses()[source]¶
Internal logic method.
- Returns:
Project statuses object.
- Return type:
_ProjectStatuses
- get_short_name()[source]¶
Status short name 3 letters tops.
- Returns:
Status short name.
- Return type:
str
- get_state()[source]¶
Get state of project status.
- Returns:
General state of status.
- Return type:
StatusState
- property icon¶
Name of icon to use for status.
- Returns:
Name of the icon.
- Return type:
str
- property index¶
Get index of status.
- Returns:
- Index of status or None if status is not under
project.
- Return type:
Union[int, None]
- move_after(other)[source]¶
Move status after other status.
- Parameters:
other (
ProjectStatus
) – Status to move after.
- move_before(other)[source]¶
Move status before other status.
- Parameters:
other (
ProjectStatus
) – Status to move before.
- property name¶
Status name.
- Returns:
Status name.
- Return type:
str
- property project_statuses¶
Internal logic method.
- Returns:
Project statuses object.
- Return type:
_ProjectStatuses
- property scope¶
Get scope of the status.
- Returns:
Scope of the status.
- Return type:
Set[str]
- set_color(color)[source]¶
Set color of project status.
- Parameters:
color (
str
) – Color in hex format. Example: ‘#ff0000’.
- set_index(index, **kwargs)[source]¶
Change status index.
- Returns:
- Index of status or None if status is not under
project.
- Return type:
Union[int, None]
- set_project_statuses(project_statuses)[source]¶
Internal logic method to change parent object.
- Parameters:
project_statuses (
_ProjectStatuses
) – Project statuses object.
- set_scope(scope)[source]¶
Get scope of the status.
- Returns:
Scope of the status.
- Return type:
scope (Iterable[str])
- set_short_name(short_name)[source]¶
Change status short name.
- Parameters:
short_name (
str
) – New status short name. 3 letters tops.
- set_state(state)[source]¶
Set color of project status.
- Parameters:
state (
StatusState
) – General state of status.
- property short_name¶
Status short name 3 letters tops.
- Returns:
Status short name.
- Return type:
str
- property slugified_name¶
Slugified and lowere status name.
- Can be used for comparison of existing statuses. e.g. ‘In Progress’
vs. ‘in-progress’.
- Returns:
Slugified and lower status name.
- Return type:
str
- static slugify_name(name)[source]¶
Slugify status name for name comparison.
- Parameters:
name (
str
) – Name of the status.- Returns:
Slugified name.
- Return type:
str
- property state¶
Get state of project status.
- Returns:
General state of status.
- Return type:
StatusState
- unset_project_statuses(project_statuses)[source]¶
Internal logic method to unset parent object.
- Parameters:
project_statuses (
_ProjectStatuses
) – Project statuses object.
- valid_scope = {'folder', 'product', 'representation', 'task', 'version', 'workfile'}¶
- valid_states = {'blocked', 'done', 'in_progress', 'not_started'}¶
- class TaskEntity(task_type, *args, label=None, tags=None, assignees=None, status=<UNKNOWN_VALUE>, **kwargs)[source]¶
Bases:
BaseEntity
Entity representing a task on AYON server.
- Parameters:
task_type (
str
) – Type of task. Task type must be available in config of project task types.entity_id (
Union[str, None]
) – Id of the entity. New id is created if not passed.parent_id (
Union[str, None]
) – Id of parent entity.name (
str
) – Name of entity.label (
Optional[str]
) – Task label.attribs (
Dict[str, Any]
) – Attribute values.data (
Dict[str, Any]
) – Entity data (custom data).thumbnail_id (
Union[str, None]
) – Id of entity’s thumbnail.active (
bool
) – Is entity active.entity_hub (
EntityHub
) – Object of entity hub which created object of the entity.created (
Optional[bool]
) – Entity is new. When ‘None’ is passed the value is defined based on value of ‘entity_id’.
- add_child(child)[source]¶
Add child entity.
- Parameters:
child (
BaseEntity
) – Child object to add.- Raises:
TypeError – When child object has invalid type to be children.
- property assignees¶
Task assignees.
- Returns:
Task assignees.
- Return type:
list[str]
- property changes¶
Receive entity changes.
- Returns:
- All values that have changed on
entity. New entity must return None.
- Return type:
Union[Dict[str, Any], None]
- entity_type = 'task'¶
- classmethod from_entity_data(task, entity_hub)[source]¶
Create entity based on queried data from server.
- Parameters:
entity_data (
Dict[str, Any]
) – Entity data from server.entity_hub (
EntityHub
) – Hub which handle the entity.
- Returns:
Object of the class.
- Return type:
- get_status()[source]¶
Task status.
- Returns:
Task status or ‘UNKNOWN_VALUE’.
- Return type:
Union[str, UNKNOWN_VALUE]
- property label¶
- parent_entity_types = ['folder']¶
- set_assignees(assignees)[source]¶
Change assignees.
- Parameters:
assignees (
Iterable[str]
) – assignees.
- property status¶
Task status.
- Returns:
Task status or ‘UNKNOWN_VALUE’.
- Return type:
Union[str, UNKNOWN_VALUE]
- property tags¶
Task tags.
- Returns:
Task tags.
- Return type:
list[str]
- property task_type¶