PubMedFetcher Object Documentation

The PubMedFetcher object in the metapub library is a tool for interacting with PubMed's vast database of biomedical literature. It provides various methods to search for articles, retrieve metadata, and access full-text content. This documentation covers the available methods, keywords, and advanced query characteristics.

Initialization

from metapub import PubMedFetcher

fetch = PubMedFetcher()

Methods

__init__(self, method='eutils', **kwargs)

Initializes the PubMedFetcher object with the specified method. Currently, only the 'eutils' method is supported.

Parameters:

Example:

fetch = PubMedFetcher()

article_by_pmid(pmid)

Fetches an article by its PubMed ID (PMID).

Parameters:

Returns:

Example:

article = fetch.article_by_pmid('12345678')

article_by_pmcid(pmcid)

Fetches an article by its PubMed Central ID (PMCID).

Parameters:

Returns:

Example:

article = fetch.article_by_pmcid('PMC1234567')

article_by_doi(doi)

Fetches an article by its Digital Object Identifier (DOI).

Parameters:

Returns:

Example:

article = fetch.article_by_doi('10.1038/ng.379')

pmids_for_query(query='', since=None, until=None, retstart=0, retmax=250, pmc_only=False, **kwargs)

Returns a list of PMIDs for a given freeform query string and keyword arguments.

Parameters:

Returns:

Example:

pmids = fetch.pmids_for_query('cancer genomics', retmax=5)

pmids_for_clinical_query(query, category, optimization='broad', since=None, until=None, retstart=0, retmax=250, pmc_only=False, **kwargs)

Returns a list of PMIDs for a clinical query in a specified category.

Parameters:

Returns:

Example:

pmids = fetch.pmids_for_clinical_query('cancer', 'therapy')

pmids_for_medical_genetics_query(query, category='all', since=None, until=None, retstart=0, retmax=250, pmc_only=False, **kwargs)

Returns a list of PMIDs for a medical genetics query in a specified category.

Parameters:

Returns:

Example:

pmids = fetch.pmids_for_medical_genetics_query('BRCA1', 'diagnosis')

pmids_for_citation(**kwargs)

Returns a list of PMIDs for a given citation. Requires at least 3 of the following details: journal title, year, volume, first page, author name.

Parameters:

Returns:

Example:

pmids = fetch.pmids_for_citation(journal='Science', year='2008', volume='4', first_page='7', author_name='Grant')

related_pmids(pmid)

Returns related PMIDs for a given PMID, organized by type of relation.

Parameters:

Returns:

Example:

related = fetch.related_pmids('12345678')

pmid_for_bookID(book_id)

Returns the PMID for a given NCBI Book ID.

Parameters:

Returns:

Example:

pmid = fetch.pmid_for_bookID('NBK2020')

Keywords and Advanced Query Characteristics

PubMed supports a variety of keywords and query characteristics to refine searches. Here are some examples:

Basic Keywords

Example:

articles = fetch.pmids_for_query('author:"Smith J" AND title:"cancer"')

Boolean Operators

Example:

articles = fetch.pmids_for_query('cancer AND genomics NOT review')

Field Tags

Example:

articles = fetch.pmids_for_query('cancer[ti] AND Smith J[au]')

Date Filters

Example:

articles = fetch.pmids_for_query('cancer genomics AND ("2020/01/01"[dp] : "2020/12/31"[dp])')

Additional Filters

Example:

articles = fetch.pmids_for_query('cancer genomics AND Review[pt]')

Handling Results

Results returned from search queries or fetch methods are typically lists of PMIDs. These PMIDs can

be further used to fetch detailed article information.

Example:

for pmid in pmids:
    article = fetch.article_by_pmid(pmid)
    print(f"Title: {article.title}")
    print(f"Authors: {', '.join(article.authors)}")
    print(f"Journal: {article.journal}")
    print(f"DOI: {article.doi}")
    print(f"Abstract: {article.abstract}")
    print()