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.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 69.7 MB
Release files / datahugger_ng-0.6.7-cp310-abi3-win_amd64.whl
| Download URL | datahugger_ng-0.6.7-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 3.9 MB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
b6b9e24796d3e595ee6a20ce0c4ec5031eacf346e76f5f173cd5faf9a8705e55
|
|
BLAKE2b-256 checksum How to use checksums |
3524a1c56b0e6d42a29268e332d94d747606d7ebfff827eb3b1d1a117624bacb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / datahugger_ng-0.6.7-cp310-abi3-musllinux_1_2_x86_64.whl
| Download URL | datahugger_ng-0.6.7-cp310-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 7.4 MB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
b3ad990891ef05d4b71c776abb917810358d34505ee7d66f3d304a5fa59ef9f0
|
|
BLAKE2b-256 checksum How to use checksums |
eca3534e3de82f78bdc0aff49905e3d4fc8b931f3eafbdedd0ae4b24f4100d36
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / datahugger_ng-0.6.7-cp310-abi3-musllinux_1_2_i686.whl
| Download URL | datahugger_ng-0.6.7-cp310-abi3-musllinux_1_2_i686.whl |
|---|---|
| Size | 6.9 MB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
cce17d8cedd58807cbef1a7b56350b115811842a6ee7f4a2ef71c3f74b5ddd28
|
|
BLAKE2b-256 checksum How to use checksums |
4b3c28451ca27fec6f9a421aa7560c4544286e07a9a571ad5ead3d1c0aa970cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / datahugger_ng-0.6.7-cp310-abi3-musllinux_1_2_armv7l.whl
| Download URL | datahugger_ng-0.6.7-cp310-abi3-musllinux_1_2_armv7l.whl |
|---|---|
| Size | 6.3 MB |
| Tags | CPython 3.10 Linux musl 1.2+ ARMv7l abi3 |
|
SHA-256 checksum How to use checksums |
82d4e0a2a65033764dc8d6857fc3780b012e93c6322955f1863a46a93e9f2d11
|
|
BLAKE2b-256 checksum How to use checksums |
17b3bfdeb14cf79f762a9a6a0457c143fae05518ea0fc58f0a658a9358ac09de
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / datahugger_ng-0.6.7-cp310-abi3-musllinux_1_2_aarch64.whl
| Download URL | datahugger_ng-0.6.7-cp310-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 7.5 MB |
| Tags | CPython 3.10 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
eef2de577a4ab564b2dc9cad97be64595dfa9b772ef2ae83af18944a8754951a
|
|
BLAKE2b-256 checksum How to use checksums |
0264295cbf00c0361c54a7438c722a1e3a300268ac59fc1f27014aa4a0bb3c2d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / datahugger_ng-0.6.7-cp310-abi3-manylinux_2_28_x86_64.whl
| Download URL | datahugger_ng-0.6.7-cp310-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 6.5 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
d201d28982c2c0980b066a368450766d131ce39ade52c26a01daf07728c82767
|
|
BLAKE2b-256 checksum How to use checksums |
276837eb4fd618b827975f99babfd4b7694e5d1f5aa2b5b9bb8f0df3025860a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / datahugger_ng-0.6.7-cp310-abi3-manylinux_2_28_ppc64le.whl
| Download URL | datahugger_ng-0.6.7-cp310-abi3-manylinux_2_28_ppc64le.whl |
|---|---|
| Size | 7.3 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ PowerPC 64-le abi3 |
|
SHA-256 checksum How to use checksums |
8aa71f6824f5fbd5896ab6a3196943df9e8d215b53ac37d48f32f6da7cab40f6
|
|
BLAKE2b-256 checksum How to use checksums |
7de2d6e539057060232da9701c77f3f804cc091278cadd7f53ea87d3bdd163a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / datahugger_ng-0.6.7-cp310-abi3-manylinux_2_28_i686.whl
| Download URL | datahugger_ng-0.6.7-cp310-abi3-manylinux_2_28_i686.whl |
|---|---|
| Size | 6.4 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
69eea0ac2b4f69437bc9467b264503ebdf01f8e403ba023bd3529d6a613c7173
|
|
BLAKE2b-256 checksum How to use checksums |
7ad9a3466c108d88c1b65fd4aee4d0cb3dc3f99fcaa7cb9c60d2daa8172cb242
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / datahugger_ng-0.6.7-cp310-abi3-manylinux_2_28_armv7l.whl
| Download URL | datahugger_ng-0.6.7-cp310-abi3-manylinux_2_28_armv7l.whl |
|---|---|
| Size | 6.1 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ ARMv7l abi3 |
|
SHA-256 checksum How to use checksums |
3388be0d3dbce91f90ea7deca6d02faafaba39d3f4cdce5bca3a87fd35bd097b
|
|
BLAKE2b-256 checksum How to use checksums |
a9885feb56b682d3a90810498605b1913666dc24912aeba2d9c2215638778585
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / datahugger_ng-0.6.7-cp310-abi3-manylinux_2_28_aarch64.whl
| Download URL | datahugger_ng-0.6.7-cp310-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 7.2 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
c43222174151f9dad8bc9d639d9a87de4d35e401fb10bb57be374af3c9678c3e
|
|
BLAKE2b-256 checksum How to use checksums |
d68be779a70d39e4d70b55084063e7e03844c0c6282f89659690ef9b35a29985
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / datahugger_ng-0.6.7-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | datahugger_ng-0.6.7-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 |
e2088a9db8d43e02de0342347a1a1bb9e3310b2e7ecf0ac5a31fc0b827113a78
|
|
BLAKE2b-256 checksum How to use checksums |
0dfcab27ca581b52975757abb3f972806e9532167f4a7d75a5380cb1009f0a35
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|