Skip to main content
Loss of provenance

A previous release had provenance metadata, but this release does not. View details.

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
from pydantic_settings import SettingsConfigDict


class FooSettings(BaseApiSettings):
    model_config = SettingsConfigDict(
        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 the contributing guide. This project is licensed under the MIT License.

Metadata

Release files for bibliofabric 0.7.0

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

Loss of provenance

These files do not have provenance metadata, despite files in a prior release including this data.

We recommend further investigation before installing these files. View details.

Source distribution (sdist)

Source distribution for bibliofabric 0.7.0
File Size Uploaded Provenance Actions
bibliofabric-0.7.0.tar.gz 39.8 kB Without provenance Details for bibliofabric-0.7.0.tar.gz

Built distribution (wheel)

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

Total release size: 86.2 kB

Release files / bibliofabric-0.7.0.tar.gz

Loss of provenance

This file belongs to a release without provenance metadata, despite a prior release including this data.

We recommend further investigation before installing this file. View details.

Download URL bibliofabric-0.7.0.tar.gz
Size 39.8 kB
Tags Source
SHA-256 checksum
How to use checksums
4f6859822ddf9a2bbbf91e96a2cd0d3d712b398699e7900509b67d729c78409c
BLAKE2b-256 checksum
How to use checksums
975ceb16cb50be5fa842e5cd3d7b84793a1ac47db68d8b98d50168e4a932e7c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

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

Loss of provenance

This file belongs to a release without provenance metadata, despite a prior release including this data.

We recommend further investigation before installing this file. View details.

Download URL bibliofabric-0.7.0-py3-none-any.whl
Size 46.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7b9decbbb4dde91bfae8d967d540f7e8b98984de32b9f1ad3c133e80839796d8
BLAKE2b-256 checksum
How to use checksums
9ec417f51a6cd60312dd90230bfa2ee0df66e537dc79373a8943456a43d26091
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for bibliofabric 0.7.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.

Loss of provenance

A previous release of these files had provenance metadata, but this release does not.

While this could reflect a routine change by the project maintainers, it may also indicate that the release files have been compromised.

Release comparison

  • Removed 0.6.0 2 files With provenance
  • Added 0.7.0 2 files Without provenance

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