Comprehensive Python client for the Uniprot REST API
Project description
Unipressed
Please visit the project website for more comprehensive documentation.
Introduction
Unipressed (Uniprot REST) is an API client for the protein database Uniprot. It provides thoroughly typed and documented code to ensure your use of the library is easy, fast, and correct!
Example
Let's say we're interested in very long proteins that are encoded within a chloroplast, in any organism:
import json
from unipressed import UniprotkbSearch
for record in UniprotkbSearch(
query={
"and_": [
{"organelle": "chloroplast"},
{"length": (5000, "*")}
]
},
fields=["length", "gene_names"]
).each_record():
print(json.dumps(record, indent=4))
This will print:
{
"primaryAccession": "A0A088CK67",
"genes": [
{
"geneName": {
"evidences": [
{
"evidenceCode": "ECO:0000313",
"source": "EMBL",
"id": "AID67672.1"
}
],
"value": "ftsH"
}
}
],
"sequence": {
"length": 5242
}
}
Advantages
- Detailed type hints for autocompleting queries as you type
- Autocompletion for return fields
- Documentation for each field
- Automatic results parsing, for
json
,tsv
,list
, andxml
- Built-in pagination, so you don't have to handle any of that yourself!
- Most of the API is automatically generated, ensuring very rapid updates whenever the API changes
- Thoroughly tested, with 41 unit tests and counting!
Usage
Installation
If you're using poetry:
poetry add unipressed
Otherwise:
pip install unipressed
Query Syntax
You can't go wrong by following the type hints.
I strongly recommend using something like pylance
for Visual Studio Code, which will provide automatic completions and warn you when you have used the wrong syntax.
If you already know how to use the Uniprot query language, you can always just input your queries as strings:
UniprotkbSearch(query="(gene:BRCA*) AND (organism_id:10090)")
However, if you want some built-in query validation and code completion using Python's type system, then you can instead use a dictionary. The simplest query is a dictionary with a single key:
{
"family": "kinase"
}
You can compile more complex queries using the and_
, or_
and not_
keys.
These first two operators take a list of query dictionaries:
{
"and_": [
{"family": "kinase"},
{"organism_id": "9606"},
]
}
Most "leaf" nodes of the query tree (ie those that aren't operators like and_
) are strings.
A few are integers or floats, and a few are ranges, which you input using a tuple with two elements, indicating the start and end of the range.
If you use the literal "*"
then you can leave the range open at one end.
For example, this query returns any protein that is in the range $(5000, \infty)$
{"length": (5000, "*")}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for unipressed-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 424d4ac770d31c6cb23bce5bac076fb026d3a1fd7f4b4906aea848a267756594 |
|
MD5 | 725e7a97eb8eae70562443f675039e90 |
|
BLAKE2b-256 | d738fb2927ed672bad53167f571535b2857c2e291bf99cf0df5e092d6043db74 |