Skip to main content

Prefect integrations interacting with an InvenioRDM instance.

Project description

prefect-invenio-rdm

prefect-invenio-rdm is a collection of prebuilt Prefect tasks and flows that can be used to publish local data to an InvenioRDM instance.

Getting started

Requires an installation of Python 3.9+.

Installation

Install prefect-invenio-rdm:

pip install prefect-invenio-rdm

Authentication

To authenticate with an InvenioRDM instance, either define the following environment variables:

export INVENIO_RDM_ACCESS_TOKEN=<access_token>
export INVENIO_RDM_BASE_URL=<base url>

or create and provide instance of InvenioRDMCredentials:

from prefect_invenio_rdm.credentials import InvenioRDMCredentials

credentials = InvenioRDMCredentials(
    base_url="https://sandbox.zenodo.org/api/",
    token="access token",
)

Concurrency

To configure concurrency for API calls, create a global concurrency limit named rate-limit:invenio-rdm-api:

prefect gcl create rate-limit:invenio-rdm-api --limit 5 --slot-decay-per-second 1.0

Example

import asyncio
from prefect import flow
from prefect_invenio_rdm.flows import create_record_dir, create_record_files
from prefect_invenio_rdm.models.records import DraftConfig, Access
from prefect_invenio_rdm.credentials import InvenioRDMCredentials
from prefect_invenio_rdm.models.api import APIResult


@flow(log_prints=True)
async def upload_data() -> None:
    # create credentials
    credentials = InvenioRDMCredentials(
        base_url="https://sandbox.zenodo.org/api/",
        token="access token",
    )

    # provide draft record configurations
    config = DraftConfig(
        record_access=Access.PUBLIC,
        files_access=Access.PUBLIC,
        files_enabled=True,
        metadata={
            "creators": [
                {
                    "person_or_org": {
                        "family_name": "Collins",
                        "given_name": "Thomas",
                        "identifiers": [
                            {"scheme": "orcid", "identifier": "0000-0002-1825-0097"}
                        ],
                        "name": "Collins, Thomas",
                        "type": "personal",
                    },
                    "affiliations": [{"id": "01ggx4157", "name": "Entity One"}],
                },
            ],
            "publisher": "InvenioRDM",
            "publication_date": "2025-01-10",
            "resource_type": {"id": "dataset"},
            "title": "My dataset",
        },
        community_id="9d50c9c1-afd0-4dc1-ad50-91040788af4f",
        custom_fields={
            "code:codeRepository": "https://github.com/organization/repository",
            "code:developmentStatus": {"id": "wip"},
            "code:programmingLanguage": [{"id": "python"}],
        },
    )

    # upload data from a directory
    result: APIResult = await create_record_dir(
        credentials=credentials,
        directory="/home/user/data/dataset/",
        config=config,
        file_pattern="*.zip",
        # delete created record if any downstream process (e.g file upload) fails 
        delete_on_failure=True,
        # automatically publishes the draft record if no failures arise
        auto_publish=False,
    )

    # or upload data from a list of files
    result: APIResult = await create_record_files(
        credentials=credentials,
        files=["/home/user/data/dataset/content.zip", "/home/user/images/image.png"],
        config=config,
        delete_on_failure=True,
        auto_publish=False,
    )

    print(result)


if __name__ == "__main__":
    asyncio.run(upload_data())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prefect_invenio_rdm-0.0.1.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

prefect_invenio_rdm-0.0.1-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file prefect_invenio_rdm-0.0.1.tar.gz.

File metadata

  • Download URL: prefect_invenio_rdm-0.0.1.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.12

File hashes

Hashes for prefect_invenio_rdm-0.0.1.tar.gz
Algorithm Hash digest
SHA256 925a9e9e917ffab1081c9074c9a4758387f431684e533d32df2a0c1f10fe80f6
MD5 1cf5f7ddbbc6bb7a8db1b10b36068c78
BLAKE2b-256 84a00624e33c880374acc538a90e07bf789bcbe8def9a8119ab330d3aed70b80

See more details on using hashes here.

File details

Details for the file prefect_invenio_rdm-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for prefect_invenio_rdm-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9bbf4592ca5c65ae7408683758ea3d7d73c029a4acfbf0663f47adf2d79208b2
MD5 41cdf881fe1f1549ecba1353c8078bdb
BLAKE2b-256 00fa78dfda456753edb9f815ab0d996ab0d20ba529039eea35cf49ef2beaae51

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page