Giter VIP home page Giter VIP logo

pynodo's Introduction

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")

pynodo's People

Contributors

tpall avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.