Quick Start Guide
This guide will help you get started with Metapub quickly.
Basic PubMed Search
from metapub import PubMedFetcher
# Create a fetcher instance
fetch = PubMedFetcher()
# Search for papers on a topic
pmids = fetch.pmids_for_query('machine learning', retmax=10)
# Get article details
for pmid in pmids:
article = fetch.article_by_pmid(pmid)
print(f"PMID {pmid}: {article.title}")
print(f"Authors: {', '.join([str(a) for a in article.authors])}")
print(f"Journal: {article.journal}")
print("---")
Retrieving Article by PMID
from metapub import PubMedFetcher
fetch = PubMedFetcher()
article = fetch.article_by_pmid('12345678')
print(f"Title: {article.title}")
print(f"Abstract: {article.abstract}")
print(f"DOI: {article.doi}")
print(f"Publication Date: {article.year}")
Finding Full Text with FindIt
from metapub import FindIt
# Try to find full text for a paper
src = FindIt('12345678') # PMID
if src.url:
print(f"Full text available at: {src.url}")
else:
print(f"Could not find full text: {src.reason}")
Working with MedGen
from metapub import MedGenFetcher
mg = MedGenFetcher()
# Search for a condition
concepts = mg.concepts_for_term('diabetes')
for concept in concepts:
print(f"CUI: {concept.cui}")
print(f"Name: {concept.name}")
print(f"Definition: {concept.definition}")
Command Line Tools
Metapub includes several command line utilities:
# Convert between IDs
convert pmid2doi 12345678
convert doi2pmid 10.1038/nature12373
# Get article information
pubmed_article 12345678
# Check NCBI health
ncbi_health_check
Next Steps
Check out the metapub for detailed API documentation
See Examples for more advanced usage patterns
Read about specific modules like metapub.findit package for FindIt functionality