openairclim.utils.download_zenodo
Download files from a Zenodo record using the requests library.
- openairclim.utils.download_zenodo.CHUNK_SIZE = 1048576
Chunk size (bytes) used when streaming file downloads.
- openairclim.utils.download_zenodo.REQUEST_TIMEOUT = 30
Timeout (seconds) applied to every Zenodo API/download request.
- openairclim.utils.download_zenodo.download(record_or_doi: str, output_dir: str | Path, file_glob: str = '*', force: bool = False, max_attempts: int = 3, backoff_seconds: float = 5.0) None[source]
Download files from a Zenodo record matching file_glob into output_dir, skipping any file that already exists and passes checksum verification.
- Raises:
ValueError – if no record ID can be found in record_or_doi
RuntimeError – if a downloaded file’s checksum doesn’t match the Zenodo record’s metadata
- openairclim.utils.download_zenodo.download_file(url: str, dest: str | Path, max_attempts: int = 3, backoff_seconds: float = 5.0) None[source]
Stream a single file from url to dest, retrying on transient errors.
- Parameters:
- Raises:
requests.HTTPError – if the request does not succeed.
requests.exceptions.RequestException – if all attempts fail.
- openairclim.utils.download_zenodo.fetch_json(url: str, max_attempts: int = 3, backoff_seconds: float = 5.0) dict[source]
Fetch and parse JSON from a URL, retrying on transient errors.
- Parameters:
- Returns:
The parsed JSON response.
- Return type:
- Raises:
requests.HTTPError – if the request does not succeed.
ValueError – if max_attempts is less than 1.
- openairclim.utils.download_zenodo.fetch_record_json(record_or_doi: str) dict[source]
Fetch a Zenodo record’s metadata.
- openairclim.utils.download_zenodo.fetch_record_versions(record_or_doi: str) list[dict][source]
Fetch every published version of a Zenodo concept record.
- openairclim.utils.download_zenodo.main()[source]
Parse command-line arguments and download the matching files
- openairclim.utils.download_zenodo.verify_checksum(path: str | Path, expected: str) bool[source]
Verify a local file’s checksum against a Zenodo-format checksum string.
- Parameters:
path (str or Path) – Path to the local file.
expected (str) – Checksum in Zenodo’s “<algorithm>:<hexdigest>” format, e.g. “md5:1234…” - see https://developers.zenodo.org/
- Returns:
- True if the file exists and its checksum matches, False
otherwise.
- Return type: