aiida_restapi.services package#

Submodules#

aiida_restapi.services.entity module#

REST API entity repository.

class aiida_restapi.services.entity.EntityService(entity_class)[source]#

Bases: Generic[EntityType, EntityModelType]

Service for managing AiiDA entities.

This class provides methods to retrieve AiiDA entities with optional filtering, sorting, and pagination.

Parameters:

entity_class – The AiiDA ORM entity class associated with this utility, e.g. orm.User, orm.Node, etc.

__annotations__ = {}#
__dict__ = mappingproxy({'__module__': 'aiida_restapi.services.entity', '__doc__': 'Service for managing AiiDA entities.\n\n    This class provides methods to retrieve AiiDA entities with optional filtering, sorting, and pagination.\n\n    :param entity_class: The AiiDA ORM entity class associated with this utility, e.g. `orm.User`, `orm.Node`, etc.\n    ', '__init__': <function EntityService.__init__>, 'project': <property object>, 'get_schema': <function EntityService.get_schema>, 'get_projections': <function EntityService.get_projections>, 'get_one': <function EntityService.get_one>, 'get_many': <function EntityService.get_many>, 'get_related_one': <function EntityService.get_related_one>, 'get_related_many': <function EntityService.get_related_many>, 'get_field': <function EntityService.get_field>, 'add': <function EntityService.add>, 'update': <function EntityService.update>, '_get_projections': <function EntityService._get_projections>, '_apply_update': <function EntityService._apply_update>, '__orig_bases__': (typing.Generic[~EntityType, ~EntityModelType],), '__dict__': <attribute '__dict__' of 'EntityService' objects>, '__weakref__': <attribute '__weakref__' of 'EntityService' objects>, '__parameters__': (~EntityType, ~EntityModelType), '__annotations__': {}})#
__init__(entity_class)[source]#
__module__ = 'aiida_restapi.services.entity'#
__orig_bases__ = (typing.Generic[~EntityType, ~EntityModelType],)#
__parameters__ = (~EntityType, ~EntityModelType)#
__weakref__#

list of weak references to the object

_apply_update(entity, model)[source]#

Apply changes to stored entity from a model payload.

Parameters:
  • entity (orm.Entity) – The AiiDA entity to update.

  • model (EntityModelType) – The Pydantic model of the entity to update.

_get_projections(orm_class=None)[source]#

Get the list of projections to use when querying the AiiDA entity.

Exclude fields that may be large.

Parameters:

orm_class (type[orm.Entity] | None) – The AiiDA ORM entity class to get the projections for.

Returns:

The list of projections to use when querying the AiiDA entity.

Return type:

list[str]

add(model)[source]#

Create new AiiDA entity from its model.

Parameters:

model (EntityModelType) – The Pydantic model of the entity to create.

Returns:

The created and stored AiiDA Entity instance.

Return type:

dict[str, t.Any]

get_field(identifier, field)[source]#

Get a specific field of an entity.

Parameters:
  • identifier (str | int) – The id of the entity to retrieve the extras for.

  • field (str) – The specific field to retrieve.

Returns:

The value of the specified field.

Return type:

t.Any

get_many(query_params)[source]#

Get AiiDA entities with optional filtering, sorting, and/or pagination.

Parameters:

query_params (QueryBuilderParams) – The query parameters for filtering, sorting, and pagination.

Returns:

The paginated results, including total count, current page, page size, and list of serialized entities.

Return type:

PaginatedResults

get_one(identifier)[source]#

Get an AiiDA entity by id.

Parameters:

identifier (str | int) – The id of the entity to retrieve.

Returns:

The serialized AiiDA entity.

Return type:

dict[str, t.Any]

get_projections()[source]#

Get queryable projections for the AiiDA entity.

Returns:

The list of queryable projections for the AiiDA entity.

Return type:

list[str]

Get related foreign entities of an entity.

Parameters:
  • identifier (str | int) – The id of the entity to retrieve the foreign entities for.

  • related_type (type[orm.Entity]) – The related AiiDA ORM entity class to retrieve.

  • query_params (QueryParams) – The query parameters, including filters, order_by, page_size, and page.

Returns:

The paginated results of related foreign entities.

Return type:

PaginatedResults

Get a related foreign entity of an entity.

Parameters:
  • identifier (str | int) – The id of the entity to retrieve the foreign entity for.

  • related_type (type[orm.Entity]) – The related AiiDA ORM entity class to retrieve.

Returns:

The related foreign entity.

Return type:

dict[str, t.Any]

get_schema(which=None)[source]#

Get JSON schema for the AiiDA entity.

Parameters:

which (str | None) – The type of schema to retrieve: ‘read’ or ‘write’.

