https://github.com/tpall/pynodo
Python wrapper for Zenodo REST API
https://github.com/tpall/pynodo
python wrapper-api zenodo
Last synced: 4 months ago
JSON representation
Python wrapper for Zenodo REST API
- Host: GitHub
- URL: https://github.com/tpall/pynodo
- Owner: tpall
- License: mit
- Created: 2020-01-03T12:52:48.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-05-22T22:37:10.000Z (about 3 years ago)
- Last Synced: 2025-08-29T05:53:58.843Z (10 months ago)
- Topics: python, wrapper-api, zenodo
- Language: Python
- Homepage:
- Size: 58.6 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://sonarcloud.io/dashboard?id=tpall_zenapi)[](https://zenodo.org/badge/latestdoi/231588382)
# Pynodo -- manage your Zenodo depositions
Python wrapper for Zenodo REST API for working with Zenodo depositions and files.
## Installation
```python
pip install pynodo
```
## Usage
[Zenodo](https://zenodo.org) access token with write scope is necessary to access depositions and files.
Separate token is neccessary for [zenodo sandbox](https://sandbox.zenodo.org) 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
```python
import pynodo
import os
zen = pynodo.Depositions(access_token=os.environ["ZENODO_SANDBOX_PAT"], sandbox=True)
```
- List user depositions
```python
depos = zen.list(params={"size": 50})
```
- Create a new deposition with some metadata
```python
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
```python
ret_depo = zen.retrieve(deposition=new_depo.id)
```
- Update deposition metadata
```python
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)
```python
zen.delete(new_depo.id)
```
### Working with DepositionFiles
pynodo allows listing, uploading, downloading and deleting of files in a deposition.
- Create zenodo (sandbox) instance
```python
import pynodo
import os
zen = pynodo.Depositions(access_token=os.environ["ZENODO_SANDBOX_PAT"], sandbox=True)
```
- Create new deposition
```python
new_depo = zen.create()
```
- Retrive deposition
```python
ret_depo = zen.retrieve(deposition=new_depo.id)
```
- Create new instance for listing files
```python
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)
```python
zen_files.upload("tests/upload.txt", "uploaded_file.txt")
```
- List files in deposition
```python
files = zen_files.files
```
- Download file from deposition (second argument with download folder is optional)
```python
zen_files.download("uploaded_file.txt", "tmp")
```
- Delete file (status code 204 shows success)
```python
zen_files.delete("uploaded_file.txt")
```