The FullTextClient provides access to full-text content from Europe PMC articles in various formats (PDF, XML, HTML).
Europe PMC has different endpoint architectures for different content types:
/PMC{id}/fullTextXML)https://europepmc.org/ftp/oa/)PMC1000000_PMC1099999.xml.gz)https://europepmc.org/articles/PMC{id}?pdf=renderhttps://europepmc.org/backend/ptpmcrender.fcgi?accid=PMC{id}&blobtype=pdfhttps://europepmc.org/pub/databases/pmc/pdf/OA/{dir}/PMC{id}.ziphttps://europepmc.org/article/MED/{medid}#free-full-text)from pyeuropepmc import FullTextClient
FullTextClient(rate_limit_delay: float = 1.0)
Parameters:
rate_limit_delay: Delay between requests to respect API limitscheck_fulltext_availability(pmcid: str) -> Dict[str, bool]
Check availability of full text formats for a given PMC ID.
Parameters:
pmcid: PMC ID (with or without ‘PMC’ prefix)Returns:
{"pdf": bool, "xml": bool, "html": bool}Note: HTML always returns False as it requires MED ID for checking.
download_pdf_by_pmcid(pmcid: str, output_path: Optional[Path] = None) -> Optional[Path]
Download PDF using multiple fallback endpoints.
Parameters:
pmcid: PMC ID (with or without ‘PMC’ prefix)output_path: Where to save the PDF (optional)Returns:
Download Strategy:
?pdf=render)ptpmcrender.fcgi)download_xml_by_pmcid(pmcid: str, output_path: Optional[Path] = None) -> Optional[Path]
Download XML full text with automatic fallback to bulk FTP archives.
This method first tries the REST API endpoint, and if that fails (404, 403, or network errors), it automatically falls back to bulk download from Europe PMC FTP OA archives.
Parameters:
pmcid: PMC ID (with or without ‘PMC’ prefix)output_path: Where to save the XML (optional)Returns:
download_xml_by_pmcid_bulk(pmcid: str, output_path: Optional[Path] = None) -> Optional[Path]
Download XML full text directly from Europe PMC FTP OA bulk archives only.
This method downloads from the Europe PMC FTP OA archives (.xml.gz files) without trying the REST API first. Useful when you specifically want to use the bulk download method or when the REST API is unavailable.
Parameters:
pmcid: PMC ID (with or without ‘PMC’ prefix)output_path: Where to save the XML (optional)Returns:
Note: Archives are organized by PMC ID ranges (e.g., PMC1000000_PMC1099999.xml.gz). The method automatically determines the correct archive and unpacks the gzipped content.
get_fulltext_content(pmcid: str, format_type: str = "xml") -> str
Get full text content as string (XML only).
Parameters:
pmcid: PMC IDformat_type: Must be “xml” (HTML not supported via PMC ID)Returns:
download_fulltext_batch(
pmcids: List[str],
format_type: str = "pdf",
output_dir: Optional[Path] = None,
skip_errors: bool = True
) -> Dict[str, Optional[Path]]
Batch download multiple articles.
Parameters:
pmcids: List of PMC IDsformat_type: “pdf” or “xml”output_dir: Directory to save filesskip_errors: Continue on individual failuresReturns:
The client raises FullTextError for:
from pyeuropepmc import FullTextClient
with FullTextClient() as client:
# Check availability
availability = client.check_fulltext_availability("3312970")
print(availability) # {"pdf": True, "xml": True, "html": False}
# Download PDF (tries multiple endpoints)
pdf_path = client.download_pdf_by_pmcid("3312970", "article.pdf")
# Download XML (via REST API)
xml_path = client.download_xml_by_pmcid("3312970", "article.xml")
from pyeuropepmc import FullTextClient, FullTextError
with FullTextClient() as client:
try:
pdf_path = client.download_pdf_by_pmcid("123456")
if pdf_path:
print(f"Downloaded: {pdf_path}")
else:
print("PDF not available via any endpoint")
except FullTextError as e:
print(f"Error: {e}")
from pathlib import Path
pmcids = ["3312970", "4123456", "5789012"]
with FullTextClient() as client:
results = client.download_fulltext_batch(
pmcids,
format_type="pdf",
output_dir=Path("downloads"),
skip_errors=True
)
for pmcid, path in results.items():
if path:
print(f"✓ {pmcid}: {path}")
else:
print(f"✗ {pmcid}: Download failed")
with statement) for proper cleanup