Returns:

A dictionary with ‘read’ and ‘write’ keys containing the respective JSON schemas.

Return type:

dict[str, t.Any]

Raises:

ValueError – If the ‘which’ parameter is not ‘read’ or ‘write’.

property project#

Get the list of projections to use when querying the AiiDA entity.

Returns:

The list of projections to use when querying the AiiDA entity.

Return type:

list[str]

update(identifier, model)[source]#

Update an existing AiiDA entity.

Parameters:
  • identifier (str | int) – The id of the entity to update.

  • model (EntityModelType) – The Pydantic model of the entity to update.

Returns:

The updated and stored AiiDA Entity instance.

Return type:

dict[str, t.Any]

aiida_restapi.services.node module#

REST API node repository.

class aiida_restapi.services.node.NodeService(entity_class)[source]#

Bases: EntityService[NodeType, NodeModelType]

Service for managing AiiDA nodes.

DEFAULT_NAMESPACE_LABEL = '~no-entry-point~'#
FULL_TYPE_CONCATENATOR = '|'#
LIKE_OPERATOR_CHARACTER = '%'#
__annotations__ = {}#
__module__ = 'aiida_restapi.services.node'#
__orig_bases__ = (aiida_restapi.services.entity.EntityService[~NodeType, ~NodeModelType],)#
__parameters__ = (~NodeType, ~NodeModelType)#
_apply_update(entity, model)[source]#

Apply changes to stored entity from a model payload.

Parameters:
  • entity (orm.Entity) – The AiiDA entity to update.

  • model (EntityModelType) – The Pydantic model of the entity to update.

_construct_full_type(node_type, process_type)[source]#

Return the full type, which fully identifies the type of any Node with the given node_type and process_type.

Parameters:
  • node_type (str) – the node_type of the Node

  • process_type (str) – the process_type of the Node

Returns:

the full type, which is a unique identifier

Return type:

str

_get_full_type_filters(full_type)[source]#

Return the QueryBuilder filters that will return all Nodes identified by the given full_type.

Parameters:

full_type (str) – the full_type node type identifier

Returns:

dictionary of filters to be passed for the filters keyword in QueryBuilder.append

Return type:

dict[str, t.Any]

Raises:
  • ValueError – if the full_type is invalid

  • TypeError – if the full_type is not a string type

_load_entry_point_from_full_type(full_type)[source]#

Return the loaded entry point for the given full_type unique node type identifier.

Parameters:

full_type (str) – the full_type unique node type identifier

Returns:

the loaded entry point

Return type:

t.Any

Raises:
  • ValueError – if the full_type is invalid

  • TypeError – if the full_type is not a string type

  • EntryPointError – if the corresponding entry point cannot be loaded

_load_entry_point_from_node_type(node_type)[source]#

Return the loaded entry point for the given node_type.

Parameters:

node_type (str) – the node_type unique node type identifier

Returns:

the loaded entry point

Return type:

NodeType

Raises:

ValueError – if the node_type is invalid

_validate_full_type(full_type)[source]#

Validate that the full_type is a valid full type unique node identifier.

Parameters:

full_type (str) – a Node full type

Raises:
  • ValueError – if the full_type is invalid

  • TypeError – if the full_type is not a string type

add(model, files=None)[source]#

Create new AiiDA node from its model.

Parameters:
  • node_model – The AiiDA ORM model of the node to create.

  • files (dict[str, UploadFile] | None) – Optional list of files to attach to the node.

Returns:

The created and stored AiiDA node instance.

Return type:

dict[str, t.Any]

get_download_formats(full_type=None)[source]#

Returns dict of possible node formats for all available node types.

Parameters:

full_type (str | None) – The full type of the AiiDA node.

Returns:

A dictionary with full types as keys and list of available formats as values.

Return type:

dict[str, list[str]]

Get the incoming links of a node.

Parameters:
  • uuid (str) – The uuid of the node to retrieve the incoming links for.

  • query_params (QueryBuilderParams) – The query parameters for filtering, sorting, and pagination.

  • direction (str) – Specify whether to retrieve incoming or outgoing links.

Returns:

The paginated requested linked nodes.

Return type:

PaginatedResults

get_projections(node_type=None)[source]#

Get projectable properties for the AiiDA entity.

Parameters:

node_type (str | None) – The AiiDA node type.

Returns:

The list of projectable properties for the AiiDA node.

Return type:

list[str]

get_repository_metadata(uuid)[source]#

Get the repository metadata of a node.

Parameters:

uuid (str) – The uuid of the node to retrieve the repository metadata for.

Returns:

A dictionary with the repository file metadata.

Return type:

dict[str, dict]

with_key = 'node'#

Module contents#