I would like to download a number of SARS-CoV-2 fastas from NCBI/Genbank using a web endpoint. I looked on their website but it's confusing.

I have the accession numbers, but can't figure out how to use the NCBI/Genbank Entrez API.

This is how I would do it using cov-spectrum: https://lapis.cov-spectrum.org/open/v1/sample/fasta?genbankAccession=MZ039713,MZ039682,OV522182

Is there something similar for NCBI/Genbank?

There must be a way, I just can't figure it out. The whole entrez thing is overwhelming to me, all I want is a simple API, like covSpectrum offers, for example. I scanned this but didn't help: https://www.ncbi.nlm.nih.gov/sars-cov-2/

E.g. how could I download all these SARS-CoV-2 nucleotide sequences with accession numbers: MZ039713,MZ039682 and OV522182 using a URL?

Some command line tools are advertised, but I don't want to have to use a CLI tool. Just a simple URL, does that not exist? CLI tools: https://www.ncbi.nlm.nih.gov/datasets/docs/v1/quickstarts/command-line-tools/

I also don't want to do any clicking through a web interface, just a URL so that other web apps can download it behind the scenes.

  • $\begingroup$ Could you please let us know which ones? $\endgroup$
    – M__
    Feb 22, 2022 at 13:38
  • $\begingroup$ @M__ what do you mean by "which ones"? For example fastas for these accession IDs: MZ039713, MZ039682 and OV522182 like displayed here: ncbi.nlm.nih.gov/nuccore/OV522182 $\endgroup$ Feb 22, 2022 at 13:42
  • 1
    $\begingroup$ Thanks I'll put a response together. Can't do it immediately, but will do today $\endgroup$
    – M__
    Feb 22, 2022 at 13:43

4 Answers 4


You can get the data from the API of the European Nucleotide Archive (ENA) which is synched with NCBI/GenBank:



You can try the NCBI Datasets API. We have an endpoint that would allow you to download virus sequences by accession The only thing to be aware (based on your list of accessions) is that our API needs the accession version to return results. In the case of your examples, they would need to be MZ039713.1, MZ039682.1 and OV522182.1. I hope this helps!

  • $\begingroup$ Thanks! Can you provide an example query? The API documentation is a bit overwhelming to me. Also, am I correct in assuming you need a private API key? $\endgroup$ Mar 3, 2022 at 20:47
  • 1
    $\begingroup$ You don't need a private API key. Using the accessions you provided as an example, you can create a json file (accessions.json): {"accessions":["MZ039713.1", "MZ039682.1", "OV522182.1"]} Then, you can use the following command to download everything using the API: cat accessions.json | curl -H "Content-Type: application/json" -X POST --data-binary @- "https://api.ncbi.nlm.nih.gov/datasets/v1/virus/genome/download" --output file.zip Let me know if you run into any issues. $\endgroup$
    – MirianT
    Mar 4, 2022 at 18:30

There are three ways to do this,

  1. If you click on this link Your NCBI examples. Its done.
  2. You would then just click "download"
  3. Click "next", click "next"

The sequence then downloads.

Essentially all I did was in the website click on the left hand navigation bar and clicked "accession number" and type in MZ039713 MZ039682 OV522182.

  1. The second way is to go to https://ncbi.nlm.nih.gov/nuccore
  2. Type type in MZ039713 MZ039682 OV522182
  3. Click on the "Summary" and click on "Fasta"
  4. Click on "send to" and click on "File"

I'm not certain is point 3 immediately above is required.

The final approach is to use efetch to automate the download, but that requires downloading the NCBI's efetch suite, which is then flipped through on a bash loop.

efetch -db nuccore -id MZ039682 -format fasta

The link for looking to automate is: https://www.ncbi.nlm.nih.gov/labs/virus/vssi/#/virus?SeqType_s=Nucleotide&VirusLineage_ss=SARS-CoV-2,%20taxid:2697049&ids=MZ039713%20MZ039682%20OV522182%20

Just to highlight MZ039713%20MZ039682%20OV522182%20

The API is here, but I don't use them.

  • $\begingroup$ Thanks! I clarified that I would like the download link to be programmatic = API, not needing to do any clicking in a web app. So do I understand it correctly that there really is no simple API to download these fastas? I need to download some efetch suite to do programmatic = non-interactive downloads? $\endgroup$ Feb 22, 2022 at 14:16

In the efetch.fcgi URL, you can set rettype=fasta to download the nucleotide sequence or rettype=fasta_cds_aa to download protein coding sequences:

$ curl 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=nuccore&rettype=fasta&id=NC_045512.2'|head -n3
>NC_045512.2 Severe acute respiratory syndrome coronavirus 2 isolate Wuhan-Hu-1, complete genome
$ curl 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=nuccore&rettype=fasta_cds_aa&id=NC_045512.2'|head -n3
>lcl|NC_045512.2_prot_YP_009724389.1_1 [gene=ORF1ab] [locus_tag=GU280_gp01] [db_xref=GeneID:43740578] [protein=ORF1ab polyprotein] [exception=ribosomal slippage] [protein_id=YP_009724389.1] [location=join(266..13468,13468..21555)] [gbkey=CDS]
New contributor
nisetama is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.