Retrieve full records (EFetch) or lightweight document summaries (ESummary) from NCBI databases using Biopython's Bio.Entrez. The skill encodes the rettype/retmode decision matrix per database, ESummary-vs-EFetch triage for bulk metadata work, GI deprecation (records after 2017 have only accession.version), the gbwithparts trap for WGS assemblies, XML schema drift, and accession-versioning for reproducible analyses.
pip install biopython
from Bio import Entrez, SeqIO
Entrez.email = 'researcher@institution.edu'
Entrez.api_key = 'optional_api_key' # raises rate to 10 req/sec
"I have 8,000 nucleotide UIDs. I only need the organism, accession.version, and sequence length. Use ESummary in chunks of 500, not EFetch -- it's an order of magnitude cheaper."
"Fetch GenBank for NM_007294 but lock the result to whatever specific .version is current today. Save the accession.version so reruns next year fetch the same record content."
"Fetch the genome assembly for WGS accession ABFD01000000 -- use rettype='gbwithparts' so the CONTIG sequences are inlined, otherwise the record comes back with no actual sequence."
"Download all CDS translations from RefSeq NC_000913.3 (E. coli K-12) using rettype='fasta_cds_aa'. Don't walk the GenBank features manually -- let NCBI do the extraction server-side."
"Convert these SRA UIDs to SRR run accessions plus Bases/Spots/AvgLength metrics using EFetch with rettype='runinfo'. Parse the CSV and return as a DataFrame."
(rettype, retmode) triple appropriate for the source database -- never default-guess.accession.version instead of legacy GI numbers.rettype='gbwithparts' to inline the sequence.SeqIO (sequences) or Entrez.read() (XML); use .get() defensively for nested XML fields.LOCUS, >, <?xml) before parsing -- guard against HTML error pages.NM_007294 resolves to whatever version is current; this is fine for exploration but breaks reproducibility. Always pin .version for published analyses.rettype='medline' parsed with Bio.Medline.parse() is more schema-stable than the XML route -- preferred for long-lived parsers.gb rettype on a WGS / assembly record returns the CONTIG join() statement but NOT the sequence. Use gbwithparts for assemblies; check len(record.seq) after parsing.Entrez.epost first; see batch-downloads).taxonomy db to get the TXID, then EFetch with db=taxonomy for the lineage -- never assume a TXID from memory.