inveniordm-py


Nameinveniordm-py JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/inveniosoftware/inveniordm-py
Summary"Invenio REST API client."
upload_time2024-05-13 12:29:58
maintainerNone
docs_urlNone
authorCERN
requires_python>=3.7
licenseMIT
keywords invenio rest api
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ..
    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.0 (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/a6/92/c622e3130af8ca6cbe539cb1b039dccb087f0ae90eaa5f5c87da0214c316/inveniordm-py-0.1.0.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.0 (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.0",
    "project_urls": {
        "Homepage": "https://github.com/inveniosoftware/inveniordm-py"
    },
    "split_keywords": [
        "invenio",
        "rest",
        "api"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d3f01948225d377b26366aa5f992dd762c06eb0cb9c32f91f4ec16edd10c4085",
                "md5": "b25438312c01b2464ab03f9ec9091e5c",
                "sha256": "03d3ba787d436c084452dda05f1f0c93aeb455bdf2f81c2da8b2c8d1582386bd"
            },
            "downloads": -1,
            "filename": "inveniordm_py-0.1.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b25438312c01b2464ab03f9ec9091e5c",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.7",
            "size": 19968,
            "upload_time": "2024-05-13T12:29:57",
            "upload_time_iso_8601": "2024-05-13T12:29:57.582682Z",
            "url": "https://files.pythonhosted.org/packages/d3/f0/1948225d377b26366aa5f992dd762c06eb0cb9c32f91f4ec16edd10c4085/inveniordm_py-0.1.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a692c622e3130af8ca6cbe539cb1b039dccb087f0ae90eaa5f5c87da0214c316",
                "md5": "5b2b8ea8792cb31e9243f579e234542b",
                "sha256": "50c0d4440c36a80442d02961da7ae1744c4ed598915bd1732b08086995901b4b"
            },
            "downloads": -1,
            "filename": "inveniordm-py-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "5b2b8ea8792cb31e9243f579e234542b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 22785,
            "upload_time": "2024-05-13T12:29:58",
            "upload_time_iso_8601": "2024-05-13T12:29:58.914192Z",
            "url": "https://files.pythonhosted.org/packages/a6/92/c622e3130af8ca6cbe539cb1b039dccb087f0ae90eaa5f5c87da0214c316/inveniordm-py-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-13 12:29:58",
    "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"
}
        
Elapsed time: 0.23512s