Datahugger API doc
This module provides a unified interface to resolve, crawl, and download datasets exposed over HTTP-like endpoints. A key design goal is that dataset crawling can be consumed both synchronously and asynchronously using the same API.
Overview
- Resolve a dataset from a URL
- Crawl its contents as a stream of entries (files or directories)
- Download and validate dataset contents using a blocking API backed by an async runtime
DOIResolver
Resolves Digital Object Identifiers (DOIs) to their target URLs using the DOI resolution service (e.g. https://doi.org/<doi>).
from datahugger import DOIResolver
doi_resolver = DOIResolver(timeout=30)
url = doi_resolver.resolve("10.34894/0B7ZLK", False)
assert url == "https://dataverse.nl/citation?persistentId=doi:10.34894/0B7ZLK"
# or for multiple resolving in one call
urls = doi_resolver.resolve_many(
["10.34894/0B7ZLK", "10.17026/DANS-2AC-ETD6", "10.17026/DANS-2BA-UAVX"], False
)
Parameters
-
doior list ofdoiinresolve_manyThe DOI to resolve (e.g."10.1000/xyz123"). Thehttps://doi.org/prefix should not be included. -
follow_redirectsWhether HTTP redirects should be followed.True: Returns the final landing page URL (default).False: Returns the first redirect target.
Core Concepts
DirEntry
Represents a directory in the dataset.
@dataclass
class DirEntry(Entry):
path_crawl_rel: pathlib.Path
root_url: str
api_url: str
Fields
-
path_crawl_relPath of the directory relative to the dataset root. -
root_urlRoot URL of the dataset this directory belongs to. -
api_urlAPI endpoint used to query the directory contents.
FileEntry
Represents a file in the dataset.
@dataclass
class FileEntry(Entry):
path_crawl_rel: pathlib.Path
download_url: str
size: int | None
checksum: list[tuple[str, str]]
TODO <- here the mimetype will be added.
Fields
-
path_crawl_relPath of the file relative to the dataset root. -
download_urlURL from which the file can be downloaded. -
sizeFile size in bytes, if known. -
checksumList of checksum pairs(algorithm, value)(e.g.("sha256", "...")).
ZipEntry
Represents a ZIP archive entry in the dataset.
A ZipEntry is a container object that describes a downloadable archive file and the files contained within it.
@dataclass
class ZipEntry(Entry):
download_url: str
size: int | None
checksum: list[tuple[str, str]]
version: str | None
creation_date: str | None
last_modification_date: str | None
files: list[FileInZipEntry]
Fields
-
download_urlURL from which the ZIP archive can be downloaded. -
sizeSize of the ZIP archive in bytes, if known. -
checksumList of checksum pairs(algorithm, value)(e.g.("sha256", "...")) used to verify archive integrity. -
versionOptional version identifier of the archive. -
creation_dateOptional creation timestamp of the archive. -
last_modification_dateOptional last modification timestamp of the archive. -
filesList of files contained inside the ZIP archive. Each entry describes a file within the archive (path, size, checksum, and optional metadata such as mimetype).
Iteration Model
SyncAsyncIterator[T]
A protocol that allows a single object to be used as both a synchronous and an asynchronous iterator.
class SyncAsyncIterator(Protocol[T]):
def __aiter__(self) -> AsyncIterator[T]: ...
async def __anext__(self) -> T: ...
def __iter__(self) -> Iterator[T]: ...
def __next__(self) -> T: ...
This enables APIs that can be consumed in either context without duplication.
Dataset
The central abstraction representing a remote dataset.
class Dataset:
def crawl(self) -> SyncAsyncIterator[FileEntry | DirEntry | ZipEntry]: ...
def crawl_file(self) -> SyncAsyncIterator[FileEntry]: ...
def download_with_validation(
self, dst_dir: pathlib.Path, limit: int = 0, includes = None, excludes = None,
) -> int: ...
def id(self) -> str: ...
def root_url(self) -> str: ...
Dataset.crawl()
def crawl(self) -> SyncAsyncIterator[FileEntry | DirEntry | ZipEntry]
Returns a stream of dataset entries (optional type that can be either DirEntry or FileEntry).
The returned object supports both:
Synchronous iteration
for entry in dataset.crawl():
print(entry)
Asynchronous iteration
async for entry in dataset.crawl():
print(entry)
Entries are yielded as either DirEntry or FileEntry.
Dataset.download_with_validation()
def download_with_validation(
self, dst_dir: pathlib.Path, limit: int = 0, includes = None, excludes = None,
) -> int
Downloads files in the dataset into the given directory and validates them using the provided checksums.
- This is a blocking call.
- Internally backed by a Rust async runtime.
- Intended for use from synchronous Python code.
Parameters
-
dst_dirDestination directory for downloaded files. -
limitMaximum number of files to download.0means no limit.
Dataset.root_url()
def root_url(self) -> str
Returns the dataset’s root URL.
Resolving a Dataset
resolve
def resolve(url: str, /) -> Dataset
Resolves a dataset from a given URL.
Example
dataset = resolve("https://example.com/dataset")
The returned Dataset can then be crawled or downloaded.
Example Usage
Crawl a dataset synchronously
dataset = resolve("https://example.com/dataset")
for entry in dataset.crawl():
if isinstance(entry, FileEntry):
print("File:", entry.path_crawl_rel)
elif isinstance(entry, DirEntry):
print("Dir:", entry.path_crawl_rel)
elif isinstance(entry, ZipEntry):
print("Zip:", entry)
Crawl a dataset asynchronously
dataset = resolve("https://example.com/dataset")
async for entry in dataset.crawl():
print(entry)
Download a dataset
dataset = resolve("https://example.com/dataset")
dataset.download_with_validation(dst_dir=pathlib.Path("./data"))
Metadata
Release files for datahugger-ng 0.6.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 67.8 MB
Release files / datahugger_ng-0.6.6-cp310-abi3-win_amd64.whl
| Download URL | datahugger_ng-0.6.6-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 3.7 MB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
814d7cc1ff9ccee805380e6914dc127b5671bc7ec935e5cd8b2782c9242fb938
|
|
BLAKE2b-256 checksum How to use checksums |
d6cad71a0a6cdda05a09107383272fee27558f360eb488737e74dea8fa7c9a8b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / datahugger_ng-0.6.6-cp310-abi3-musllinux_1_2_x86_64.whl
| Download URL | datahugger_ng-0.6.6-cp310-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 7.2 MB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
ae71a71d6d994b3c0cddd7964f96cd725c8218e892c5cbf3029d91a2cb1ff532
|
|
BLAKE2b-256 checksum How to use checksums |
c57a21f65c59bc4b8829166c5fd1d2bb9be86ab46d28a46022b331748489f209
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / datahugger_ng-0.6.6-cp310-abi3-musllinux_1_2_i686.whl
| Download URL | datahugger_ng-0.6.6-cp310-abi3-musllinux_1_2_i686.whl |
|---|---|
| Size | 6.7 MB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
47fdec70b6cbc49c7ea9b9b3004f178b110f87bd3357842dab0c42198c8bdb38
|
|
BLAKE2b-256 checksum How to use checksums |
60a2288778783456a8cb8894a22863f20fffa03b373c094a589bfbecef727c5b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / datahugger_ng-0.6.6-cp310-abi3-musllinux_1_2_armv7l.whl
| Download URL | datahugger_ng-0.6.6-cp310-abi3-musllinux_1_2_armv7l.whl |
|---|---|
| Size | 6.1 MB |
| Tags | CPython 3.10 Linux musl 1.2+ ARMv7l abi3 |
|
SHA-256 checksum How to use checksums |
740e3426b88031ce4e9275d13bc5ee02f8d220a1a6c3165a455867026e08f19f
|
|
BLAKE2b-256 checksum How to use checksums |
032cc45480fdc2e58d1da83d478e7c7383c992e3c539e5ae66e7671eb64bbbd9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / datahugger_ng-0.6.6-cp310-abi3-musllinux_1_2_aarch64.whl
| Download URL | datahugger_ng-0.6.6-cp310-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 7.3 MB |
| Tags | CPython 3.10 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
3a07aed10198eb668b75674dc07221267b814e41c39933c1e21bdef6d8d4c81c
|
|
BLAKE2b-256 checksum How to use checksums |
39668f0f8092adb5c4b747419c079e26fcacb894e0e2a48430e4064011eadd95
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / datahugger_ng-0.6.6-cp310-abi3-manylinux_2_28_x86_64.whl
| Download URL | datahugger_ng-0.6.6-cp310-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 6.3 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
e3902496ce9ebfc84df148692a2bc62dbb8ebeb9393e6ea4bfb5a243b9d7815a
|
|
BLAKE2b-256 checksum How to use checksums |
778201ac4af43958262fe749fa2917bb0493ae5ace4f5b0944ef797ac40bf4c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / datahugger_ng-0.6.6-cp310-abi3-manylinux_2_28_ppc64le.whl
| Download URL | datahugger_ng-0.6.6-cp310-abi3-manylinux_2_28_ppc64le.whl |
|---|---|
| Size | 7.1 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ PowerPC 64-le abi3 |
|
SHA-256 checksum How to use checksums |
76ce3adf70d2ddb865a2ee82c53230b0304ac70bb4a702cb32eba1f085dc252e
|
|
BLAKE2b-256 checksum How to use checksums |
d26996e95f17fc6d3e27fe4c6e2406dc5f5bace8b22cb95f4a96e6f668c2b1cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / datahugger_ng-0.6.6-cp310-abi3-manylinux_2_28_i686.whl
| Download URL | datahugger_ng-0.6.6-cp310-abi3-manylinux_2_28_i686.whl |
|---|---|
| Size | 6.2 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
c2bb70b01d0a2313d68748cbe12b18ab4b3dd18241b938365e8ca7c76fb15077
|
|
BLAKE2b-256 checksum How to use checksums |
cff766f8d402a103f9ee4206d89123780be657d6853f065b3fd578705b08888a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / datahugger_ng-0.6.6-cp310-abi3-manylinux_2_28_armv7l.whl
| Download URL | datahugger_ng-0.6.6-cp310-abi3-manylinux_2_28_armv7l.whl |
|---|---|
| Size | 5.9 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ ARMv7l abi3 |
|
SHA-256 checksum How to use checksums |
87b85af06ff2d0cb19914469afb6c3b7262b702a829e1f1e316cebc5d073c8a8
|
|
BLAKE2b-256 checksum How to use checksums |
be1128209e453a67a098017dee978880ff017599216367883ed9df1a11e0801f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / datahugger_ng-0.6.6-cp310-abi3-manylinux_2_28_aarch64.whl
| Download URL | datahugger_ng-0.6.6-cp310-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 7.0 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
1ccc6c4c373066e4d1eebab82456abb7d40a4cbd57f5fe13da920b4b5ce840a8
|
|
BLAKE2b-256 checksum How to use checksums |
c81e2e2306a37fd262437474c364c599fe5efe602b8a8bce316de08845561154
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / datahugger_ng-0.6.6-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | datahugger_ng-0.6.6-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 4.3 MB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
24bcd161d131f31f3e3eb91eae6fe0358a4726474abf9f52e69299b2bbfc268e
|
|
BLAKE2b-256 checksum How to use checksums |
7bb4822374c0898b2ff982f1bfca26003aabee6e4c8135242a6e3d571d04a19e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|