crossref_local API
Main Functions
- crossref_local.search(query, limit=10, offset=0, with_if=False)[source]
Full-text search across works.
Uses FTS5 index for fast searching across titles, abstracts, and authors.
- Parameters:
- Return type:
SearchResult- Returns:
SearchResult with matching works
Example
>>> from crossref_local import search >>> results = search("machine learning") >>> print(f"Found {results.total} matches")
- crossref_local.get(doi)[source]
Get a work by DOI.
- Parameters:
doi (
str) – Digital Object Identifier- Return type:
Optional[Work]- Returns:
Work object or None if not found
Example
>>> from crossref_local import get >>> work = get("10.1038/nature12373") >>> print(work.title)
- crossref_local.configure(db_path)[source]
Configure for local database access.
Example
>>> from crossref_local import configure >>> configure("/path/to/crossref.db")
- crossref_local.configure_http(api_url='http://localhost:8333')[source]
Configure for HTTP API access.
Example
>>> from crossref_local import configure_http >>> configure_http("http://localhost:8333") >>> # Or via SSH tunnel: >>> # ssh -L 8333:127.0.0.1:8333 your-server >>> configure_http() # Uses default localhost:8333
- crossref_local.enrich(results, include_citations=True, include_references=True)[source]
Enrich search results with full metadata (citations, references).
The search() function returns basic metadata for speed. This function fetches full metadata for each work, adding citation counts and references.
- Parameters:
- Return type:
SearchResult- Returns:
SearchResult with enriched works
Example
>>> from crossref_local import search, enrich >>> results = search("machine learning", limit=10) >>> enriched = enrich(results) >>> for work in enriched: ... print(f"{work.title}: {work.citation_count} citations")
- crossref_local.enrich_dois(dois, include_citations=True, include_references=True)[source]
Enrich a list of DOIs with full metadata.
Fetches complete metadata for each DOI including citation counts and reference lists.
- Parameters:
- Return type:
List[Work]- Returns:
List of Work objects with full metadata
Example
>>> from crossref_local import enrich_dois >>> works = enrich_dois(["10.1038/nature12373", "10.1126/science.aax0758"]) >>> for w in works: ... print(f"{w.doi}: {w.citation_count} citations, {len(w.references)} refs")
Data Classes
Work
- class crossref_local.Work(doi, title=None, authors=<factory>, year=None, journal=None, issn=None, volume=None, issue=None, page=None, publisher=None, type=None, abstract=None, url=None, citation_count=None, references=<factory>, impact_factor=None, impact_factor_source=None)[source]
Represents a scholarly work from CrossRef.
- doi
Digital Object Identifier
- title
Work title
- authors
List of author names
- year
Publication year
- journal
Journal/container title
- issn
Journal ISSN
- volume
Volume number
- issue
Issue number
- page
Page range
- publisher
Publisher name
- type
Work type (journal-article, book-chapter, etc.)
- abstract
Abstract text (if available)
- url
Resource URL
- citation_count
Number of citations (if available)
- references
List of reference DOIs
- doi: str
- classmethod from_metadata(doi, metadata)[source]
Create Work from CrossRef metadata JSON.
- citation(style='apa')[source]
Format as citation string.
- to_text(include_abstract=False)[source]
Format as human-readable text.
- save(path, format='json')[source]
Save work to file.
- Parameters:
- Return type:
- Returns:
Path to saved file
Examples
>>> work = get("10.1038/nature12373") >>> work.save("paper.json") >>> work.save("paper.bib", format="bibtex")
- __init__(doi, title=None, authors=<factory>, year=None, journal=None, issn=None, volume=None, issue=None, page=None, publisher=None, type=None, abstract=None, url=None, citation_count=None, references=<factory>, impact_factor=None, impact_factor_source=None)
SearchResult
- class crossref_local.SearchResult(works, total, query, elapsed_ms, limit_info=None)[source]
Container for search results with metadata.
- works
List of Work objects
- total
Total number of matches
- query
Original search query
- elapsed_ms
Search time in milliseconds
- limit_info
Information about result limiting
- works: List[Work]
- total: int
- query: str
- elapsed_ms: float
- limit_info: LimitInfo | None = None
- 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, limit_info=None)