PubMed
bibliofabric.pubmed is a Python client for the NCBI E-utilities, the
programmatic interface of PubMed. It wraps the five read scripts of the
E-utilities: esearch.fcgi (uid search), esummary.fcgi (document
summaries), efetch.fcgi (full records as XML), elink.fcgi
(cross-database links and provider URLs), and einfo.fcgi (database
metadata). Every call returns typed Pydantic models, and each client ships
as an async class plus a generated sync twin.
The API works without credentials. Without an API key NCBI allows 3
requests per second; the default settings pace the client accordingly. With
PUBMED_API_KEY set the upstream ceiling rises to 10 requests per second;
set PUBMED_MAX_REQUESTS_PER_SECOND=10 to use it. NCBI asks every caller
to send tool and email contact parameters; the client sends them from
PUBMED_TOOL (default bibliofabric) and PUBMED_EMAIL. PubMed records
come from NLM and are in the public domain in the United States.
Quick start
import asyncio
from bibliofabric.pubmed import PubmedClient
async def main() -> None:
async with PubmedClient() as client:
page = await client.ids.search(query="CRISPR review", page_size=5)
print("total hits:", page.total)
print("uids:", [record.uid for record in page.results])
first = await client.summaries.get(page.results[0].uid)
print(first.title, f"({first.pubdate})")
record = await client.records.get(page.results[0].uid)
print("authors:", len(record.medline_citation.article.authors))
asyncio.run(main())
total hits: 13291
uids: ['43111037', '43110557', '43110019', '43109945', '43109867']
CRISPR functional screening for natural killer cells. (2026 Nov 29)
authors: 3
Sync quick start
PubmedSyncClient is generated from the async source and offers the same
methods without async and await. The page
Async and sync clients explains when to use which.
from bibliofabric.pubmed import PubmedSyncClient
with PubmedSyncClient() as client:
page = client.ids.search(query="CRISPR review", page_size=5)
record = client.records.get(page.results[0].uid)
print(record.pmid, record.title)
What the client offers
| Attribute | Route | Common methods | Notes |
|---|---|---|---|
client.ids |
esearch.fcgi |
search, iterate, collect, first, count; get raises ConfigurationError |
search() pages by offset; params={"usehistory": "y"} puts webenv and querykey into page.meta |
client.summaries |
esummary.fcgi |
search, iterate, collect, first, count, get, by_ids |
search() runs one esearch with history and one esummary request |
client.records |
efetch.fcgi |
search, iterate, collect, first, count, get, by_ids |
full PubmedArticle records from the PubmedArticleSet XML |
client.links |
elink.fcgi |
related, provider_links |
related() answers cmd=neighbor, provider_links() answers cmd=prlinks |
client.info |
einfo.fcgi |
database, databases |
field lists and cross-database links of one database |
Search verbs on client.ids return one Uid per hit. client.summaries
and client.records compose the history flow themselves: a search(query)
call sends usehistory=y to esearch, then asks esummary or efetch for the
records of that history window.
The shared behavior of search, iterate, collect, first, and count
is described in Paging, and search(query=...) query
strings in Search.
Examples
Runnable scripts live in packages/bibliofabric/examples/pubmed/:
quickstart.pysearches, reads one summary and one full record, and follows a PMC link.records_sync.pyharvests full records with the sync client.
Next
- Upstream quirks lists where the live API differs from its documentation.
- The API reference is generated from the source.