asteroid.models.zenodo module

class asteroid.models.zenodo.Zenodo(api_key=None, use_sandbox=True)[source]

Bases: object

Faciliate Zenodo’s REST API.

Parameters:
  • api_key (str) – Access token generated to upload depositions.
  • use_sandbox (bool) – Whether to use the sandbox (default: True) Note that api_key are different in sandbox.
Methods (all methods return the requests response):
create_new_deposition change_metadata_in_deposition, upload_new_file_to_deposition publish_deposition get_deposition remove_deposition remove_all_depositions

Note

A Zenodo record is something that is public and cannot be deleted. A Zenodo deposit has not yet been published, is private and can be deleted.

change_metadata_in_deposition(dep_id, metadata)[source]

Set or replace metadata in given deposition

Parameters:
  • dep_id (int) – deposition id. You cna get it with r = create_new_deposition(); dep_id = r.json()[‘id’]
  • metadata (dict) – Metadata dict.

Examples

metadata = {

‘title’: ‘My first upload’, ‘upload_type’: ‘poster’, ‘description’: ‘This is my first upload’, ‘creators’: [{‘name’: ‘Doe, John’,

‘affiliation’: ‘Zenodo’}]

}

create_new_deposition(metadata=None)[source]

Creates a new deposition.

Parameters:metadata (dict, optional) – Metadata dict to upload on the new deposition.
get_deposition(dep_id=-1)[source]

Get deposition by deposition id. Get all dep_id is -1 (default).

publish_deposition(dep_id)[source]

Publish given deposition (Cannot be deleted)!

Parameters:dep_id (int) – deposition id. You cna get it with r = create_new_deposition(); dep_id = r.json()[‘id’]
remove_all_depositions()[source]

Removes all unpublished deposition (not records).

remove_deposition(dep_id)[source]

Remove deposition with deposition id dep_id

upload_new_file_to_deposition(dep_id, file, name=None)[source]

Upload one file to existing deposition. :param dep_id: deposition id. You cna get it with

r = create_new_deposition(); dep_id = r.json()[‘id’]
Parameters:
  • file (str or io.BufferedReader) – path to a file, or already opened file (path prefered).
  • name (str, optional) – name given to the uploaded file. Defaults to the path.

(More: https://developers.zenodo.org/#deposition-files)