PubMed Downloader
Convert PubMed articles to clean, structured markdown. Handles the full pipeline: PMID resolution, full-text extraction via PubMed Central, HTML-to-markdown conversion, and supplementary material retrieval.
Articles without open-access full text automatically fall back to abstract-only download.
Installation
pip install pubmed-markdown
Requires Python 3.11+.
Setup
Set your email for NCBI API identification (required to avoid 403 errors):
export NCBI_EMAIL=your-email@institution.edu
Or pass them directly:
downloader = PubMedMarkdown(
email="your-email@institution.edu",
ncbi_key="your-ncbi-api-key", # optional; raises rate limit from 3 to 10 req/s
)
Quick Start
from pubmed_markdown import PubMedMarkdown
downloader = PubMedMarkdown()
# Get markdown string from a PMID
markdown = downloader.pmid_to_markdown("12895196")
Usage
Python API
Get markdown strings (single or batch, no files created):
from pubmed_markdown import PubMedMarkdown
downloader = PubMedMarkdown()
# From PMID — accepts a single string or a list
markdown = downloader.pmid_to_markdown("12895196")
markdowns = downloader.pmid_to_markdown(["12895196", "17872605"])
# From PMCID directly — also accepts a single string or a list
markdown = downloader.pmcid_to_markdown("PMC1884285")
markdowns = downloader.pmcid_to_markdown(["PMC1884285", "PMC6435416"])
# Skip supplementary materials
markdown = downloader.pmid_to_markdown("12895196", include_supplements=False)
Save markdown files to disk (single or batch):
from pubmed_markdown import PubMedMarkdown
downloader = PubMedMarkdown()
downloader.pmids_to_markdown_files(["12895196", "17872605"], save_dir="data")
# Also works with a single PMID
downloader.pmids_to_markdown_files("25051018", save_dir="data")
# Overwrite existing files
downloader.pmids_to_markdown_files(["12895196"], save_dir="data", overwrite=True)
This creates:
data/
├── html/ # Raw HTML from PMC
└── markdown/ # Converted markdown files
Full-text articles are saved as {PMCID}.md. Articles without open-access full text are saved as PMID{PMID}.md with abstract only.
Individual utility functions:
from pubmed_markdown import (
get_pmcid_from_pmid,
get_html_from_pmcid,
get_abstract_markdown_from_pmid,
fetch_bioc_supplement,
format_supplement_as_markdown,
)
# Resolve PMIDs to PMCIDs (returns dict mapping PMID -> PMCID or None)
mapping = get_pmcid_from_pmid(["12895196", "17872605"])
# Fetch raw HTML from PMC
html = get_html_from_pmcid("PMC1884285")
# Get abstract for non-open-access articles
abstract_md = get_abstract_markdown_from_pmid("12345678")
# Get raw supplementary material text
supplement = fetch_bioc_supplement("PMC6435416")
# Get supplementary materials formatted as a markdown section
supplement_md = format_supplement_as_markdown("PMC6435416")
Command Line
# Convert PMIDs from a file (one PMID per line)
pubmed-download --file_path=pmids.txt --save_dir=data
# Overwrite existing files
pubmed-download --file_path=pmids.txt --save_dir=data --overwrite
# Specify email directly
pubmed-download --file_path=pmids.txt --email=your-email@institution.edu
API Reference
| Method | Creates Files | Returns | Use Case |
|---|---|---|---|
pmid_to_markdown() |
No | Markdown string(s) | Single or batch, programmatic use |
pmcid_to_markdown() |
No | Markdown string(s) | Direct PMCID conversion |
pmids_to_markdown_files() |
Yes | None | Batch processing, building datasets |
pmids_to_pmcids() |
No | List of PMCIDs | PMID to PMCID resolution |
pmcids_to_html() |
Yes | None | Fetch and save raw HTML |
local_html_to_markdown() |
Yes | None | Re-convert existing HTML files |
All methods accepting IDs take either a single string or a list of strings.
How It Works
- PMID to PMCID -- Uses NCBI's ID Converter API with batching and rate limiting
- Multi-tier full-text extraction -- By default (
source="auto"), fetches JATS XML via NCBI E-utilitiesefetch(no WAF, works from cloud IPs), falls back to Europe PMCfullTextXML, and falls back to PMC HTML for publisher XML opt-outs or scanned articles. Passsource="html_first","xml", or"html"to customize the tier order. - Markdown conversion -- Converts JATS XML or PMC HTML to a consistent structured markdown schema preserving tables, figures, citations, and references
- Supplementary materials -- Fetches pre-processed supplement text via NCBI's BioC API
- Abstract fallback -- Articles not in PMC Open Access get abstract + metadata via NCBI E-Fetch
Configuration
| Environment Variable | Default | Description |
|---|---|---|
NCBI_EMAIL |
None | Email for NCBI API identification |
NCBI_API_KEY |
None | Optional NCBI API key (increases E-utilities rate limit from 3 to 10 req/s) |
Development
This project uses uv for environment management, testing, and publishing:
# Install dependencies (including dev tools and API server extras)
uv sync --all-extras
# Run tests
uv run pytest
# Format code
uv run black pubmed_markdown/ tests/ api.py
# Run the FastAPI server locally
uv run --extra api uvicorn api:app --host 0.0.0.0 --port 8000 --reload
# Build and publish a release to PyPI
rm -rf dist/ && uv build && uv publish
License
MIT
Metadata
Release files for pubmed-markdown 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pubmed_markdown-0.3.0.tar.gz | 62.3 kB | Without provenance | Details for pubmed_markdown-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pubmed_markdown-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for pubmed_markdown-0.3.0-py3-none-any.whl |
Total release size: 106.0 kB
Release files / pubmed_markdown-0.3.0.tar.gz
| Download URL | pubmed_markdown-0.3.0.tar.gz |
|---|---|
| Size | 62.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9e0379f5863679bffd5da9fadfd70d36cb7aa27308e7bb28ef6d21285d28b6a9
|
|
BLAKE2b-256 checksum How to use checksums |
64da2bbcb955a58e33eac99e287050ad3e6c7195ea85984c92e7bf1de612351a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / pubmed_markdown-0.3.0-py3-none-any.whl
| Download URL | pubmed_markdown-0.3.0-py3-none-any.whl |
|---|---|
| Size | 43.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d15e2f6842b2e047c9ef3b4a2cb24e541505a3baf704fb2a69232f5cd9081d1c
|
|
BLAKE2b-256 checksum How to use checksums |
01cfacb0efeb5b964c769916becfa78803bab425335ed62011ee4a2f495fdf61
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for pubmed-markdown 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.