..
Copyright (C) 2024 CERN.
inveniordm-py is free software; you can redistribute it and/or modify
it under the terms of the MIT License; see LICENSE file for more details.
================
inveniordm-py
================
.. image:: https://github.com/inveniosoftware/inveniordm-py/workflows/CI/badge.svg
:target: https://github.com/inveniosoftware/inveniordm-py/actions?query=workflow%3ACI
.. image:: https://img.shields.io/github/tag/inveniosoftware/inveniordm-py.svg
:target: https://github.com/inveniosoftware/inveniordm-py/releases
.. image:: https://img.shields.io/pypi/dm/inveniordm-py.svg
:target: https://pypi.python.org/pypi/inveniordm-py
.. image:: https://img.shields.io/github/license/inveniosoftware/inveniordm-py.svg
:target: https://github.com/inveniosoftware/inveniordm-py/blob/master/LICENSE
`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`:
.. code-block:: python
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:
.. code-block:: python
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:
.. code-block:: python
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:
.. code-block:: python
# Publish the draft and check the status
record = draft.publish()
print(record.data["status"])
..
Copyright (C) 2024 CERN.
inveniordm-py is free software; you can redistribute it and/or modify
it under the terms of the MIT License; see LICENSE file for more details.
Changes
=======
Version 0.1.1 (released 2024-07-14)
- installation: remove `invenio-i18n` dependency
Version 0.1.0 (released 2024-05-13)
- Initial public alpha release.
Raw data
{
"_id": null,
"home_page": "https://github.com/inveniosoftware/inveniordm-py",
"name": "inveniordm-py",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "invenio rest api",
"author": "CERN",
"author_email": "info@inveniosoftware.org",
"download_url": "https://files.pythonhosted.org/packages/36/01/bf0787c40c62d64d32d3b484572d42f218c06417109629a00f930325e351/inveniordm-py-0.1.1.tar.gz",
"platform": "any",
"description": "..\n Copyright (C) 2024 CERN.\n\n inveniordm-py is free software; you can redistribute it and/or modify\n it under the terms of the MIT License; see LICENSE file for more details.\n\n================\n inveniordm-py\n================\n\n.. image:: https://github.com/inveniosoftware/inveniordm-py/workflows/CI/badge.svg\n :target: https://github.com/inveniosoftware/inveniordm-py/actions?query=workflow%3ACI\n\n.. image:: https://img.shields.io/github/tag/inveniosoftware/inveniordm-py.svg\n :target: https://github.com/inveniosoftware/inveniordm-py/releases\n\n.. image:: https://img.shields.io/pypi/dm/inveniordm-py.svg\n :target: https://pypi.python.org/pypi/inveniordm-py\n\n.. image:: https://img.shields.io/github/license/inveniosoftware/inveniordm-py.svg\n :target: https://github.com/inveniosoftware/inveniordm-py/blob/master/LICENSE\n\n`inveniordm-py` is a Python client designed to interact with the InvenioRDM API.\n\n\n================\nUsage\n================\n\nHere's a basic example of how to use `inveniordm-py`:\n\n.. code-block:: python\n\n from inveniordm_py.client import InvenioAPI\n\n # Initialize client\n client = InvenioAPI('https://your-invenio-instance.com', 'your-token')\n\n # Get a list of all records\n records = client.records.search()\n\nThe client supports creating and updating drafts:\n\n.. code-block:: python\n\n from inveniordm_py.records.metadata import DraftMetadata\n\n # Create a draft with metadata\n data = {\n \"metadata\": {\n \"title\": \"Test\",\n \"resource_type\": {\n \"id\": \"publication-article\",\n },\n \"publication_date\": \"2024\",\n \"creators\": [\n {\n \"person_or_org\": {\n \"family_name\": \"Brown\",\n \"given_name\": \"Troy\",\n \"type\": \"personal\",\n }\n },\n ],\n \"publisher\": \"Zenodo\"\n }\n }\n draft = client.records.create(data=DraftMetadata(data))\n\n # Update metadata and draft\n data.update({\n \"metadata\": {\n \"title\": \"Test 2\",\n }\n })\n draft.update(data=DraftMetadata(data))\n\nFiles can be added to the draft:\n\n.. code-block:: python\n\n from inveniordm_py.files.metadata import FileMetadata, OutgoingStream, FileMetadata\n\n # Define files metadata\n fname = \"test.txt\"\n fpath = \"/path/to/test.txt\"\n file_data = FileMetadata({\"key\": fname})\n\n # Create the file and add it to the draft using a stream\n draft.files.create(file_data)\n stream = open(fpath, \"rb\")\n f.set_contents(OutgoingStream(data=stream))\n f.commit()\n\n # It also supports the addition of multiple files from disk\n _dir = \"/path/to/dir\"\n file_data = FilesListMetadata([{\"key\": fname} for fname in os.listdir(_dir)])\n draft.files.create(file_data)\n for f in draft.files:\n file_path = os.path.join(_dir, f.data['key'])\n stream = open(file_path, \"rb\")\n f.set_contents(OutgoingStream(data=stream))\n f.commit()\n\n\nFinally, the draft can be published:\n\n.. code-block:: python\n\n # Publish the draft and check the status\n record = draft.publish()\n print(record.data[\"status\"])\n\n..\n Copyright (C) 2024 CERN.\n\n inveniordm-py is free software; you can redistribute it and/or modify\n it under the terms of the MIT License; see LICENSE file for more details.\n\nChanges\n=======\n\nVersion 0.1.1 (released 2024-07-14)\n\n- installation: remove `invenio-i18n` dependency\n\nVersion 0.1.0 (released 2024-05-13)\n\n- Initial public alpha release.\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "\"Invenio REST API client.\"",
"version": "0.1.1",
"project_urls": {
"Homepage": "https://github.com/inveniosoftware/inveniordm-py"
},
"split_keywords": [
"invenio",
"rest",
"api"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "38774fd894baeaf59795f8a79723098b9199d5007a35eeb6099953ebf22c51f7",
"md5": "7972c061d09c06f75c5d074a1e28030f",
"sha256": "c9c0ebc6dc65953ca326e2162ed452abd1c4def57ef45d93b47205a45b2f0e91"
},
"downloads": -1,
"filename": "inveniordm_py-0.1.1-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "7972c061d09c06f75c5d074a1e28030f",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": ">=3.7",
"size": 19998,
"upload_time": "2024-07-14T10:27:51",
"upload_time_iso_8601": "2024-07-14T10:27:51.768509Z",
"url": "https://files.pythonhosted.org/packages/38/77/4fd894baeaf59795f8a79723098b9199d5007a35eeb6099953ebf22c51f7/inveniordm_py-0.1.1-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3601bf0787c40c62d64d32d3b484572d42f218c06417109629a00f930325e351",
"md5": "cb2aede03c7a1dd9e7a8bfbb21b9c978",
"sha256": "f1b61834c6a2236a6079bbc17926645b924ba493279d901ceb8bcf6d53091c95"
},
"downloads": -1,
"filename": "inveniordm-py-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "cb2aede03c7a1dd9e7a8bfbb21b9c978",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 22850,
"upload_time": "2024-07-14T10:27:53",
"upload_time_iso_8601": "2024-07-14T10:27:53.190619Z",
"url": "https://files.pythonhosted.org/packages/36/01/bf0787c40c62d64d32d3b484572d42f218c06417109629a00f930325e351/inveniordm-py-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-14 10:27:53",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "inveniosoftware",
"github_project": "inveniordm-py",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "inveniordm-py"
}