Skip to content

RemyLau/py2zenodo

Repository files navigation

PyPI version Code style: black Imports: isort

py2zenodo

A Python wrapper for Zenodo REST API

Installation

We use Poetry to manage this package. Run the following command at the project root directory to install py2zenodo.

poetry install

Then, you can activate the interactive shell environment by

poetry shell

Use cases

Uploading files

Using the CLI

Upload a single file to Zenodo (to be published).

py2zenodo <path_to_file> --token <your_zenodo_api_token>

Upload multiple files to Zenodo sandbox (to be published).

py2zenodo <path_to_file1> <path_to_file2> --token <your_zenodo_sandbox_api_token> --sandbox

Using the API

from py2zenodo import Deposition

# Initialize a deposition for Zenodo sandbox using token information
depo = Deposition(access_token=your_token, sandbox=True)

# Create a new deposition and upload a file
depo.create_new_depo()
depo.upload_file(path_to_file)

Getting record information

For all examples below, we will use the Zenodo record 1145370 that was created for demonstration and testing purposes for py2zenodo.

Getting record information using the record identifier

from py2zenodo import Record

# Load information about a particular record given the record id
# Note: the sandbox option indicates that this is a sandbox record (https://sandbox.zenodo.org).
# For ordinary Zenodo record, set sandbox=False, or simply ignore this option.
rec = Record("1145370", sandbox=True)

# Print some key information about this record
print(rec.title)  # title of this record
print(rec.doi)  # doi of this record
print(rec.latest_link)  # link to the latest version of this record
print(rec.latest_recid)  # record id of the latest version of this record
print(rec.files)  # information about available files in this record

# Show all information associated with the record
print(rec.raw)  # alternatively, use `print(rec.show())` to print nicely formatted json

All available properties for Record:

  • conceptdoi
  • conceptrecid
  • doi
  • files
  • id
  • latest_link
  • latest_recid
  • links
  • metadata
  • title
  • raw

Querying records given a query string

from py2zenodo import Records

# Query records with a query string
recs = Record("py2zenodo", sandbox=True)

# Print information about the records obtained from the query
print(rec.titles)
print(rec.dois)

# Get a particular record by indexing
rec = recs[0]

All available properties for Records:

  • conceptdois
  • conceptrecids
  • dois
  • ids
  • records
  • titles

Getting all versions of a particular record

from py2zenodo import Record, Records

# Load a record
rec = Record("1145373")

# Load all versions of that record by using the concept record identifier
recs = Records(rec.conceptrecid)

About

A Python wrapper for Zenodo REST API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages