Skip to main content

Datahugger API doc

Python version

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

  • doi or list of doi in resolve_many The DOI to resolve (e.g. "10.1000/xyz123"). The https://doi.org/ prefix should not be included.

  • follow_redirects Whether 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_rel Path of the directory relative to the dataset root.

  • root_url Root URL of the dataset this directory belongs to.

  • api_url API 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_rel Path of the file relative to the dataset root.

  • download_url URL from which the file can be downloaded.

  • size File size in bytes, if known.

  • checksum List 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_url URL from which the ZIP archive can be downloaded.

  • size Size of the ZIP archive in bytes, if known.

  • checksum List of checksum pairs (algorithm, value) (e.g. ("sha256", "...")) used to verify archive integrity.

  • version Optional version identifier of the archive.

  • creation_date Optional creation timestamp of the archive.

  • last_modification_date Optional last modification timestamp of the archive.

  • files List 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_dir Destination directory for downloaded files.

  • limit Maximum number of files to download. 0 means 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.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for datahugger-ng 0.6.8
File
datahugger_ng-0.6.8-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
datahugger_ng-0.6.8-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details
datahugger_ng-0.6.8-cp310-abi3-musllinux_1_2_i686.whl CPython 3.10 abi3 Linux musl 1.2+ x86-32 Details
datahugger_ng-0.6.8-cp310-abi3-musllinux_1_2_armv7l.whl CPython 3.10 abi3 Linux musl 1.2+ ARMv7l Details
datahugger_ng-0.6.8-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details
datahugger_ng-0.6.8-cp310-abi3-manylinux_2_28_x86_64.whl CPython 3.10 abi3 Linux glibc 2.28+ x86-64 Details
datahugger_ng-0.6.8-cp310-abi3-manylinux_2_28_ppc64le.whl CPython 3.10 abi3 Linux glibc 2.28+ PowerPC 64-le Details
datahugger_ng-0.6.8-cp310-abi3-manylinux_2_28_i686.whl CPython 3.10 abi3 Linux glibc 2.28+ x86-32 Details
datahugger_ng-0.6.8-cp310-abi3-manylinux_2_28_armv7l.whl CPython 3.10 abi3 Linux glibc 2.28+ ARMv7l Details
datahugger_ng-0.6.8-cp310-abi3-manylinux_2_28_aarch64.whl CPython 3.10 abi3 Linux glibc 2.28+ ARM64 Details
datahugger_ng-0.6.8-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details

Total release size: 70.0 MB

Release files / datahugger_ng-0.6.8-cp310-abi3-win_amd64.whl

Download URL datahugger_ng-0.6.8-cp310-abi3-win_amd64.whl
Size 3.9 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
d296a965ebe94af78a4598c16e2e64b19bc13767d04478648dd8bf8a5db3b122
BLAKE2b-256 checksum
How to use checksums
f9f3f2a5b94582695a21e5f9d9f9adbdb6f24e2737b97aaf834950f8d557a110
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / datahugger_ng-0.6.8-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL datahugger_ng-0.6.8-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
efff2e99f7399902658f7b5132d7a3eefeaad6ddde9c8fe4f7cc39f49fb964f9
BLAKE2b-256 checksum
How to use checksums
f1440e708777dc328fe7127e7e0f549a921a33609d4e4ee3ae96fb58d6259e76
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / datahugger_ng-0.6.8-cp310-abi3-musllinux_1_2_i686.whl

Download URL datahugger_ng-0.6.8-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
8dbb357fce4a81e3e8cb42ec3786bfe828f424bd7754a72f56c6d922c70700e5
BLAKE2b-256 checksum
How to use checksums
be2a5b2cf41e9e247ecb6061d2e3c32d4d300339373c7356ed9d442be9170883
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / datahugger_ng-0.6.8-cp310-abi3-musllinux_1_2_armv7l.whl

Download URL datahugger_ng-0.6.8-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
b1012325161655ed6479979d3687434866fb77fadc0c01190cc8b9aa109db898
BLAKE2b-256 checksum
How to use checksums
8d36825a3b209e78d7f288e3b6a4d4f93585c404ce8bb26ff4492dcd502d7894
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / datahugger_ng-0.6.8-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL datahugger_ng-0.6.8-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
c8b98d64f1ae5c330c1e4fa22cd54385cdc3f35cfc6db6da4959924c38c1e831
BLAKE2b-256 checksum
How to use checksums
6737257b0fc4040da6c08c466efa4c136f867268724ec9ca58b22f23089aa913
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / datahugger_ng-0.6.8-cp310-abi3-manylinux_2_28_x86_64.whl

Download URL datahugger_ng-0.6.8-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
53b976ec64c1323c8d8f1683c3ab1a2c0090f6c779933d9045021048f8a2350a
BLAKE2b-256 checksum
How to use checksums
a0423950652863678d046a5600e07fe698e6fce6239a1a4fb12790f627c72672
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / datahugger_ng-0.6.8-cp310-abi3-manylinux_2_28_ppc64le.whl

Download URL datahugger_ng-0.6.8-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
95c2d532f6453217576755ec89d5f1184f7e8b7a0584ca889f03ed944703f6ed
BLAKE2b-256 checksum
How to use checksums
d4c44f52d0ee342d24d14e49b1544b7a9d0ac305f09fe44a2f79b96cbfcca5e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / datahugger_ng-0.6.8-cp310-abi3-manylinux_2_28_i686.whl

Download URL datahugger_ng-0.6.8-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
538f6ef8ae3b6ce3557f89fd4f9ff27e35f1db632675b3ab79706e7dadaed5e5
BLAKE2b-256 checksum
How to use checksums
90ecdca61b634ee8f1e2270e6d31de00f050928a0217bf56cc66ba6222335637
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / datahugger_ng-0.6.8-cp310-abi3-manylinux_2_28_armv7l.whl

Download URL datahugger_ng-0.6.8-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
570bb72d2aa6fb6dec52910951e9691cfabdac8aeb7c5b1d3372eff4f2fc88ab
BLAKE2b-256 checksum
How to use checksums
a5165d57f1b39be349a808d174d1445026a830c64f230280f42d74522e952a5b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / datahugger_ng-0.6.8-cp310-abi3-manylinux_2_28_aarch64.whl

Download URL datahugger_ng-0.6.8-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
5f01a2f675d78c4b5f49f9cb11dd7540fb969d0155ff176b22e6cb8bfa2feee8
BLAKE2b-256 checksum
How to use checksums
9fea92e2ed06ffdea0762cd475d4b50d44485d15954442bde2e17e2c12890637
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / datahugger_ng-0.6.8-cp310-abi3-macosx_11_0_arm64.whl

Download URL datahugger_ng-0.6.8-cp310-abi3-macosx_11_0_arm64.whl
Size 4.4 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
1825b4cb33be87260a53fd782fe16dc770c40e5561ff1e5eb98f817056f7e87f
BLAKE2b-256 checksum
How to use checksums
8ebeb48783334223ad4de1886c6e0afe316efe30c86b761eaa0ce2c04de7b16b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release history Release notifications | RSS feed

This release

0.6.8 This release

11 release files

0.6.7

11 release files

0.6.6

11 release files

0.6.5

11 release files

0.6.4

11 release files

0.6.3

11 release files

0.6.2

11 release files

0.6.1

11 release files

0.6.0

11 release files

0.5.6

11 release files

0.5.5

11 release files

0.5.4

11 release files

0.5.3

11 release files

0.5.2

11 release files

0.5.1

11 release files

0.5.0

11 release files

0.4.0

11 release files

0.3.0

11 release files

0.1.1

10 release files

0.1.0

10 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page