Python SDK for microCafe - AI-powered microbiome analysis
Project description
microCafe Python SDK
Official Python SDK for microCafe — AI-powered microbiome analysis.
Installation
pip install microcafe
Quick Start
from microcafe import Client
# Auto-reads API key from env var or ~/.microcafe/config.json
client = Client()
# Or pass explicitly
client = Client(api_key="mc_your_key_here")
# Classify a single sequence
result = client.classify("ATCGATCGATCG...")
print(result.predictions[0].genus) # "Bacteroides"
print(result.predictions[0].confidence) # 0.95
# Classify a file (submits, polls, returns abundance)
summary = client.classify_file("sequences.fq")
print(summary.summary.raw_counts) # {"Bacteroides": 150, "Prevotella": 80}
print(summary.summary.relative_abundance) # {"Bacteroides": 65.2, "Prevotella": 34.8}
CLI Usage
# Save API key (stored in ~/.microcafe/config.json)
microcafe configure mc_your_key_here
# Classify a single sequence
microcafe classify "ATCGATCGATCG..."
microcafe classify "ATCGATCG..." --format json
# Classify a file (submits, shows progress bar, returns abundance)
microcafe classify-file sequences.fq
microcafe classify-file sequences.fq --output results.json
microcafe classify-file sequences.fq --format json
# Check job status
microcafe status <job_id>
microcafe status <job_id> --wait # poll until complete
# Get abundance table
microcafe abundance <job_id>
microcafe abundance <job_id> --top 20 # show top 20 genera
microcafe abundance <job_id> --output abundance.json
# Get per-sequence predictions
microcafe predictions <job_id>
microcafe predictions <job_id> --output predictions.json
Python API Reference
Client
from microcafe import Client
# Auto-resolves API key from env var or config file
client = Client()
# Or configure explicitly
client = Client(
api_key="mc_xxx", # Optional if env var or config file is set
base_url="https://...", # Optional, default: https://microcafe.ai/api
timeout=300 # Optional, request timeout in seconds
)
Single Sequence Classification
result = client.classify(
sequence="ATCGATCG...",
top_k=5 # Number of top predictions
)
print(result.sequence_length)
for pred in result.predictions:
print(f"{pred.genus}: {pred.confidence}")
File Classification
# Submits file, polls for progress, returns abundance summary
summary = client.classify_file(
file_path="sequences.fq",
top_k=5,
poll_interval=2.0, # Seconds between status checks
on_progress=lambda s: print(f"{s.progress}%") # Optional callback
)
print(summary.summary.raw_counts)
print(summary.summary.relative_abundance)
Job Management
# Submit file (returns immediately)
job = client.classify_file_async("sequences.fq")
print(job.job_id)
# Check status
status = client.get_job_status(job.job_id)
print(f"{status.progress}% — {status.sequences_processed}/{status.total_sequences}")
# Wait for completion
final_status = client.wait_for_job(job.job_id)
# Get results
abundance = client.get_job_summary(job.job_id) # abundance table
predictions = client.get_job_results(job.job_id) # per-sequence predictions
Environment Variables
export MICROCAFE_API_KEY=mc_your_key_here
# No need to pass api_key if env var is set
client = Client()
Error Handling
from microcafe import Client, MicroCafeError, RateLimitError, AuthenticationError
try:
result = client.classify("ATCG...")
except RateLimitError as e:
print(f"Rate limited. Retry after {e.retry_after} seconds")
except AuthenticationError:
print("Invalid API key")
except MicroCafeError as e:
print(f"Error: {e.message}")
Supported File Formats
- FASTA (
.fasta,.fa) - FASTQ (
.fastq,.fq)
Links
License
MIT
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
microcafe-0.1.0.tar.gz
(11.1 kB
view details)
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
microcafe-0.1.0-py3-none-any.whl
(14.8 kB
view details)
File details
Details for the file microcafe-0.1.0.tar.gz.
File metadata
- Download URL: microcafe-0.1.0.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef596284b4a24d62b2ea44d75646cdd3483750ba99c48f1c72441f709e3ffc3b
|
|
| MD5 |
50f8f4b4a9b8cb55efa120994304d704
|
|
| BLAKE2b-256 |
54e486860692f22e44add039eafa0be016bf72059d93eac3f11d0caf98aa3cc9
|
File details
Details for the file microcafe-0.1.0-py3-none-any.whl.
File metadata
- Download URL: microcafe-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea12c480470ae347763465393070badaecb35fe051fe2f61262290785ae165b7
|
|
| MD5 |
37030cd7c84da268d921ad652c56495d
|
|
| BLAKE2b-256 |
a668fba67ddcf5497f9d3bd90554b665102f7405184724a0ea8ec39dcc571187
|