API Reference¶
OpenCite is a library as well as a CLI. The programmatic surface centers on two
async orchestrators and a set of data models, all configured by a single
Config object.
At a glance¶
| Symbol | Module | Use it for |
|---|---|---|
SearchOrchestrator |
opencite.search |
Parallel multi-source search with dedup/merge |
CitationExplorer |
opencite.citations |
Citation-graph traversal and canonical papers |
Config |
opencite.config |
Load and merge configuration |
Paper, IDSet, ... |
opencite.models |
Data models returned by the orchestrators |
OpenCiteError, ... |
opencite.exceptions |
Error hierarchy to catch |
Typical usage¶
Both orchestrators are async context managers. Open one, run your queries, and
let the async with block close the underlying HTTP clients:
import asyncio
from opencite import Config
from opencite.search import SearchOrchestrator
async def main():
config = Config.from_env()
async with SearchOrchestrator(config) as searcher:
result = await searcher.search(
"transformer attention",
max_results=10,
sources=("openalex", "s2"),
sort="citations",
)
print(f"{len(result.papers)} papers, by source: {result.total_by_source}")
for paper in result.papers:
print(paper.year, paper.title)
asyncio.run(main())
Top-level exports¶
The package re-exports the data models and Config for convenience:
opencite: Academic literature search, citation management, and PDF retrieval.
Config
dataclass
¶
Configuration for opencite.
from_env
classmethod
¶
from_env(config_path: Path | None = None) -> Config
Create config from TOML, .env files, and environment variables.
Priority (later overrides earlier): 1. Config dataclass defaults 2. ~/.opencite/config.toml 3. .env files (~/.opencite/.env, then CWD .env) 4. Environment variables
show ¶
Return a human-readable string of the resolved config.
API keys are masked by default.
Paper
dataclass
¶
Central data model for an academic paper.
Designed to be populated incrementally: a search fills basic fields, then enrichment passes add TLDR, PDF locations, etc.
Author
dataclass
¶
Structured author representation.
IDSet
dataclass
¶
All known identifiers for a single paper.
Immutable so it can be used for dedup lookups.
Source
dataclass
¶
Journal or venue information.
PDFLocation
dataclass
¶
A known location where a PDF can be retrieved.
SearchResult
dataclass
¶
Result of a multi-source search.
CitationResult
dataclass
¶
Result of a citation graph query.