Skip to main content

python binding of datahugger -- rust tool for fetching data and metadata from DOI or URL.

Project description

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"))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

datahugger_ng-0.6.5-cp310-abi3-win_amd64.whl (3.7 MB view details)

Uploaded CPython 3.10+Windows x86-64

datahugger_ng-0.6.5-cp310-abi3-musllinux_1_2_x86_64.whl (7.2 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

datahugger_ng-0.6.5-cp310-abi3-musllinux_1_2_i686.whl (6.7 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ i686

datahugger_ng-0.6.5-cp310-abi3-musllinux_1_2_armv7l.whl (6.1 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARMv7l

datahugger_ng-0.6.5-cp310-abi3-musllinux_1_2_aarch64.whl (7.3 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

datahugger_ng-0.6.5-cp310-abi3-manylinux_2_28_x86_64.whl (6.4 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64

datahugger_ng-0.6.5-cp310-abi3-manylinux_2_28_ppc64le.whl (7.1 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ppc64le

datahugger_ng-0.6.5-cp310-abi3-manylinux_2_28_i686.whl (6.2 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ i686

datahugger_ng-0.6.5-cp310-abi3-manylinux_2_28_armv7l.whl (5.9 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARMv7l

datahugger_ng-0.6.5-cp310-abi3-manylinux_2_28_aarch64.whl (7.0 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

datahugger_ng-0.6.5-cp310-abi3-macosx_11_0_arm64.whl (4.3 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

Details for the file datahugger_ng-0.6.5-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for datahugger_ng-0.6.5-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 4a77e0f2af927adecd8f5759de9244e124b5f97d593380edbea720f2b332ac71
MD5 479baaa56f94be56a17c55eae0b2fa3e
BLAKE2b-256 72563d87d8b06ba09a386c5ac472812f17df829d35bba1999cbcb30793de4ece

See more details on using hashes here.

File details

Details for the file datahugger_ng-0.6.5-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for datahugger_ng-0.6.5-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ba7cb06cf637686b1c8694390d2e67b95f08ce292e0a64af5aa918c40ae026e3
MD5 3c2896b629d7e2e515273a5b8e540508
BLAKE2b-256 2d5b68ea7cff36af71b39a41486fe438789da21ab6d4b6d6822ed3a4e9a414ec

See more details on using hashes here.

File details

Details for the file datahugger_ng-0.6.5-cp310-abi3-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for datahugger_ng-0.6.5-cp310-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 e0f8dac6710808ad22f173a8393d25b0fb371ab91a7d90e7f00b0f13b68e8a08
MD5 e0ac9f8dc52c4afe1efc91bbbf662909
BLAKE2b-256 e309d34ca103d8c7bf88b29ed2405d8a41d072e4656568eab36b71449d266eac

See more details on using hashes here.

File details

Details for the file datahugger_ng-0.6.5-cp310-abi3-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for datahugger_ng-0.6.5-cp310-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 a59af8d3a87fcee51ecf51a1c935fec949600e90502167f78d9a8daa7996fb25
MD5 5621f06588ebfc6b6a400f284d3681f2
BLAKE2b-256 bb312a900fa4d2cabdbf6c76f9ec5e244ee0cb7422c5ada517d4db008e109378

See more details on using hashes here.

File details

Details for the file datahugger_ng-0.6.5-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for datahugger_ng-0.6.5-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 6128588b64d962263d174ce2641fe58cf14fc484f4f994ec4499386a7ed61df6
MD5 fb1e5a7ec2d12f12e3102159a5a9f1a1
BLAKE2b-256 47451b75db2822b266fd51cbcfbe3e5f84363eb6964495cad2326f413e87f50a

See more details on using hashes here.

File details

Details for the file datahugger_ng-0.6.5-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for datahugger_ng-0.6.5-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ab2c9afbc9a5ed1adb6d1b17bcabc7673684223ad2b605b7d183c7048984a883
MD5 78ff70d42a7a3c22b613f28c13c23948
BLAKE2b-256 31dd2ecf0c06cd7ef5940c74340e0edb2119d721062a0bd3df7e66b793a80208

See more details on using hashes here.

File details

Details for the file datahugger_ng-0.6.5-cp310-abi3-manylinux_2_28_ppc64le.whl.

File metadata

File hashes

Hashes for datahugger_ng-0.6.5-cp310-abi3-manylinux_2_28_ppc64le.whl
Algorithm Hash digest
SHA256 27cac442eef016a98127f7983ad17e9d44502b25f96e2b3a38dbe6b043bdb60c
MD5 d5088afd9fdf63e4e18859e6bcf76e3d
BLAKE2b-256 4cbeba11b41b918d532e26c971460b843c3643f976a9a15c091aa0ce98992eea

See more details on using hashes here.

File details

Details for the file datahugger_ng-0.6.5-cp310-abi3-manylinux_2_28_i686.whl.

File metadata

File hashes

Hashes for datahugger_ng-0.6.5-cp310-abi3-manylinux_2_28_i686.whl
Algorithm Hash digest
SHA256 754fab7b433ae8dbfb762b8d9e9d14d297678f9bc21c9746212157a9db976902
MD5 24e38dc36365d0737f3e76fab2d48494
BLAKE2b-256 e8856b7cc606eea2746f1fe74474a40f8a384d7167a13820146c026472855ac5

See more details on using hashes here.

File details

Details for the file datahugger_ng-0.6.5-cp310-abi3-manylinux_2_28_armv7l.whl.

File metadata

File hashes

Hashes for datahugger_ng-0.6.5-cp310-abi3-manylinux_2_28_armv7l.whl
Algorithm Hash digest
SHA256 6ddec4fbe77c42e7802b500252d910ce03da54680324ccd2270fd280160214fb
MD5 a8d7e3c03fd2cbaec602188f7459df9f
BLAKE2b-256 5075865ec389ea2dcee315e1ec9da77aa945f5461cd6b5eea03c1e7b07c7cddb

See more details on using hashes here.

File details

Details for the file datahugger_ng-0.6.5-cp310-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for datahugger_ng-0.6.5-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b7daadea2afba4d13691871d9ecfe109c20186053c920dd88dc34bd54d6fb8ce
MD5 1a24ee0aca8cc3a52cbeca62cc575b99
BLAKE2b-256 20fcd697dd7e542f8228a04cd56efe6d64d6be4b3dde0811a7dc058f9b3d87a5

See more details on using hashes here.

File details

Details for the file datahugger_ng-0.6.5-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for datahugger_ng-0.6.5-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 aaeea1becbab00e9c0433a40ae6459fceb88b3cf23e525c5fcefc8cb11a3e292
MD5 e214ac2ac4d6acc99a38287e00e1e5e8
BLAKE2b-256 bd3f8ad341d68b7edaeb11192b45eff1cf3f66287f4139704e23d2ef8afa1f27

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page