Query UniProt's REST API (https://rest.uniprot.org/). Encodes the 2022 endpoint migration (legacy https://www.uniprot.org/uniprot/... is deprecated; JSON schema changed substantially), the four UniProt resources (UniProtKB / UniRef / UniParc / Proteomes), search vs stream vs accessions endpoint trade-offs, isoform handling (P04637-2 suffix), async ID-mapping job pattern, the critical ?fields= for bulk pulls, and the Swiss-Prot vs TrEMBL distinction.
pip install requests pandas
No API key required. Rate limit generous (~200 req/sec). ID-mapping has its own job queue.
fields= parameter to keep payload small""Fetch UniProt P04637 as JSON and pull: primaryAccession, uniProtkbId, proteinDescription.recommendedName.fullName.value, genes[0].geneName.value, sequence.value, and all PDB cross-refs. Use .get() chains for every nested field -- the schema is deeply nested and some fields are optional."
"Search human reviewed kinases. Use /search with format=tsv and fields=accession,gene_primary,protein_name,length,xref_pdb,xref_alphafolddb,size=500. Don't omit fields= -- default returns full JSON entries (~20-30 KB each) and 500 of them is 15 MB."
"I want all human Swiss-Prot entries (~20,000). The /search endpoint caps at 500/page. Use /stream with fields=accession,gene_primary,length to stream all results in one HTTP response."
"Convert 100 Ensembl Gene IDs to UniProt accessions. Use POST /idmapping/run with from=Ensembl, to=UniProtKB. Poll /idmapping/status/{jobId} every 3 seconds with a 600-second timeout (jobs can hang). Retrieve via /idmapping/results/{jobId}."
"TP53 (P04637) has multiple isoforms. The bare P04637 fetch returns the canonical sequence only. Walk comments[type=ALTERNATIVE PRODUCTS].isoforms; for each isoform, fetch P04637-2.fasta, P04637-3.fasta, etc."
"These accessions from a 2015 paper may be obsolete or merged. Run ID mapping from=UniProtKB_AC-ID, to=UniProtKB to resolve to current primary accessions before fetching."
rest.uniprot.org); flag legacy URLs as broken.fields= explicitly to control payload./stream not /search.reviewed:true for reference-quality analyses (avoids 250M TrEMBL).organism_id:9606 to scope by species..get() chains and defensive defaults.-N suffixed accession separately; canonical is the default.https://www.uniprot.org/uniprot/... URLs may redirect but the JSON schema is the new one -- old field paths break.?fields= is essential for bulk; without it each entry is 20-30 KB JSON.reviewed:true) is ~570K entries; TrEMBL (auto-annotated) is ~250M. Always filter for reference work.-N suffix; the bare accession is the canonical sequence only.gene:TP53 matches across species; combine with organism_id:9606 for specificity.gene_exact: avoids wildcard matches that gene: allows./proteomes/{upid}.fasta.gz -- e.g. UP000005640 is human.