aiida.tools.importexport.dbexport package

Provides export functionalities.

class aiida.tools.importexport.dbexport.ExportFileFormat(value)[source]

Bases: str, enum.Enum

Archive file formats

TAR_GZIPPED = 'tar.gz'
ZIP = 'zip'
__dict__ = mappingproxy({'_generate_next_value_': <function Enum._generate_next_value_>, '__module__': 'aiida.tools.importexport.common.config', '__doc__': 'Archive file formats', '__dict__': <attribute '__dict__' of 'ExportFileFormat' objects>, '__weakref__': <attribute '__weakref__' of 'ExportFileFormat' objects>, '_member_names_': ['ZIP', 'TAR_GZIPPED'], '_member_map_': {'ZIP': <ExportFileFormat.ZIP: 'zip'>, 'TAR_GZIPPED': <ExportFileFormat.TAR_GZIPPED: 'tar.gz'>}, '_member_type_': <class 'str'>, '_value2member_map_': {'zip': <ExportFileFormat.ZIP: 'zip'>, 'tar.gz': <ExportFileFormat.TAR_GZIPPED: 'tar.gz'>}, 'ZIP': <ExportFileFormat.ZIP: 'zip'>, 'TAR_GZIPPED': <ExportFileFormat.TAR_GZIPPED: 'tar.gz'>, '__repr__': <function Enum.__repr__>, '__str__': <function Enum.__str__>, '__format__': <function Enum.__format__>, '__new__': <function Enum.__new__>})
__module__ = 'aiida.tools.importexport.common.config'
__weakref__

list of weak references to the object (if defined)

_generate_next_value_(start, count, last_values)
_member_map_ = {'TAR_GZIPPED': <ExportFileFormat.TAR_GZIPPED: 'tar.gz'>, 'ZIP': <ExportFileFormat.ZIP: 'zip'>}
_member_names_ = ['ZIP', 'TAR_GZIPPED']
_member_type_

alias of builtins.str

_value2member_map_ = {'tar.gz': <ExportFileFormat.TAR_GZIPPED: 'tar.gz'>, 'zip': <ExportFileFormat.ZIP: 'zip'>}
aiida.tools.importexport.dbexport.export(entities: Optional[Iterable[Any]] = None, filename: Optional[str] = None, file_format: Union[str, Type[aiida.tools.importexport.archive.writers.ArchiveWriterAbstract]] = <ExportFileFormat.ZIP: 'zip'>, overwrite: bool = False, silent: Optional[bool] = None, use_compression: Optional[bool] = None, include_comments: bool = True, include_logs: bool = True, allowed_licenses: Optional[Union[list, Callable]] = None, forbidden_licenses: Optional[Union[list, Callable]] = None, writer_init: Optional[Dict[str, Any]] = None, batch_size: int = 100, **traversal_rules: bool)aiida.tools.importexport.archive.writers.ArchiveWriterAbstract[source]

Export AiiDA data to an archive file.

Note, the logging level and progress reporter should be set externally, for example:

from aiida.common.progress_reporter import set_progress_bar_tqdm

EXPORT_LOGGER.setLevel('DEBUG')
set_progress_bar_tqdm(leave=True)
export(...)

Deprecated since version 1.5.0: Support for the parameter silent will be removed in v2.0.0. Please set the log level and progress bar implementation independently.

Deprecated since version 1.5.0: Support for the parameter use_compression will be removed in v2.0.0. Please use writer_init={‘use_compression’: True}.

Deprecated since version 1.2.1: Support for the parameters what and outfile will be removed in v2.0.0. Please use entities and filename instead, respectively.

Parameters
  • entities – a list of entity instances; they can belong to different models/entities.

  • filename – the filename (possibly including the absolute path) of the file on which to export.

  • file_format – ‘zip’, ‘tar.gz’ or ‘folder’ or a specific writer class.

  • overwrite – if True, overwrite the output file without asking, if it exists. If False, raise an ArchiveExportError if the output file already exists.

  • allowed_licenses – List or function. If a list, then checks whether all licenses of Data nodes are in the list. If a function, then calls function for licenses of Data nodes expecting True if license is allowed, False otherwise.

  • forbidden_licenses – List or function. If a list, then checks whether all licenses of Data nodes are in the list. If a function, then calls function for licenses of Data nodes expecting True if license is allowed, False otherwise.

  • include_comments – In-/exclude export of comments for given node(s) in entities. Default: True, include comments in export (as well as relevant users).

  • include_logs – In-/exclude export of logs for given node(s) in entities. Default: True, include logs in export.

  • writer_init – Additional key-word arguments to pass to the writer class init

  • batch_size – batch database query results in sub-collections to reduce memory usage

  • traversal_rules – graph traversal rules. See aiida.common.links.GraphTraversalRules what rule names are toggleable and what the defaults are.

Returns

a dictionary of data regarding the export process (timings, etc)

Raises

Submodules

Utility functions for export of AiiDA entities

aiida.tools.importexport.dbexport.utils.check_licenses(node_licenses, allowed_licenses, forbidden_licenses)[source]

Check licenses

aiida.tools.importexport.dbexport.utils.check_process_nodes_sealed(nodes)[source]

Check ProcessNode s are sealed Only sealed ProcessNode s may be exported.

Parameters

nodes (list, int) – ProcessNode s to be checked. Should be their PK(s).

Raises

ExportValidationError – if a ProcessNode is not sealed or nodes is not a list, set, or int.

aiida.tools.importexport.dbexport.utils.deprecated_parameters(old, new)[source]

Handle deprecated parameter (where it is replaced with another)

Parameters
  • old (dict) – The old, deprecated parameter as a dict with keys “name” and “value”

  • new (dict) – The new parameter as a dict with keys “name” and “value”

Returns

New parameter’s value (if not defined, then old parameter’s value)

aiida.tools.importexport.dbexport.utils.fill_in_query(partial_query, originating_entity_str, current_entity_str, tag_suffixes=None, entity_separator='_')[source]

This function recursively constructs QueryBuilder queries that are needed for the SQLA export function. To manage to construct such queries, the relationship dictionary is consulted (which shows how to reference different AiiDA entities in QueryBuilder. To find the dependencies of the relationships of the exported data, the get_all_fields_info (which described the exported schema and its dependencies) is consulted.

aiida.tools.importexport.dbexport.utils.serialize_dict(datadict, remove_fields=None, rename_fields=None, track_conversion=False)[source]

Serialize the dict using the serialize_field function to serialize each field.

Parameters
  • remove_fields

    a list of strings. If a field with key inside the remove_fields list is found, it is removed from the dict.

    This is only used at level-0, no removal is possible at deeper levels.

  • rename_fields

    a dictionary in the format {"oldname": "newname"}.

    If the “oldname” key is found, it is replaced with the “newname” string in the output dictionary.

    This is only used at level-0, no renaming is possible at deeper levels.

  • track_conversion – if True, a tuple is returned, where the first element is the serialized dictionary, and the second element is a dictionary with the information on the serialized fields.

aiida.tools.importexport.dbexport.utils.serialize_field(data, track_conversion=False)[source]

Serialize a single field.

Todo

Generalize such that it the proper function is selected also during import

aiida.tools.importexport.dbexport.utils.summary(*, file_format, export_version, outfile, include_comments, include_logs, traversal_rules)[source]

Print summary for export