<p>Biopython has an efetch frontend.</p>
<pre><code>from Bio import Entrez
Entrez.email = &quot;mg@example.edu&quot; 
handle = Entrez.efetch(db=&quot;nucleotide&quot;, id=&quot;KR052012.1&quot;, rettype=&quot;gb&quot;, retmode=&quot;text&quot;)
print(handle.read())
</code></pre>
<hr />
<p><strong>OUT</strong></p>
<p>LOCUS       KR052012               10714 bp    RNA     linear   VRL 09-MAY-2015
DEFINITION  Dengue virus strain Hb33/CHN/2014, complete genome.
ACCESSION   KR052012
VERSION     KR052012.1
KEYWORDS<br />
.... etc</p>
<p>You will likely need to perform an EFetch search and then extract out the accession numbers for import (as done above)</p>

CC BY-SA 4.0
2019-09-05T12:04:10.667Z
2022-03-11T17:26:51.983Z
2022-03-11T17:26:51.983Z
M__
<blockquote>
  <p><em>This isn't a Python library, but it's easily invoked from Python code, easy to install, and has a lot of useful features.</em></p>
</blockquote>

<p>I just discovered the amazing <a href="https://github.com/shenwei356/taxonkit/" rel="nofollow noreferrer">taxonkit library</a> this week. In particular, the <a href="https://bioinf.shenwei.me/taxonkit/usage/#name2taxid" rel="nofollow noreferrer"><code>taxonkit name2taxid</code> command</a> seems to be what you're looking for.</p>

<pre><code>$ cat NAMES
Polistes dominula
Sinorhizobium meliloti
Gossypium hirsutum
$ cat NAMES | taxonkit name2taxid
Polistes dominula       743375
Sinorhizobium meliloti  382
Gossypium hirsutum      3635
</code></pre>

<p>Easily installed using <code>conda install taxonkit</code>.</p>

CC BY-SA 4.0
2020-04-25T21:37:03.490Z
2020-04-25T21:37:03.490Z
Daniel Standage
<p>If you want to perform a species search, here's the raw efetch code. I use this within an alias and the complex quotes are needed for complicated reasons. The reg-ex may need to be adapted to your search. $virus here is your species of interest, e.g. <code>set virus='some species'</code> (csh or tcsh), `virus='some species' (bash). You'll just need to translate this to Biopython.</p>

<pre><code>alias esummary-acc \
'esearch -db protein -query "<span class="math-container">$virus" |\
efetch -format docsum |\
xtract -pattern DocumentSummary -element Title,AccessionVersion |\
grep "$</span>virus" |\
perl -p -e '"'"'s/^.*\[.*\]\s+(\w+)/$1/'"'"''
</code></pre>

CC BY-SA 4.0
2019-09-05T14:26:53.857Z
2019-09-05T14:26:53.857Z
M__
<p>I have a list of scientific names of species. Is there a python module that can fetch <a href="https://www.ncbi.nlm.nih.gov/Taxonomy/TaxIdentifier/tax_identifier.cgi" rel="nofollow noreferrer">NCBI taxonomy IDs</a>? </p>

CC BY-SA 4.0
2019-09-05T09:35:16.760Z
Biopython has a collection of NCBI Entrez query modules. Please check this StackOverflow thread.
https://stackoverflow.com/questions/16504238/attempting-to-obtain-taxonomic-information-from-biopython
arup
<python><ngs><genomics><metagenome><taxonomy>
Python module for fetching NCBI id for a list of species
# Python module for fetching NCBI id for a list of species

(Asked by: username_0 on 2019-09-05)

I have a list of scientific names of species. Is there a python module that can fetch [NCBI taxonomy IDs](https://www.ncbi.nlm.nih.gov/Taxonomy/TaxIdentifier/tax_identifier.cgi)?

**Tags:** python, ngs, genomics, metagenome, taxonomy
> **Comments:**
> **username_1**: Biopython has a collection of NCBI Entrez query modules. Please check this StackOverflow thread. https://stackoverflow.com/questions/16504238/attempting-to-obtain-taxonomic-information-from-biopython  

---

## 3 answers

### Answer by username_2 on 2019-09-05. Score: 1

Biopython has an efetch frontend.
from Bio import Entrez
Entrez.email = "mg@example.edu" 
handle = Entrez.efetch(db="nucleotide", id="KR052012.1", rettype="gb", retmode="text")
print(handle.read())


OUT
LOCUS       KR052012               10714 bp    RNA     linear   VRL 09-MAY-2015
DEFINITION  Dengue virus strain Hb33/CHN/2014, complete genome.
ACCESSION   KR052012
VERSION     KR052012.1
KEYWORDS
.... etc
You will likely need to perform an EFetch search and then extract out the accession numbers for import (as done above)


---

### Answer by username_3 on 2020-04-25. Score: 1

This isn't a Python library, but it's easily invoked from Python code, easy to install, and has a lot of useful features.

I just discovered the amazing taxonkit library this week. In particular, the taxonkit name2taxid command seems to be what you're looking for.
$ cat NAMES
Polistes dominula
Sinorhizobium meliloti
Gossypium hirsutum
$ cat NAMES | taxonkit name2taxid
Polistes dominula       743375
Sinorhizobium meliloti  382
Gossypium hirsutum      3635

Easily installed using conda install taxonkit.


---

### Answer by username_2 on 2019-09-05. Score: 0

If you want to perform a species search, here's the raw efetch code. I use this within an alias and the complex quotes are needed for complicated reasons. The reg-ex may need to be adapted to your search. $virus here is your species of interest, e.g. set virus='some species' (csh or tcsh), `virus='some species' (bash). You'll just need to translate this to Biopython.
alias esummary-acc \
'esearch -db protein -query "$virus" |\
efetch -format docsum |\
xtract -pattern DocumentSummary -element Title,AccessionVersion |\
grep "$virus" |\
perl -p -e '"'"'s/^.*\[.*\]\s+(\w+)/$1/'"'"''


---

