Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Example of using the Entrez API to get pubmed citations
## this little script shows off the use of the pubmed API through bioconductor
## requires installing Biopython (using pip)
## also requires installing the DTD files for each of the Entrez API calls,
## but the instructions for this are given when you run the script
## useful list of Entrez databases that can be queried through API
# pmc_pubmed PubMed citations for these articles
# pmc_refs_pubmed PubMed article citing PMC article
# pmc_pmc_cites PMC articles that given PMC article cites
# pmc_pmc_citedby PMC article citing given PMC article
# pubmed_pubmed Calculated set of PubMed citations similar to the selected article(s) retrieved using a word weight algorithm.
# pubmed_pubmed_refs Citation referenced in PubMed article. Only valid for PubMed citations that are also in PMC.
from Bio import Entrez = ""
def get_abstract(pmid):
handle = Entrez.efetch(db='pubmed', id=pmid, retmode='text', rettype='abstract')
def get_links_id(pmid):
link_list = []
links = Entrez.elink(dbfrom="pubmed", id=pmid, linkname="pubmed_pubmed")
record =
records = record[0][u'LinkSetDb'][0][u'Link']
for link in records:
return link_list
def get_links_term(term):
links = Entrez.esearch(db="pubmed", retmax = 1000, term=term)
record =
link_list = record[u'IdList']
return link_list
### MAIN -----------------------
print(get_links_term("Saffran JR[Author] "))
print "----------------------------"
print "----------------------------"

This comment has been minimized.

Show comment Hide comment

caspase8 Jan 3, 2018

How can I use this script to retrieve PMIDs for multiple 'terms'? Thanks a lot for the help.

caspase8 commented Jan 3, 2018

How can I use this script to retrieve PMIDs for multiple 'terms'? Thanks a lot for the help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment