Skip to content

oarepo_config.datastreams

oarepo_config.datastreams

Configuration for datastreams.

configure_datastreams(readers: dict[str, Any] | None = None, writers: dict[str, Any] | None = None, transformers: dict[str, Any] | None = None) -> None

Register custom sources for importing vocabularies (fixtures) into the repository.

Vocabularies (controlled lists such as languages, resource types or licenses) can be loaded from files or external services using "datastreams" - a reader that fetches/reads the raw data, an optional transformer that converts it, and a writer that stores it. Invenio already ships with a set of built-in readers/writers/ transformers; use this function only if you need to add your own (for example, a reader that pulls a vocabulary from a custom REST API).

Parameters:

Name Type Description Default
readers dict[str, Any] | None

Extra readers to make available, as a mapping of a short name to either an import path string ("my_package.readers:MyReader") or the class/object itself.

None
writers dict[str, Any] | None

Extra writers to make available, in the same format as readers.

None
transformers dict[str, Any] | None

Extra transformers to make available, in the same format as readers.

None

Any readers/writers/transformers already registered (for example by configure_generic_parameters) are kept; the ones passed here are added on top.

Invenio configuration variables set:

  • VOCABULARIES_DATASTREAM_READERS - only if readers is given; merged with any existing value.
  • VOCABULARIES_DATASTREAM_WRITERS - only if writers is given; merged with any existing value.
  • VOCABULARIES_DATASTREAM_TRANSFORMERS - only if transformers is given; merged with any existing value.
Example
config.configure_datastreams(
    readers={
        "myreader": "my_package:MyReader"
    },
    writers={
        "mywriter": "my_package:MyWriter"
    },
)
Source code in oarepo_config/datastreams.py
def configure_datastreams(
    readers: dict[str, Any] | None = None,
    writers: dict[str, Any] | None = None,
    transformers: dict[str, Any] | None = None,
) -> None:
    """Register custom sources for importing vocabularies (fixtures) into the repository.

    Vocabularies (controlled lists such as languages, resource types or
    licenses) can be loaded from files or external services using
    "datastreams" - a reader that fetches/reads the raw data, an
    optional transformer that converts it, and a writer that stores it.
    Invenio already ships with a set of built-in readers/writers/
    transformers; use this function only if you need to add your own
    (for example, a reader that pulls a vocabulary from a custom REST
    API).

    Args:
        readers: Extra readers to make available, as a mapping of a
            short name to either an import path string
            (`"my_package.readers:MyReader"`) or the class/object
            itself.
        writers: Extra writers to make available, in the same format as
            `readers`.
        transformers: Extra transformers to make available, in the same
            format as `readers`.

    Any readers/writers/transformers already registered (for example by
    [`configure_generic_parameters`][oarepo_config.configure_generic_parameters]) are kept; the ones passed here
    are added on top.

    Invenio configuration variables set:

    * `VOCABULARIES_DATASTREAM_READERS` - only if `readers` is
      given; merged with any existing value.
    * `VOCABULARIES_DATASTREAM_WRITERS` - only if `writers` is
      given; merged with any existing value.
    * `VOCABULARIES_DATASTREAM_TRANSFORMERS` - only if
      `transformers` is given; merged with any existing value.

    Example:
        ```python
        config.configure_datastreams(
            readers={
                "myreader": "my_package:MyReader"
            },
            writers={
                "mywriter": "my_package:MyWriter"
            },
        )
        ```

    """
    # can't move into a function cause of constant_from_caller methods
    if readers:
        objs = {k: obj_or_import_string(v) for k, v in readers.items()}
        VOCABULARIES_DATASTREAM_READERS = merge_with_caller("VOCABULARIES_DATASTREAM_READERS", objs)

    if writers:
        objs = {k: obj_or_import_string(v) for k, v in writers.items()}
        VOCABULARIES_DATASTREAM_WRITERS = merge_with_caller("VOCABULARIES_DATASTREAM_WRITERS", objs)

    if transformers:
        objs = {k: obj_or_import_string(v) for k, v in transformers.items()}
        VOCABULARIES_DATASTREAM_TRANSFORMERS = merge_with_caller("VOCABULARIES_DATASTREAM_TRANSFORMERS", objs)
    set_constants_in_caller(locals())