transport_data.util.pooch.ZenodoRepository

class transport_data.util.pooch.ZenodoRepository(doi, archive_url)[source]

Bases: ZenodoRepository

Custom version of pooch.downloaders.ZenodoRepository.

__init__(doi, archive_url)

Methods

__init__(doi, archive_url)

download_url(file_name)

Use the repository API to get the download URL for a file given the archive URL.

get_headers()

Return a set of HTTP headers including the Zenodo API token, if any.

initialize(doi, archive_url)

Initialize the data repository if the given URL points to a corresponding repository.

populate_registry(pooch)

Populate the registry using the data repository's API

Attributes

api_response

Cached API response from Zenodo.

api_version

Version of the Zenodo API we are interacting with

base_api_url

property api_response

Cached API response from Zenodo.

This version differs from the upstream version:

  1. The record ID for the Zenodo API is constructed without the “zenodo.” prefix.

  2. A keyring secret with ID api-token-zenodo, if any, is used for the HTTP “Authorization” header.

  3. The request is retried with increasing delays until it succeeds.

property api_version

Version of the Zenodo API we are interacting with

The versions can either be :

  • "legacy": corresponds to the Zenodo API that was supported until 2023-10-12 (before the migration to InvenioRDM).

  • "new": corresponds to the new API that went online on 2023-10-13 after the migration to InvenioRDM.

The "new" API breaks backward compatibility with the "legacy" one and could probably be replaced by an updated version that restores the behaviour of the "legacy" one.

Return type:

str

download_url(file_name)

Use the repository API to get the download URL for a file given the archive URL.

Parameters:

file_name (str) – The name of the file in the archive that will be downloaded.

Returns:

download_url – The HTTP URL that can be used to download the file.

Return type:

str

Notes

After Zenodo migrated to InvenioRDM on Oct 2023, their API changed. The link to the desired files that appears in the API response leads to 404 errors (by 2023-10-17). The files are available in the following url: https://zenodo.org/records/{article_id}/files/{file_name}?download=1.

This method supports both the legacy and the new API.

classmethod get_headers() dict[str, str]

Return a set of HTTP headers including the Zenodo API token, if any.

classmethod initialize(doi, archive_url)

Initialize the data repository if the given URL points to a corresponding repository.

Initializes a data repository object. This is done as part of a chain of responsibility. If the class cannot handle the given repository URL, it returns None. Otherwise a DataRepository instance is returned.

Parameters:
  • doi (str) – The DOI that identifies the repository

  • archive_url (str) – The resolved URL for the DOI

populate_registry(pooch)

Populate the registry using the data repository’s API

Parameters:

pooch (Pooch) – The pooch instance that the registry will be added to.

Notes

After Zenodo migrated to InvenioRDM on Oct 2023, their API changed. The checksums for each file listed in the API reference is now an md5 sum.

This method supports both the legacy and the new API.