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.

Files for pynodo, version 0.2.2
Filename, size File type Python version Upload date Hashes
Filename, size pynodo-0.2.2-py3-none-any.whl (7.0 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size pynodo-0.2.2.tar.gz (4.5 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page