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.8.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.8.0
File Size Uploaded Provenance Actions
bibliofabric-0.8.0.tar.gz 43.5 kB Without provenance Details for bibliofabric-0.8.0.tar.gz

Built distribution (wheel)

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

Total release size: 93.6 kB

Release files / bibliofabric-0.8.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.8.0.tar.gz
Size 43.5 kB
Tags Source
SHA-256 checksum
How to use checksums
fe86e93dbf9dff50b61148c5fe4de0a9c6ef33b0adba17b4205e90bb4f6b4d4a
BLAKE2b-256 checksum
How to use checksums
d36d5a63b7287ba6560c8121186e82d8f501dcb787cbe195dfd36ef2aa1d93a7
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.8.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.8.0-py3-none-any.whl
Size 50.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
16bce38bb998b71362ff82835bfd336fba39a31b74283d1b296bf8a840438fe0
BLAKE2b-256 checksum
How to use checksums
3b7b0744c43d7074eba14423d30979ed891235576e51f8370711745b9637d416
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.8.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.8.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