pythonfilterbiopythonpubmed

Applying language filter to Entrez.esearch and Entrez.efetch


I'm querying PubMed for some results using Biopython. This is a portion of the code:

def search(query):
        Entrez.email = 'gandalf@rivendell.lotr'
        handle = Entrez.esearch(db   = 'pubmed',
                                sort = 'relevance',
                                retmax = '30000',
                                retmode = 'xml',
                                term = query)
        results = Entrez.read(handle)
        return results

I want to the results to have papers only in English. I checked the documentation at http://www.ncbi.nlm.nih.gov/books/NBK25499/ but found no attributes for this filter.

PubMed's manual search allows filtering by language. How should I modify the code?


Solution

  • You can modify the search term as shown below:

    query = "{} AND English[Language]".format(query)
    
    handle = Entrez.esearch(db='pubmed',
                            sort='relevance',
                            retmax='30',
                            retmode='xml',
                            term=query)