rics.translation.factory#

Factory functions for translation classes.

Module Attributes

FetcherFactory

A callable used to create Fetcher instances.

MapperFactory

A callable used to created Mapper instances.

Functions

default_fetcher_factory(clazz, config)

Create a Fetcher from a dict config.

default_mapper_factory(config, for_fetcher)

Create a Mapper from a dict config.

Classes

TranslatorFactory(file, extra_fetchers, ...)

Create a Translator from TOML inputs.

FetcherFactory#

A callable used to create Fetcher instances.

alias of Callable[[str, Dict[str, Any]], AbstractFetcher]

MapperFactory#

A callable used to created Mapper instances.

alias of Callable[[Dict[str, Any], bool], Optional[Mapper]]

default_fetcher_factory(clazz: str, config: Dict[str, Any]) AbstractFetcher[source]#

Create a Fetcher from a dict config.

Parameters
  • clazz – Type of Fetcher to create.

  • config – Keyword arguments for the fetcher class.

Returns

An AbstractFetcher instance.

Raises
default_mapper_factory(config: Dict[str, Any], for_fetcher: bool) Optional[Mapper][source]#

Create a Mapper from a dict config.

Parameters
  • config – Keyword arguments for the Mapper.

  • for_fetcher – Flag indicating that the Mapper returned will be used by an AbstractFetcher instance.

Returns

A Mapper instance.

Raises

ConfigurationError – If config is invalid.

class TranslatorFactory(file: Union[str, bytes, PathLike], extra_fetchers: Iterable[Union[str, bytes, PathLike]], fetcher_factory: Callable[[str, Dict[str, Any]], AbstractFetcher], mapper_factory: Callable[[Dict[str, Any], bool], Optional[Mapper]])[source]#

Bases: Generic[NameType, SourceType, IdType]

Create a Translator from TOML inputs.

Parameters
  • file – Path to a TOML file, or a pre-parsed dict.

  • extra_fetchers – Path to TOML files defining additional fetchers. Useful for fetching from multiple sources or kinds of sources, for example locally stored files in conjunction with one or more databases. The fetchers are ranked by input order, with the fetcher defined in file being given the highest priority (rank 0).

  • fetcher_factory – A Fetcher instance, or a callable taking (name, kwargs) which returns an AbstractFetcher.

  • mapper_factory – A Mapper instance, or a callable taking (kwargs) which returns a Mapper. Used for both Translator and Fetcher mapper initialization.

See also

The Translator Configuration Files page.

create() Translator[source]#

Create a Translator from a TOML file.

Returns

A Translator object.

Raises

exceptions.ConfigurationError – If the config is invalid.