Add your description here
Project description
BioThings Typed Client
A strongly-typed Python wrapper around the BioThings Client library, providing type safety and better IDE support through Python's type hints and Pydantic models.
Features
- Type Safety: Strongly typed models for all BioThings data using Pydantic
- IDE Support: Full autocompletion and type checking in modern IDEs
- Synchronous & Asynchronous: Support for both sync and async operations
- Helper Methods: Additional utility methods for common operations
- Validation: Runtime type checking and data validation
- Compatibility: Maintains full compatibility with the original BioThings client
Installation
Clone the Repository
git clone https://github.com/longevity-genie/biothings-typed-client.git
cd biothings-typed-client
Using pip
pip install biothings-typed-client
Using UV (Recommended)
UV is a fast Python package installer and resolver, written in Rust. It's designed to be a drop-in replacement for pip and pip-tools.
-
Install UV (if you haven't already):
curl -LsSf https://astral.sh/uv/install.sh | sh
-
Install the package:
uv sync -
To create a virtual environment and install dependencies:
uv venv source .venv/bin/activate # On Unix/macOS # or .venv\Scripts\activate # On Windows uv install biothings-typed-client
Quick Start
Synchronous Client
from biothings_typed_client.variants import VariantClient
# Initialize the client
client = VariantClient()
# Get a single variant
variant = client.getvariant("chr7:g.140453134T>C")
if variant:
print(f"Variant ID: {variant.get_variant_id()}")
print(f"Chromosome: {variant.chrom}")
print(f"Position: {variant.vcf.position}")
print(f"Reference: {variant.vcf.ref}")
print(f"Alternative: {variant.vcf.alt}")
# Get multiple variants
variants = client.getvariants(["chr7:g.140453134T>C", "chr9:g.107620835G>A"])
for variant in variants:
print(f"Found variant: {variant.get_variant_id()}")
# Query variants
results = client.query("dbnsfp.genename:cdk2", size=5)
for hit in results["hits"]:
print(f"Found variant: {hit['_id']}")
Asynchronous Client
import asyncio
from biothings_typed_client.variants import VariantClientAsync
async def main():
# Initialize the client
client = VariantClientAsync()
# Get a single variant
variant = await client.getvariant("chr7:g.140453134T>C")
if variant:
print(f"Variant ID: {variant.get_variant_id()}")
print(f"Has clinical significance: {variant.has_clinical_significance()}")
print(f"Has functional predictions: {variant.has_functional_predictions()}")
# Query variants
results = await client.query("dbnsfp.genename:cdk2", size=5)
print("\nQuery results:")
print(results)
# Run the async code
asyncio.run(main())
Gene Client Examples
Synchronous Gene Client
from biothings_typed_client.genes import GeneClient
# Initialize the client
client = GeneClient()
# Get a single gene
gene = client.getgene("1017") # Using Entrez ID
if gene:
print(f"Gene ID: {gene.id}")
print(f"Symbol: {gene.symbol}")
print(f"Name: {gene.name}")
# Get multiple genes
genes = client.getgenes(["1017", "1018"]) # Using Entrez IDs
for gene in genes:
print(f"Found gene: {gene.symbol} ({gene.name})")
# Query genes
results = client.query("symbol:CDK2", size=5)
for hit in results["hits"]:
print(f"Found gene: {hit['symbol']} ({hit['name']})")
# Batch query genes
genes = client.querymany(["CDK2", "BRCA1"], scopes=["symbol"], size=1)
for gene in genes:
print(f"Found gene: {gene['symbol']} ({gene['name']})")
Asynchronous Gene Client
import asyncio
from biothings_typed_client.genes import GeneClientAsync
async def main():
# Initialize the client
client = GeneClientAsync()
# Get a single gene
gene = await client.getgene("1017") # Using Entrez ID
if gene:
print(f"Gene ID: {gene.id}")
print(f"Symbol: {gene.symbol}")
print(f"Name: {gene.name}")
# Query genes
results = await client.query("symbol:CDK2", size=5)
print("\nQuery results:")
for hit in results["hits"]:
print(f"Found gene: {hit['symbol']} ({hit['name']})")
# Run the async code
asyncio.run(main())
Available Clients
The library currently provides the following typed clients:
VariantClient/VariantClientAsync: For accessing variant data- More clients coming soon...
Response Models
The library provides strongly-typed response models for all data types. For example, the VariantResponse model includes:
class VariantResponse(BaseModel):
id: str = Field(description="Variant identifier")
version: int = Field(description="Version number")
chrom: str = Field(description="Chromosome number")
hg19: GenomicLocation = Field(description="HG19 genomic location")
vcf: VCFInfo = Field(description="VCF information")
# Optional annotation fields
cadd: Optional[CADDScore] = None
clinvar: Optional[ClinVarAnnotation] = None
cosmic: Optional[CosmicAnnotation] = None
dbnsfp: Optional[DbNSFPPrediction] = None
dbsnp: Optional[DbSNPAnnotation] = None
# ... and more
Helper Methods
The response models include useful helper methods:
# Get a standardized variant ID
variant.get_variant_id()
# Check for clinical significance
variant.has_clinical_significance()
# Check for functional predictions
variant.has_functional_predictions()
Development
Running Tests
pytest tests/
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file biothings_typed_client-0.0.1.tar.gz.
File metadata
- Download URL: biothings_typed_client-0.0.1.tar.gz
- Upload date:
- Size: 47.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d8cf9fc60d09147dbee42e5fd15dcb3320bce034317c4a0677102afd85204009
|
|
| MD5 |
e5eb4bc43c7bc138ac8d9c390c1ab54d
|
|
| BLAKE2b-256 |
29e026583ed3ce1924478ccc6838d5bb376264425bf0a56c0a9a885313e7b8c7
|
File details
Details for the file biothings_typed_client-0.0.1-py3-none-any.whl.
File metadata
- Download URL: biothings_typed_client-0.0.1-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0207b1fbe642266f5bf2157a4856c81ab60648f878db0494184afee2ff8752d1
|
|
| MD5 |
a2c61e219c4ae756a70a94ee68417c11
|
|
| BLAKE2b-256 |
8f23061bd68d34b0df9a7aa24381e87e90b6cd28b42de9386875e86bd0e44676
|