Using Entrez.efetch() to retrive .fasta file from any NCBI database? I tried to use these python codes to retrieve a .fasta file from gene database, but the output were the parameters of the report
from Bio import Entrez
Entrez.email = &quot;send_helps@earth.com&quot;
handle = Entrez.efetch(db = &quot;gene&quot;,id = &quot;682&quot;,rettype=&quot;fasta&quot;, retmode=&quot;xml&quot;)
print(Entrez.read(handle))

i also read the documentation on this site about efetch() and seems like this function can only retrieve certain kinds of data for each database. So i can't take fasta file from gene database !?
I don't want to use the NCBI web UI. What's wrong with my code? Is there a way i can guarantee to retreive a .fasta file through python from NCBI ? Am i misundertanding something severly ?
Sorry for bad English. thank you.
In order to download the FASTA sequence of transcript variants using Entrez eutilities, you will have to use Entrez.elink to get a list of transcript accessions for the gene of interest and then use Entrez.efetch to fetch the sequence(s). Just to give you an idea, you can use Entrez Direct for this as follows:
elink -db gene -id 682 -target nuccore -name gene_nuccore_refseqrna \
  | efetch -format fasta

You can find more Entrez Link descriptions here. Note, there is a gene_fasta option for efetch but it still returns only the transcript sequence (i.e., no intron sequence).
If you need the full gene sequence (including the intronic regions), you can use the commands mentioned here.
Alternatively, you can use NCBI Datasets for this. You can use the web interface, command line tool or the python API. This page with the how-to articles has the information you seek.