PyEuropePMC is a Python library for searching and retrieving scientific literature from the Europe PMC database. It provides a simple, robust interface to access millions of research articles, preprints, and other scholarly content.
pip install pyeuropepmc
For development:
pip install -e ".[dev]"
Python 3.10 and newer versions are supported.
No, Europe PMC provides open access to their search API without requiring registration or API keys.
from pyeuropepmc.search import SearchClient
with SearchClient() as client:
results = client.search("CRISPR", pageSize=10)
for paper in results["resultList"]["result"]:
print(paper["title"])
# Search by author
results = client.search('AUTH:"Smith J"')
# Search by author and topic
results = client.search('AUTH:"Smith J" AND cancer')
Use the pagination features:
# Automatic pagination
all_results = client.fetch_all_pages("machine learning", max_results=1000)
# Manual pagination
page1 = client.search("query", pageSize=100, offset=0)
page2 = client.search("query", pageSize=100, offset=100)
Note: RIS and BibTeX support has been removed as of vX.Y.Z. Please use JSON, XML, or Dublin Core formats.
json_results = client.search("query", format="json")
xml_results = client.search("query", format="xml")
dc_results = client.search("query", format="dc")
# Specific year
results = client.search("cancer AND PUB_YEAR:2023")
# Date range
results = client.search("cancer AND PUB_YEAR:[2020 TO 2023]")
# Recent articles (last 5 years)
from datetime import datetime
current_year = datetime.now().year
results = client.search(f"cancer AND PUB_YEAR:[{current_year-5} TO {current_year}]")
# Built-in rate limiting
client = SearchClient(rate_limit_delay=2.0) # 2 seconds between requests
# Custom throttling
import time
for query in queries:
results = client.search(query)
time.sleep(1) # Additional delay
# Search specific sources
results_pubmed = client.search("query", source="MED")
results_pmc = client.search("query", source="PMC")
results_preprints = client.search("query", source="PPR")
# Combine results
all_results = results_pubmed + results_pmc + results_preprints
from pyeuropepmc.search import SearchClient, EuropePMCError
try:
with SearchClient() as client:
results = client.search("complex query")
except EuropePMCError as e:
print(f"Search failed: {e}")
except Exception as e:
print(f"Unexpected error: {e}")
The client includes built-in retry logic for network errors.
Europe PMC doesn’t publish specific rate limits, but we recommend:
SearchClient(rate_limit_delay=1.0)# Use appropriate page sizes
results = client.search("query", pageSize=100) # vs. pageSize=10
# Request only needed fields
results = client.search("query", resultType="lite") # vs. "core"
# Use caching for repeated queries
# (implement your own caching layer)
Standard fields include:
for paper in results["resultList"]["result"]:
# Check if full text is available
if paper.get("isOpenAccess") == "Y":
print(f"Open access: {paper.get('fullTextUrlList')}")
# PMC articles may have full text
if paper.get("pmcid"):
print(f"PMC ID: {paper['pmcid']}")
Citation counts are updated regularly but may not be real-time. They include:
AUTH: not AUTHOR:# Debug: Check hit count
hit_count = client.get_hit_count("your query")
print(f"Total matches: {hit_count}")
# Increase timeout
client = SearchClient(timeout=60) # Default is 30 seconds
# Check network connectivity
# Try simpler queries first
Not all articles have complete metadata:
Use safe access:
title = paper.get("title", "No title available")
authors = paper.get("authorString", "No authors listed")
See our Contributing Guide for:
# Good: Specific, well-structured queries
query = 'TITLE:"machine learning" AND PUB_YEAR:[2020 TO 2023]'
# Avoid: Too broad or ambiguous
query = "data" # Too broad, millions of results
# Good: Use context managers
with SearchClient() as client:
results = client.search("query")
# Good: Implement proper error handling
try:
results = client.search("query")
except EuropePMCError as e:
logger.error(f"Search failed: {e}")
# Good: Process results efficiently
def extract_key_info(results):
return [
{
"title": paper.get("title"),
"year": paper.get("pubYear"),
"citations": paper.get("citedByCount", 0)
}
for paper in results["resultList"]["result"]
]