Skip to main content

Aletheca: Asynchronous Python client for the OpenAlex API

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

Aletheca is an async Python client for the OpenAlex API, built on bibliofabric.

Docs: utsmok.github.io/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

Or with pip: pip install aletheca. Requires Python >=3.12.

Quick Start

import asyncio
from aletheca import AlethecaSession

async def main():
    async with AlethecaSession() as session:
        # Get a work by OpenAlex ID
        work = await session.works.get("W1234567890")
        print(work.title)

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

        # Iterate all works by an author (cursor-based auto-pagination)
        async for work in session.works.iterate(
            filters={"authorships.author.id": "A1234567890"},
            page_size=200,
        ):
            print(work.title)

asyncio.run(main())

No authentication required -- the OpenAlex API works without it. For higher rate limits, see Authentication.

Examples

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

# As a script
uv run examples/simple_example.py

# As an interactive notebook
uv run marimo edit examples/simple_example.py
Script Description
simple_example.py Search, iterate, get works
02_filtering_and_search.py WorksFilters, AuthorsFilters, and other filter models
03_institution_research.py Works by institution, topic analysis
04_author_discovery.py Find authors, retrieve their works
05_advanced_queries.py Cursor pagination, select fields, sort
06_convenience_queries.py session.queries.* convenience functions
07_iterator_helpers.py collect(), count(), first() from bibliofabric mixins
08_safe_types_and_helpers.py SafeList, SafeStr, DOI normalization, abstract reconstruction

See examples/README.md for details on running examples as interactive marimo notebooks.

Authentication

Aletheca auto-detects the OpenAlex API key from environment variables or .env files (prefixed with ALETHECA_). No auth is the default if nothing is configured.

ALETHECA_OPENALEX_API_KEY=your_api_key

Or pass explicitly:

async with AlethecaSession(api_key="your_api_key") as session:
    ...

With an API key you get faster responses (dedicated pool). Without one, you use the polite pool (slower).

Full guide: Authentication

Basic Usage

Get a single entity

work = await session.works.get("W2741809801")
print(work.title, work.doi, work.publication_year)

Search

results = await session.works.search(search="machine learning", page_size=5)
for work in results.results:
    print(work.title)

Iterate all results

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

Convenience queries

citations = await session.queries.citing_works("W2741809801")
print(f"{len(citations)} citations")

Full guide: Usage Basics · Works · All Entities

Known OpenAlex API Issues

Full bug report with reproduction steps: OPENALEX_BUG_REPORT.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 200, not 100 -- documented as 100 but the API accepts 200
  • 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

uv sync --all-groups --all-extras         # install everything
uv run ruff check src/ --fix              # lint
uv run ruff format src/                   # format
uvx ty check src/                         # type check
uv run pytest tests/                      # run tests
uv run pytest --cov=aletheca tests/       # coverage (CI threshold: 95%)
uv build                                  # build package
uv run mkdocs serve                       # local docs

Contributions welcome -- see Contributing.

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aletheca-0.2.1.tar.gz (22.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aletheca-0.2.1-py3-none-any.whl (35.4 kB view details)

Uploaded Python 3

File details

Details for the file aletheca-0.2.1.tar.gz.

File metadata

  • Download URL: aletheca-0.2.1.tar.gz
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for aletheca-0.2.1.tar.gz
Algorithm Hash digest
SHA256 149b39127b88a004b398be58e16fd8463071d6a4cd19dc48cce5ebf3e024fd3b
MD5 8363649e34ee3e8b885dcb4259f522a2
BLAKE2b-256 f81f3468b5384e556cd6e1d545af4256b3bfba3ffa4ccacec667f5df85990a25

See more details on using hashes here.

File details

Details for the file aletheca-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: aletheca-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 35.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for aletheca-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b3a21bf105edd50f91188e3eec0d1422be673519072d3ec58a1d34f342a791d2
MD5 3200bfb48558cf0401449f7c817ae800
BLAKE2b-256 5013eeac442dc38563d0e0ae2b3e7aeddbfdca08bd26e35e452c51741dd2e6d7

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.2

2 files

This release

0.2.1 This release

2 files

0.2.0

2 files

0.1.0

2 files

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