id_translation.dio#

Insertion and extraction of IDs and translations.

See Translation IO for help.

Module Attributes

ENTRYPOINT_GROUP

Group used to discover DataStructureIO integrations.

Functions

get_resolution_order(*[, real])

Returns known DataStructureIO implementations in the correct resolution order.

is_registered(io)

Return IO implementation registration status.

load_integrations()

Discover, load, and register entrypoint integrations.

pretty_io_name(arg)

Pretty-print IO name.

register_io(io)

Register a new IO implementation.

resolve_io(arg, *[, io_kwargs, task_id])

Get an IO instance for arg.

Classes

DataStructureIO()

Insertion and extraction of IDs and translations.

class DataStructureIO[source]#

Bases: Generic[TranslatableT, NameType, SourceType, IdType]

Insertion and extraction of IDs and translations.

abstractmethod extract(translatable, names)[source]#

Extract IDs from translatable.

Parameters:
  • translatable – Data to extract IDs from.

  • names – List of names in translatable to extract IDs for.

Returns:

A dict {name: ids}.

classmethod get_rank()[source]#

Return the rank of this implementation.

See dio.get_resolution_order() for details. The highest possible rank is 0.

Returns:

Implementation rank.

Raises:

ValueError – If the implementation is not registered.

abstractmethod classmethod handles_type(arg)[source]#

Return True if the implementation handles data for the type of arg.

abstractmethod insert(translatable, names, tmap, copy)[source]#

Insert translations into translatable.

Parameters:
  • translatable – Data to translate. Modified iff copy=False.

  • names – Names in translatable to translate.

  • tmap – Translations for IDs in translatable.

  • copy – If True, modify contents of the original translatable. Otherwise, returns a copy.

Returns:

A copy of translatable if copy=True, None otherwise.

Raises:

NotInplaceTranslatableError – If copy=False for a type which is not translatable in-place.

classmethod is_registered()[source]#

Returns registration status for this implementation.

See dio.is_registered() for details.

names(translatable)[source]#

Extract names from translatable.

Parameters:

translatable – Data to extract names from.

Returns:

A list of names to translate. Returns None if names cannot be extracted.

priority = 10000#

Determines order in which IOs are considered (higher = earlier).

Set priority < 0 to disable.

classmethod register()[source]#

Register this implementation for all Translator instances.

See dio.register_io() for details.

ENTRYPOINT_GROUP = 'id_translation.dio'#

Group used to discover DataStructureIO integrations.

See load_integrations() and importlib.metadata.entry_points() for details.

get_resolution_order(*, real=False)[source]#

Returns known DataStructureIO implementations in the correct resolution order.

Parameters:

real – If True, return the actual list instead of a copy.

Returns:

A list of IO implementations sorted by rank.

is_registered(io)[source]#

Return IO implementation registration status.

Implementations should register themselves using DataStructureIO.register().

Parameters:

io – A DataStructureIO type.

load_integrations()[source]#

Discover, load, and register entrypoint integrations.

Reset the registry, then load entrypoints in the 'id_translation.dio' entrypoint group (see importlib.metadata.entry_points() for details).

Will skip integrations that raise ImportError when loaded (except circular imports).

Raises:

TypeError – If an integration does not inherit from DataStructureIO.

Notes

Called automatically when id_translation is imported.

pretty_io_name(arg)[source]#

Pretty-print IO name.

register_io(io)[source]#

Register a new IO implementation.

Classes are polled through DataStructureIO.handles_type() in based on DataStructureIO.priority.

Parameters:

io – A DataStructureIO type

resolve_io(arg, *, io_kwargs=None, task_id=None)[source]#

Get an IO instance for arg.

Parameters:
  • arg – An argument to get IO for.

  • io_kwargs – Keyword arguments for the IO class (e.g. PandasIO).

  • task_id – Used for logging.

Returns:

A data structure IO instance for arg.

Raises:

UntranslatableTypeError – If no suitable IO implementation could be found.

See also

The register_io() function.

Modules

default

Default DataStructureIO implementations.

exceptions

Data structure IO exceptions.

integration

Integration modules.