Skip to main content
Loss of provenance

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

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

Discontinued. Aletheca is now bibliofabric.openalex in the bibliofabric package. This is the last release of aletheca, and it receives no further updates. Install bibliofabric and follow the migration guide.

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 and sync -- built on httpx with proper connection pooling; generated sync twin (AlethecaSyncClient) with the same API
  • 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
  • Ergonomic helpers -- batch_get_by_doi(), batch_get_by_openalex_id(), citing(), referenced(), oa_pdf_urls(), search_scoped(), sample(), group_by(), iterate_group_by(), autocomplete(), and rate_limit()

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), batch_get_by_openalex_id(ids), group_by(...), iterate_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(...) and client.works.sample(...). The client also exposes client.autocomplete(query) (free) and client.rate_limit() (free budget check).

Examples

All examples in examples/ are plain Python scripts. Run them from the repository root:

uv run packages/aletheca/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: Upstream quirks.

  • 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.5.2

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 aletheca 0.5.2
File Size Uploaded Provenance Actions
aletheca-0.5.2.tar.gz 46.2 kB Without provenance Details for aletheca-0.5.2.tar.gz

Built distribution (wheel)

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

Total release size: 110.6 kB

Release files / aletheca-0.5.2.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 aletheca-0.5.2.tar.gz
Size 46.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7e99f2b8f8ab484ae57a2d6a40b09c363afabbc1dc4c04d503dbb0adbe8a597b
BLAKE2b-256 checksum
How to use checksums
9a09f15da2d16bd6a99fac841f270a647ab5cfecf9917916db8a63d2134c7838
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 / aletheca-0.5.2-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 aletheca-0.5.2-py3-none-any.whl
Size 64.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
72040e2af3672af498ee1c41b12d27127ed047f3e71cce356b71530136c992c8
BLAKE2b-256 checksum
How to use checksums
3b45e8c78b2dfbcbe9827afe8585f3abf8da32b13fb1414b334ac0a3b8f4bfb8
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 aletheca 0.5.2

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.4.0 2 files With provenance
  • Added 0.5.2 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