Metadata-Version: 2.4
Name: bibliofabric
Version: 0.9.1
Summary: Typed async and sync clients for scholarly infrastructure APIs: OpenAlex, OpenAIRE, Crossref, ROR, Zenodo, DataCite, and more, on one shared core
Author: Samuel Mok
Author-email: Samuel Mok <s.mok@utwente.nl>
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Framework :: AsyncIO
Classifier: Typing :: Typed
Requires-Dist: httpx>=0.27.0
Requires-Dist: pydantic>=2.9.0
Requires-Dist: pydantic-settings>=2.9.1
Requires-Dist: tenacity>=9.0.0
Requires-Python: >=3.12
Project-URL: Homepage, https://github.com/utsmok/bibliofabric
Project-URL: Repository, https://github.com/utsmok/bibliofabric
Project-URL: Documentation, https://utsmok.github.io/bibliofabric/
Project-URL: Issues, https://github.com/utsmok/bibliofabric/issues
Project-URL: Changelog, https://github.com/utsmok/bibliofabric/blob/main/packages/bibliofabric/CHANGELOG.md
Description-Content-Type: text/markdown

# bibliofabric: Python clients for scholarly metadata APIs

*Samuel Mok // s.mok@utwente.nl*

`bibliofabric` is one package with sixteen clients for scholarly metadata
APIs. A client fetches records from one source as typed models, with plain
Python calls. Every client comes in an async version and a sync version that
share the same methods, and all of them stand on one core that handles HTTP,
retries, rate limits, paging, and error mapping.

## Installation

```bash
uv add bibliofabric
```

Requires Python 3.12 or newer. The clients `aireloom`, `aletheca`, and
`stavrophora` were folded into this package as `bibliofabric.openaire`,
`bibliofabric.openalex`, and `bibliofabric.crossref`; the
[migration guide](https://utsmok.github.io/bibliofabric/migration/) lists
every rename.

## Use a client

```python
from bibliofabric.crossref import CrossrefSyncClient

with CrossrefSyncClient() as client:
    work = client.works.get("10.1038/nature12373")
    print(work.primary_title)
```

The script prints `Nanometre-scale thermometry in a living cell`. The async
client makes the same calls with `await`:

```python
import asyncio

from bibliofabric.crossref import CrossrefClient


async def main() -> None:
    async with CrossrefClient() as client:
        work = await client.works.get("10.1038/nature12373")
        print(work.primary_title)


asyncio.run(main())
```

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.

The [Quick start](https://utsmok.github.io/bibliofabric/quickstart/) continues
with search, paging, and error handling. The guide
[What every client gives you](https://utsmok.github.io/bibliofabric/guide/)
explains the methods that all clients share, and every client has its own
quick start and guide at
[utsmok.github.io/bibliofabric](https://utsmok.github.io/bibliofabric/).

## Clients

Each client is a subpackage of `bibliofabric`, named after its source. No
client needs a key to start. Where a key exists, the table names the variable
that holds it.

| Client | Import | What you get | Key |
|---|---|---|---|
| [OpenAlex](https://utsmok.github.io/bibliofabric/openalex/) | `bibliofabric.openalex` | works, authors, sources, institutions, topics, funders, and the citation graph | free key recommended, `OPENALEX_API_KEY` |
| [OpenAIRE](https://utsmok.github.io/bibliofabric/openaire/) | `bibliofabric.openaire` | research products, projects, organizations, data sources, persons, and links between publications and data | none, `OPENAIRE_CLIENT_ID` and `OPENAIRE_CLIENT_SECRET` for a larger quota |
| [Crossref](https://utsmok.github.io/bibliofabric/crossref/) | `bibliofabric.crossref` | works, journals, funders, members, prefixes, licenses, and the beta data citation index | none, `CROSSREF_MAILTO` for the faster pool |
| [ROR](https://utsmok.github.io/bibliofabric/ror/) | `bibliofabric.ror` | research organizations and funders, with search and bulk data dumps | none |
| [Zenodo](https://utsmok.github.io/bibliofabric/zenodo/) | `bibliofabric.zenodo` | records, files, communities, vocabularies, and OAI-PMH harvesting | none, `ZENODO_API_TOKEN` for private records |
| [DataCite](https://utsmok.github.io/bibliofabric/datacite/) | `bibliofabric.datacite` | DOIs, clients, providers, repositories, prefixes, events, and GraphQL | none |
| [OpenCitations](https://utsmok.github.io/bibliofabric/opencitations/) | `bibliofabric.opencitations` | citation links between DOI-identified publications, and their metadata | none |
| [DOI](https://utsmok.github.io/bibliofabric/doi/) | `bibliofabric.doi` | the registration agency of a DOI, metadata as CSL, DataCite, or Schema.org, and Handle records | none |
| [Semantic Scholar](https://utsmok.github.io/bibliofabric/semanticscholar/) | `bibliofabric.semanticscholar` | papers, authors, citations, references, recommendations, datasets, snippets, and patents | key recommended, `SEMANTICSCHOLAR_API_KEY` |
| [ORCID](https://utsmok.github.io/bibliofabric/orcid/) | `bibliofabric.orcid` | researcher records with works, employment, education, and peer reviews | none, `ORCID_ACCESS_TOKEN` for a larger quota |
| [Europe PMC](https://utsmok.github.io/bibliofabric/europepmc/) | `bibliofabric.europepmc` | articles, full text, citations, references, annotations, grants, and preprints | none |
| [Wikidata](https://utsmok.github.io/bibliofabric/wikidata/) | `bibliofabric.wikidata` | entities, claims, search, site links, lexemes, and SPARQL | none |
| [DOAJ](https://utsmok.github.io/bibliofabric/doaj/) | `bibliofabric.doaj` | open access journals and articles | none |
| [ISSN Portal](https://utsmok.github.io/bibliofabric/issn/) | `bibliofabric.issn` | ISSN records and title word abbreviations | none |
| [arXiv](https://utsmok.github.io/bibliofabric/arxiv/) | `bibliofabric.arxiv` | preprints by query, with paging | none |
| [bioRxiv and medRxiv](https://utsmok.github.io/bibliofabric/rxiv/) | `bibliofabric.rxiv` | preprints, their versions, the articles they became, funders, and usage statistics | none |

## What every client does the same way

Every client shares one set of methods, so you learn them once. `get()`
fetches one record. `search()` returns one page, and `iterate()`, `collect()`,
`first()`, and `count()` work with the whole result set. `batch_get()` fetches
many records at once. Clients read their settings from environment variables,
accept identifiers such as DOIs in several forms, raise typed exceptions, and
retry after a rate limit on their own.

## Build a client on the core

A client for a source that isn't covered yet defines four things: a settings
subclass, a response unwrapper, a query dialect, and one `ResourceClient`
subclass per endpoint. The sync twin is generated from the async code. The
[guide to building a client](https://utsmok.github.io/bibliofabric/bibliofabric/writing-a-client/)
walks through every step with a complete example, and the pages next to it
describe the core (`BaseApiClient`, `QueryDialect`, `Page`, and the exception
hierarchy).

## Contributing and license

See the [contributing guide](https://utsmok.github.io/bibliofabric/contributing/).
This project is licensed under the MIT License.
