Skip to main content

Aletheca: Python client for the OpenAlex API (async and sync)

Samuel Mok -- s.mok@utwente.nl -- 2025-2026

Aletheca is a Python client for the OpenAlex API, built on bibliofabric. The async client is the source of truth; a generated sync twin (AlethecaSyncClient, resource classes WorksSyncClient, AuthorsSyncClient, ...) offers the same API without an event loop.

Docs: utsmok.github.io/bibliofabric/aletheca -- PyPI: aletheca -- License: MIT

Features

  • Async by design -- built on httpx + asyncio with proper connection pooling
  • Typed throughout -- Pydantic v2 models for all entities, PEP 561 py.typed marker
  • Cursor pagination -- efficient iteration over large result sets via cursor-based auto-pagination
  • Filter serialization -- automatic conversion to OpenAlex filter=key:value syntax with Pydantic filter models
  • Safe types -- SafeList and SafeStr for None-safe traversal of API responses
  • Convenience queries -- high-level functions for common workflows (works_by_author, citing_works, etc.)

Installation

uv add aletheca

Requires Python >=3.12.

Quick Start

import asyncio
from aletheca import AlethecaClient


async def main():
    async with AlethecaClient() as client:
        # Get a work by OpenAlex ID (URL forms like https://doi.org/... also work)
        work = await client.works.get("W1234567890")
        print(work.title)

        # Search works (one page)
        page = await client.works.search(query="machine learning", page_size=10)
        for work in page.results:
            print(f"{work.title} ({work.publication_year})")

        # Iterate over matches with cursor auto-pagination (per-page=100 default)
        async for work in client.works.iterate(
            filters={"authorships.author.id": "A1234567890"},
        ):
            print(work.title)


asyncio.run(main())

Sync quick start

The sync twin behaves the same and never touches an event loop, so it also works in Jupyter, in threads, and when called from inside a running event loop:

from aletheca import AlethecaSyncClient

with AlethecaSyncClient() as client:
    work = client.works.get("W1234567890")
    print(work.title)

    page = client.works.search(query="machine learning", page_size=10)
    for work in page.results:
        print(f"{work.title} ({work.publication_year})")

    for work in client.works.iterate(
        filters={"authorships.author.id": "A1234567890"}, limit=5
    ):
        print(work.title)

Other resource methods: count() (minimal-cost select=id request), batch_get(ids, field=..., batch_size=...), batch_get_by_doi(dois), group_by(...), sample(n, seed=...), search_scoped(...) (search.title_and_abstract, search.exact, search.semantic), and the corpus=/include_pulled= parameters on client.works.search(...). The client also exposes client.autocomplete(query) (free) and client.rate_limit() (free budget check).

Examples

All examples in examples/ are dual-purpose -- run as scripts or as interactive marimo notebooks:

# As a script
uv run examples/quickstart.py
Script Description
quickstart.py Get, count, and search works
search_and_iterate.py Filter models, scoped search, cursor iteration
batch_and_citations.py batch_get_by_doi(), citing(), referenced(), rate_limit()

See examples/README.md for run instructions.

Authentication

OpenAlex has no polite pool: since February 2026 the API ignores mailto and meters unkeyed traffic at $0.10/day per IP address. A free API key raises the budget to $1/day and is required for cursor paging beyond the first page. Get one at openalex.org/settings/api.

Aletheca reads the key from the environment or .env (prefix ALETHECA_):

ALETHECA_API_KEY=your_api_key          # ALETHECA_OPENALEX_API_KEY also accepted

Or pass it explicitly:

async with AlethecaClient(api_key="your_api_key") as client:
    ...

The key is sent as the api_key query parameter by default; pass auth_scheme="bearer" (or set ALETHECA_AUTH_SCHEME=bearer) to send it as an Authorization: Bearer header instead.

→ Full guide: docs index and errors, retries, and rate limits

Basic Usage

Get a single entity

work = await client.works.get("W2741809801")
print(work.title, work.doi, work.publication_year)
page = await client.works.search(query="machine learning", page_size=5)
for work in page.results:
    print(work.title)

Iterate all results

async for work in client.works.iterate(
    filters={"publication_year": 2024, "is_oa": True},
):
    print(work.title)
    break  # stop when you want

Citations and references

citations = await client.works.citing("W2741809801", limit=100)
refs = await client.works.referenced("W2741809801", limit=100)
print(f"{len(citations)} citing works, {len(refs)} references fetched")

→ Full guide: Works · all entity pages · API reference

Known OpenAlex API Issues

Verified findings: docs/upstream-quirks.md.

  • OpenAPI spec is substantially incomplete -- 50+ fields returned by the live API are missing from the spec schemas across all entity types. Several spec fields don't exist in the live API.
  • Wrong field names in spec -- content_url (spec) vs content_urls (live), grants_count (spec) vs awards_count (live)
  • Undocumented fields -- institution_awarded on Awards is not documented anywhere; 15+ nested Award filters are missing from the docs filter table
  • Awards endpoint missing from llms.txt -- the awards endpoint is not listed in the API quick reference
  • per_page max is 100 -- 200 still works but is deprecated legacy behavior, slated for removal (OpenAlex docs, 2026-08); all examples here use 100
  • Keyword IDs are slug paths, not short IDs -- live keyword records carry ids like https://openalex.org/keywords/photosynthesis, and the single-record route rejects that full-URL form (nested slashes → HTML 404) even though /works/https://openalex.org/W… is accepted. get() normalizes both forms.
  • Awards 400 body is the authoritative filter list -- the awards endpoint rejects several filters its docs summaries suggest (funder.country_code, plain display_name, lead_investigator.id, from_/to_*_date) and its 400 error body enumerates all 40 valid filters, which is more complete than any docs table.

Development

Aletheca lives in the bibliofabric uv workspace at packages/aletheca. From the repository root:

uv sync --all-packages --all-groups  # install everything
uv run pytest packages/aletheca/tests  # offline tests; add -m live_api for live smoke tests
uv build --package aletheca           # build package

Shared tooling (ruff, ty, pytest, mkdocs) is configured once at the workspace root; see the root AGENTS.md.

Contributions welcome -- see Contributing.

License

MIT

Metadata

Release files for aletheca 0.4.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 aletheca 0.4.0
File Size Uploaded Provenance Actions
aletheca-0.4.0.tar.gz 38.0 kB With provenance Details for aletheca-0.4.0.tar.gz

Built distribution (wheel)

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

Total release size: 93.1 kB

Release files / aletheca-0.4.0.tar.gz

Download URL aletheca-0.4.0.tar.gz
Size 38.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f3deac64556c2d08f2f0714065ffc838fbb708f918ee1a7a4d609b9ec42e1a3a
BLAKE2b-256 checksum
How to use checksums
4b99438131df76287fcb951878d00a33284e6efe0a3fc8ad379cff55581e4f06
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 / aletheca-0.4.0-py3-none-any.whl

Download URL aletheca-0.4.0-py3-none-any.whl
Size 55.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f934a11f2f366e83c4155c4298cfcea7c4317eaef00d132210cc662f77e077fd
BLAKE2b-256 checksum
How to use checksums
00f58655048ba3a589892192eb3d904d165d63b751b0d52067ca062b688c2aa2
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 aletheca 0.4.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 aletheca-0.4.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