Skip to main content

bibliofabric: shared core for scholarly API clients

Samuel Mok // s.mok@utwente.nl

bibliofabric is an asynchronous Python framework for building client libraries for scholarly APIs (OpenAIRE, OpenAlex, Crossref, and similar services). It owns what every such client needs: HTTP with retries and throttling, authentication, error mapping, paging, batch retrieval, identifier normalization, and typed resource clients. A client library only adds what is specific to its API.

Installation

uv add bibliofabric

Requires Python 3.12 or newer.

Building a client

A client library defines four things: a settings subclass, a response unwrapper, a query dialect, and one ResourceClient subclass per endpoint.

from bibliofabric import (
    BaseApiClient,
    BaseApiSettings,
    QueryDialect,
    ResourceClient,
    ResponseUnwrapper,
)
from pydantic import BaseModel, ConfigDict


class FooSettings(BaseApiSettings):
    model_config = ConfigDict(env_prefix="FOO_", env_file=".env", extra="ignore")


class Work(BaseModel):
    id: str = ""
    title: str = ""
    doi: str | None = None


class FooUnwrapper:
    """Unwraps the Foo API envelope: {"results": [...], "total": n}."""

    def results(self, body):
        return body.get("results", [])

    def item(self, body):
        return body

    def total(self, body):
        return body.get("total")

    def next_cursor(self, body):
        return body.get("next_cursor")

    def meta(self, body):
        return {k: v for k, v in body.items() if k != "results"}


DIALECT = QueryDialect(
    page_size_param="per_page",
    max_page_size=200,
    query_param="search",
    select_param="select",
)


class Works(ResourceClient[Work]):
    path = "works"
    model = Work
    dialect = DIALECT


class FooClient(BaseApiClient):
    def __init__(self, settings=None, auth=None):
        super().__init__(
            base_url="https://api.foo.org/v1",
            settings=settings or FooSettings(),
            unwrapper=FooUnwrapper(),
            auth=auth,
        )
        self.works = Works(self)

Using the client:

async with FooClient() as client:
    work = await client.works.get("W123")  # 404 raises NotFoundError
    page = await client.works.search(query="algae")  # returns Page[Work]
    async for work in client.works.iterate(page_size=100, limit=500):
        ...
    count = await client.works.count()
    batch = await client.works.batch_get(["W1", "W2", "W3"])

get(), search(), and count() return typed results; iteration supports cursor, page, and offset paging depending on the dialect. Errors, retries, and limits are described in the errors page.

Every client built on the framework also gets a generated sync twin. Sync classes follow the FooClient -> FooSyncClient naming rule:

with FooSyncClient() as client:
    work = client.works.get("W123")
    page = client.works.search(query="algae")
    for work in client.works.iterate(page_size=100, limit=500):
        ...

The sync client uses httpx.Client, time.sleep, and threads; it never starts an event loop, so it works in plain scripts, in Jupyter, and inside a running event loop. See the "Sync usage" docs page.

Reference clients

Contributing and license

See contributing.md. This project is licensed under the MIT License.

Metadata

Release files for bibliofabric 0.6.0

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

Source distribution (sdist)

Source distribution for bibliofabric 0.6.0
File Size Uploaded Provenance Actions
bibliofabric-0.6.0.tar.gz 27.0 kB With provenance Details for bibliofabric-0.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bibliofabric 0.6.0
File Interpreter ABI Platform Actions
bibliofabric-0.6.0-py3-none-any.whl Python 3 none any Details for bibliofabric-0.6.0-py3-none-any.whl

Total release size: 60.4 kB

Release files / bibliofabric-0.6.0.tar.gz

Download URL bibliofabric-0.6.0.tar.gz
Size 27.0 kB
Tags Source
SHA-256 checksum
How to use checksums
857ce79a7a78d562c1f34282ff62786f1425cbd9846bd8d3c995335c5b1874da
BLAKE2b-256 checksum
How to use checksums
f9f4f97807ffeef27964dcd0caa4d360f41d4397a273d014ef49537b84c4325f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Release files / bibliofabric-0.6.0-py3-none-any.whl

Download URL bibliofabric-0.6.0-py3-none-any.whl
Size 33.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
57ac27a88dd912c4bb5e6279ad1eca3207169650fcad3f694bcfa05004c50985
BLAKE2b-256 checksum
How to use checksums
a421b4c8dd60a6fe62cc7964e96ae7e7cb9943d84cb2bb3ef56866c2ed958216
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Security for bibliofabric 0.6.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for bibliofabric-0.6.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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