openalex_local API
The openalex_local package exposes a small set of functions
(search, get, count, info, configure,
get_mode) and the Work / SearchResult dataclasses, plus
the Config singleton from openalex_local._core.config. Each
is documented below.
Core Functions
search
- openalex_local.search(query, limit=20, offset=0)[source]
Full-text search across works.
Uses FTS5 index for fast searching across titles and abstracts.
- Parameters:
- Return type:
- Returns:
SearchResult with matching works
Example
>>> from openalex_local import search >>> results = search("machine learning") >>> print(f"Found {results.total} matches")
get
- openalex_local.get(id_or_doi)[source]
Get a work by OpenAlex ID or DOI.
- Parameters:
id_or_doi (
str) – OpenAlex ID (e.g., W2741809807) or DOI- Return type:
- Returns:
Work object or None if not found
Example
>>> from openalex_local import get >>> work = get("W2741809807") >>> work = get("10.1038/nature12373") >>> print(work.title)
count
info
- openalex_local.info()[source]
Get database/API information.
- Return type:
- Returns:
Dictionary with database stats and mode info
- Raises:
FileNotFoundError – If no database configured and HTTP mode unavailable
Configuration
configure
get_mode
Data Classes
Work
- class openalex_local.Work(openalex_id, doi=None, title=None, abstract=None, authors=<factory>, year=None, source=None, issn=None, volume=None, issue=None, pages=None, publisher=None, type=None, concepts=<factory>, topics=<factory>, cited_by_count=None, referenced_works=<factory>, is_oa=False, oa_url=None, scitex_if=None, source_h_index=None, source_cited_by_count=None)[source]
Bases:
objectRepresents a scholarly work from OpenAlex.
- Variables:
openalex_id – OpenAlex ID (e.g., W2741809807)
doi – Digital Object Identifier
title – Work title
abstract – Abstract text (reconstructed from inverted index)
authors – List of author names
year – Publication year
source – Journal/venue name
issn – Journal ISSN
volume – Volume number
issue – Issue number
pages – Page range
publisher – Publisher name
type – Work type (journal-article, book-chapter, etc.)
concepts – List of OpenAlex concepts
topics – List of OpenAlex topics
cited_by_count – Number of citations
referenced_works – List of referenced OpenAlex IDs
is_oa – Is open access
oa_url – Open access URL
- citation(style='apa')[source]
Format work as a citation string.
- Parameters:
style (
str) – Citation style - “apa” (default) or “bibtex”- Return type:
- Returns:
Formatted citation string
Example
>>> work.citation() # APA format 'Piwowar, H., & Priem, J. (2018). The state of OA. PeerJ.' >>> work.citation("bibtex") # BibTeX format '@article{W2741809807, title={The state of OA}, ...}'
- save(path, format='json')[source]
Save work to file.
- Parameters:
- Return type:
- Returns:
Path to saved file
Examples
>>> work = get("W2741809807") >>> work.save("paper.json") >>> work.save("paper.bib", format="bibtex")
- __init__(openalex_id, doi=None, title=None, abstract=None, authors=<factory>, year=None, source=None, issn=None, volume=None, issue=None, pages=None, publisher=None, type=None, concepts=<factory>, topics=<factory>, cited_by_count=None, referenced_works=<factory>, is_oa=False, oa_url=None, scitex_if=None, source_h_index=None, source_cited_by_count=None)
SearchResult
- class openalex_local.SearchResult(works, total, query, elapsed_ms)[source]
Bases:
objectContainer for search results with metadata.
- Variables:
works – List of Work objects
total – Total number of matches
query – Original search query
elapsed_ms – Search time in milliseconds
- save(path, format='json', include_abstract=True)[source]
Save search results to file.
- Parameters:
- Return type:
- Returns:
Path to saved file
Examples
>>> results = search("machine learning", limit=10) >>> results.save("results.json") >>> results.save("results.bib", format="bibtex") >>> results.save("results.txt", format="text")
- __init__(works, total, query, elapsed_ms)