Programmatic access to PubMed biomedical literature via NCBI E-utilities REST API. Covers advanced Boolean/MeSH query construction, field-tagged searching, E-utilities endpoints (ESearch, EFetch, ESummary, EPost, ELink), history server for batch processing, citation matching, and systematic review search strategies. Use when searching biomedical literature, building automated literature pipelines, or conducting systematic reviews.
PubMed is the U.S. National Library of Medicine's database with 36M+ biomedical citations from MEDLINE and life sciences journals. This skill covers programmatic access via the E-utilities REST API and advanced search query construction using Boolean operators, MeSH terms, and field tags.
pip install requests # HTTP client for E-utilities API
# Optional: pip install biopython — Bio.Entrez wrapper (higher-level API)
API Rate Limits: 3 req/s without key, 10 req/s with key. Register at https://www.ncbi.nlm.nih.gov/account/
import requests, time
BASE_URL = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/"
API_KEY = "YOUR_API_KEY" # Optional but recommended
def pubmed_request(endpoint, params):
params.setdefault("api_key", API_KEY)
response = requests.get(f"{BASE_URL}{endpoint}", params=params)
response.raise_for_status()
time.sleep(0.1 if API_KEY != "YOUR_API_KEY" else 0.34)
return response
# Search → Fetch workflow
search_resp = pubmed_request("esearch.fcgi", {
"db": "pubmed", "term": "CRISPR[tiab] AND 2024[dp]",
"retmax": 5, "retmode": "json"
})
pmids = search_resp.json()["esearchresult"]["idlist"]
print(f"Found: {pmids}")
fetch_resp = pubmed_request("efetch.fcgi", {
"db": "pubmed", "id": ",".join(pmids),
"rettype": "abstract", "retmode": "text"
})
print(fetch_resp.text[:500])
For complete code examples across all 6 endpoints and search patterns, see references/api_reference.md.
For systematic review workflow and literature monitoring pipeline, see references/workflows.md.
For complete field tag reference and query templates, see references/search_syntax.md and references/common_queries.md.
| Endpoint | Purpose | Key Parameters |
|---|---|---|
esearch.fcgi | Search, return PMIDs | term, retmax, sort, usehistory |
efetch.fcgi | Download full records | id/query_key+WebEnv, rettype, retmode |
esummary.fcgi | Lightweight summaries | id, retmode |
epost.fcgi | Upload UIDs to server | id (comma-separated) |
elink.fcgi | Related articles, cross-DB | id, dbfrom, db, cmd |
einfo.fcgi | List databases/fields | db (optional) |
ecitmatch.cgi | Match citations to PMIDs | bdata |
For result sets >500 articles, use the history server to avoid URL length limits:
usehistory=y → returns WebEnv + QueryKeyWebEnv + QueryKey + retstart/retmaxWebEnvWhen no field tag is specified, PubMed maps terms through the MeSH Translation Table → Journals Table → Author Index → Full Text. Bypass ATM with explicit field tags (e.g., term[tiab]) or quoted phrases.
| Subheading | Use |
|---|---|
/diagnosis | Diagnostic methods |
/drug therapy | Pharmaceutical treatment |
/epidemiology | Disease patterns |
/etiology | Disease causes |
/genetics | Genetic aspects |
/prevention & control | Preventive measures |
/therapy | Treatment approaches |
| Parameter | Endpoint | Default | Effect |
|---|---|---|---|
term | ESearch | Required | Search query with Boolean/field tags |
retmax | ESearch/EFetch | 20 | Max records returned (up to 10,000) |
retstart | ESearch/EFetch | 0 | Offset for pagination |
rettype | EFetch | full | Output: abstract, medline, xml, uilist |
retmode | All | xml | Format: xml, json, text |
sort | ESearch | relevance | relevance, pub_date, first_author |
usehistory | ESearch | n | Enable history server: y for large sets |
api_key | All | None | NCBI API key for 10 req/sec |
time.sleep(0.1) with API key, time.sleep(0.34) without(diabetes mellitus[mh] OR diabetes[tiab]) for comprehensive coverage| Problem | Cause | Solution |
|---|---|---|
| HTTP 429 | Rate limit exceeded | Add time.sleep(); use API key |
| HTTP 414 (URI Too Long) | Too many PMIDs in URL | Use history server or EPost |
| Empty result set | Overly restrictive query | Remove filters one at a time |
| Unexpected MeSH mapping | Automatic Term Mapping | Use explicit field tags: term[tiab] |
| Missing abstracts | Pre-1975 or certain types | Filter: hasabstract[text] |
| Stale history server | Session expired (8h) | Re-run ESearch with usehistory=y |
| Truncated results | Default retmax=20 | Set retmax=100 or higher |