Skip to main content

Python wrapper for Zenodo REST API

Project description

Quality Gate StatusDOI

Pynodo -- manage your Zenodo depositions

Python wrapper for Zenodo REST API for working with Zenodo depositions and files.

Installation

pip install pynodo

Usage

Zenodo access token with write scope is necessary to access depositions and files. Separate token is neccessary for zenodo sandbox environment. Sandbox can be switched by setting sandbox=True when initiating pynodo instance.

  • Depositions can be accessed using pynodo.Depositions class.

  • Files in a deposition can be accessed using pynodo.DepositionFiles class.

  • Depositions.create and DepositionFiles.files return namedtuple and list of namedtuples, respectively. Other functions return either json response or status code (delete).

  • Actions (e.g. publish, new version, edit) are not implemented.

Working with Depositions

pynodo allows listing, creating, retrieving, updating and deleting of depostions.

  • Create zenodo (sandbox) instance
import pynodo
import os

zen = pynodo.Depositions(access_token=os.environ["ZENODO_SANDBOX_PAT"], sandbox=True)
  • List user depositions
depos = zen.list(params={"size": 50})
  • Create a new deposition with some metadata
data = {
    "metadata": {
        "title": "My first upload",
        "upload_type": "poster",
        "description": "This is my first upload",
        "creators": [{"name": "Päll, Taavi", "affiliation": "UT"}],
    }
}
new_depo = zen.create(data=data)
  • Retrieve deposition info
ret_depo = zen.retrieve(deposition=new_depo.id)
  • Update deposition metadata
updates = {
    "metadata": {
        "title": "Modified upload",
        "upload_type": "dataset",
        "description": "This is updated upload",
        "creators": [
            {"name": "Päll, Taavi", "affiliation": "UT"},
            {"name": "Sus, Scrofa", "affiliation": "Mets"},
        ],
    }
}
updated_depo = zen.update(deposition=new_depo.id, data=updates)
  • Delete deposition (status code 204 shows success)
zen.delete(new_depo.id)

Working with DepositionFiles

pynodo allows listing, uploading, downloading and deleting of files in a deposition.

  • Create zenodo (sandbox) instance
import pynodo
import os
zen = pynodo.Depositions(access_token=os.environ["ZENODO_SANDBOX_PAT"], sandbox=True)
  • Create new deposition
new_depo = zen.create()
  • Retrive deposition
ret_depo = zen.retrieve(deposition=new_depo.id)
  • Create new instance for listing files
zen_files = pynodo.DepositionFiles(
    deposition=new_depo.id,
    access_token=os.environ["ZENODO_SANDBOX_PAT"],
    sandbox=True,
)
  • Upload file (second argument with new file name is optional)
zen_files.upload("tests/upload.txt", "uploaded_file.txt")
  • List files in deposition
files = zen_files.files
  • Download file from deposition (second argument with download folder is optional)
zen_files.download("uploaded_file.txt", "tmp")
  • Delete file (status code 204 shows success)
zen_files.delete("uploaded_file.txt")

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

pynodo-0.2.2.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

pynodo-0.2.2-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file pynodo-0.2.2.tar.gz.

File metadata

  • Download URL: pynodo-0.2.2.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for pynodo-0.2.2.tar.gz
Algorithm Hash digest
SHA256 76c75e824f570edad803272c25a11192c8b8189a575885b53bf4fe162798e655
MD5 a414ec20e2f04d2a2d0560789dba6720
BLAKE2b-256 8215f1771c6854b60473ea3e10ffb17ccfe45d13056552f2a65c829ed58c82a7

See more details on using hashes here.

File details

Details for the file pynodo-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: pynodo-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for pynodo-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 345982ab3c3265757dbe15989f8d6f77fe4b6fa12ec4b8376411bcc173289af6
MD5 5f37d1cca7c4402c382885cb6d39c8f7
BLAKE2b-256 cde6ac0062c7fda3d68bf4febfa2ffb2c0c42b40582abdda1e7cd2ddcc72b132

See more details on using hashes here.

Supported by

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