Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Searching PubMed with Biopython
# This code uses Biopython to retrieve lists of articles from pubmed
# you need to install Biopython first.
# If you use Anaconda:
# conda install biopython
# If you use pip/venv:
# pip install biopython
# Full discussion:
from Bio import Entrez
def search(query): = ''
handle = Entrez.esearch(db='pubmed',
results =
return results
def fetch_details(id_list):
ids = ','.join(id_list) = ''
handle = Entrez.efetch(db='pubmed',
results =
return results
if __name__ == '__main__':
results = search('fever')
id_list = results['IdList']
papers = fetch_details(id_list)
for i, paper in enumerate(papers['PubmedArticle']):
print("{}) {}".format(i+1, paper['MedlineCitation']['Article']['ArticleTitle']))
Copy link

echorule commented Dec 6, 2022

This is awesome thanks and works pretty well. I'm stuck on trying to get the details of the authors in a succinct way, can anybody help with how to do that? paper['MedlineCitation']['Article']['AuthorList'] isnt right....
Thanks in advance!

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