Skip to main content

"Invenio REST API client."

Project description

inveniordm-py

https://github.com/inveniosoftware/inveniordm-py/workflows/CI/badge.svg https://img.shields.io/github/tag/inveniosoftware/inveniordm-py.svg https://img.shields.io/pypi/dm/inveniordm-py.svg https://img.shields.io/github/license/inveniosoftware/inveniordm-py.svg

inveniordm-py is a Python client designed to interact with the InvenioRDM API.

Usage

Here’s a basic example of how to use inveniordm-py:

from inveniordm_py.client import InvenioAPI

# Initialize client
client = InvenioAPI('https://your-invenio-instance.com', 'your-token')

# Get a list of all records
records = client.records.search()

The client supports creating and updating drafts:

from inveniordm_py.records.metadata import DraftMetadata

# Create a draft with metadata
data = {
    "metadata": {
        "title": "Test",
        "resource_type": {
            "id": "publication-article",
        },
        "publication_date": "2024",
        "creators": [
            {
                "person_or_org": {
                    "family_name": "Brown",
                    "given_name": "Troy",
                    "type": "personal",
                }
            },
        ],
        "publisher": "Zenodo"
    }
}
draft = client.records.create(data=DraftMetadata(data))

# Update metadata and draft
data.update({
    "metadata": {
        "title": "Test 2",
    }
})
draft.update(data=DraftMetadata(data))

Files can be added to the draft:

from inveniordm_py.files.metadata import FileMetadata, OutgoingStream, FileMetadata

# Define files metadata
fname = "test.txt"
fpath = "/path/to/test.txt"
file_data = FileMetadata({"key": fname})

# Create the file and add it to the draft using a stream
draft.files.create(file_data)
stream = open(fpath, "rb")
f.set_contents(OutgoingStream(data=stream))
f.commit()

# It also supports the addition of multiple files from disk
_dir = "/path/to/dir"
file_data = FilesListMetadata([{"key": fname} for fname in os.listdir(_dir)])
draft.files.create(file_data)
for f in draft.files:
    file_path = os.path.join(_dir, f.data['key'])
    stream = open(file_path, "rb")
    f.set_contents(OutgoingStream(data=stream))
    f.commit()

Finally, the draft can be published:

# Publish the draft and check the status
record = draft.publish()
print(record.data["status"])

Changes

Version 0.1.0 (2024-05-13)

  • Initial public alpha release.

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

inveniordm-py-0.1.0.tar.gz (22.8 kB view details)

Uploaded Source

Built Distribution

inveniordm_py-0.1.0-py2.py3-none-any.whl (20.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file inveniordm-py-0.1.0.tar.gz.

File metadata

  • Download URL: inveniordm-py-0.1.0.tar.gz
  • Upload date:
  • Size: 22.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.8.19

File hashes

Hashes for inveniordm-py-0.1.0.tar.gz
Algorithm Hash digest
SHA256 50c0d4440c36a80442d02961da7ae1744c4ed598915bd1732b08086995901b4b
MD5 5b2b8ea8792cb31e9243f579e234542b
BLAKE2b-256 a692c622e3130af8ca6cbe539cb1b039dccb087f0ae90eaa5f5c87da0214c316

See more details on using hashes here.

File details

Details for the file inveniordm_py-0.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for inveniordm_py-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 03d3ba787d436c084452dda05f1f0c93aeb455bdf2f81c2da8b2c8d1582386bd
MD5 b25438312c01b2464ab03f9ec9091e5c
BLAKE2b-256 d3f01948225d377b26366aa5f992dd762c06eb0cb9c32f91f4ec16edd10c4085

See more details on using hashes here.

Supported by

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