Python SDK for the Aither platform - contextual intelligence and model observability
Project description
aither
Python SDK for the Aither platform - contextual intelligence and model observability.
Features
- OTLP Native: Uses OpenTelemetry Protocol for efficient, standardized data transfer
- Non-blocking: Predictions are logged asynchronously without blocking your application
- Automatic batching: Multiple predictions are sent in batches for efficiency
- Label correlation: Track ground truth labels with trace ID correlation
- Zero latency impact: Background worker handles all API communication
Installation
pip install aither
Quick Start
import aither
# Initialize with your API key
aither.init(api_key="aith_your_api_key")
# Log a prediction - returns trace_id for label correlation
trace_id = aither.log_prediction(
model_name="fraud_detector",
features={"amount": 150.0, "country": "US"},
prediction=0.87,
)
# Later, when you know the ground truth:
aither.log_label(trace_id=trace_id, label=1) # Was actually fraud
Configuration
Environment Variables
export AITHER_API_KEY="aith_your_api_key"
export AITHER_ENDPOINT="https://aither.computer" # optional
Explicit Initialization
import aither
aither.init(
api_key="aith_your_api_key",
endpoint="https://aither.computer",
flush_interval=1.0, # seconds between flushes
batch_size=100, # max predictions per batch
)
API Reference
aither.init(api_key=None, endpoint=None, flush_interval=1.0, batch_size=100)
Initialize the global client.
api_key: Your Aither API key (or setAITHER_API_KEYenv var)endpoint: API endpoint URL (default:https://aither.computer)flush_interval: How often to flush queued predictions in secondsbatch_size: Maximum predictions per batch request
aither.log_prediction(...) -> str
Log a model prediction (non-blocking). Returns a trace_id for label correlation.
trace_id = aither.log_prediction(
model_name="fraud_detector", # Required: model identifier
features={"amount": 150.0}, # Required: input features
prediction=0.87, # Required: prediction value
# Optional parameters:
version="1.2.3", # Model version
probabilities=[0.13, 0.87], # Class probabilities
classes=["legit", "fraud"], # Class labels
environment="production", # Deployment environment
request_id="req-abc123", # Request identifier
user_id="user-anonymized-hash", # User identifier (anonymized)
)
Returns: trace_id (hex string) for correlating ground truth labels.
aither.log_label(trace_id, label)
Log ground truth for a previous prediction (non-blocking).
aither.log_label(
trace_id=trace_id, # From log_prediction()
label=1, # Actual outcome
)
aither.flush()
Force immediate flush of all queued data (blocking).
aither.log_prediction(model_name="my-model", features={}, prediction=0.5)
aither.flush() # Wait for all data to be sent
aither.close()
Close the global client and flush remaining data.
aither.close() # Flush and shutdown background worker
Usage Patterns
Basic Prediction Logging
import aither
aither.init(api_key="aith_...")
# Log prediction, get trace_id
trace_id = aither.log_prediction(
model_name="churn_predictor",
features={"tenure": 24, "monthly_charges": 65.5},
prediction=0.73,
)
# Store trace_id with your prediction for later label correlation
save_to_database(prediction_id, trace_id)
Ground Truth Correlation
# Later, when ground truth is known:
trace_id = get_trace_id_from_database(prediction_id)
aither.log_label(trace_id=trace_id, label="churned")
Classification with Probabilities
trace_id = aither.log_prediction(
model_name="sentiment_classifier",
features={"text": "Great product!"},
prediction="positive",
probabilities=[0.05, 0.15, 0.80],
classes=["negative", "neutral", "positive"],
version="2.1.0",
environment="production",
)
FastAPI Integration
import aither
from fastapi import FastAPI
aither.init(api_key="aith_...")
app = FastAPI()
@app.post("/predict")
async def predict(data: dict):
prediction = model.predict(data)
# Non-blocking - returns instantly
trace_id = aither.log_prediction(
model_name="my-model",
features=data,
prediction=prediction,
)
return {"prediction": prediction, "trace_id": trace_id}
@app.post("/label")
async def label(trace_id: str, actual: int):
aither.log_label(trace_id=trace_id, label=actual)
return {"status": "ok"}
@app.on_event("shutdown")
async def shutdown():
aither.close() # Flush remaining data
Using the Client Directly
from aither import AitherClient
# With background worker (default)
client = AitherClient(
api_key="aith_...",
flush_interval=1.0,
batch_size=100,
)
trace_id = client.log_prediction(
model_name="my-model",
features={"x": 1},
prediction=0.5,
)
client.log_label(trace_id=trace_id, label=1)
client.close()
# Immediate mode (blocking, no background worker)
with AitherClient(api_key="aith_...", enable_background=False) as client:
client.log_prediction(...) # Sends immediately
Data Format
The SDK uses OTLP (OpenTelemetry Protocol) to send predictions as spans with ml.* attributes:
| Attribute | Description |
|---|---|
ml.model.name |
Model identifier |
ml.model.version |
Model version |
ml.features |
JSON-encoded input features |
ml.prediction |
JSON-encoded prediction value |
ml.prediction.probabilities |
Class probabilities |
ml.prediction.classes |
Class labels |
ml.label |
Ground truth value |
ml.environment |
Deployment environment |
ml.request_id |
Request identifier |
ml.user_id |
User identifier |
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
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 aither-0.2.0.tar.gz.
File metadata
- Download URL: aither-0.2.0.tar.gz
- Upload date:
- Size: 68.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a6c2e72b6d18073e8219d55bc6132c98762270f3994ef714d7d43ace4b1eadc
|
|
| MD5 |
d296812fd008d14a9e582f06aec5164a
|
|
| BLAKE2b-256 |
5868a8f550980595c43e21f53f40f8a0d76755e21a3174f2ec635b45425c589c
|
Provenance
The following attestation bundles were made for aither-0.2.0.tar.gz:
Publisher:
publish.yml on aither-computer/aither-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aither-0.2.0.tar.gz -
Subject digest:
6a6c2e72b6d18073e8219d55bc6132c98762270f3994ef714d7d43ace4b1eadc - Sigstore transparency entry: 870893608
- Sigstore integration time:
-
Permalink:
aither-computer/aither-sdk@df65995eb0ad8f01b1f9f58331173dc557ccdddc -
Branch / Tag:
refs/heads/main - Owner: https://github.com/aither-computer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@df65995eb0ad8f01b1f9f58331173dc557ccdddc -
Trigger Event:
push
-
Statement type:
File details
Details for the file aither-0.2.0-py3-none-any.whl.
File metadata
- Download URL: aither-0.2.0-py3-none-any.whl
- Upload date:
- Size: 17.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d26834574e85ce1a6e70342dd6f818fcb8915eda26f758203994b0bbe0604f6
|
|
| MD5 |
bfdf3696baff54ea7c0f7b230fe0c9f2
|
|
| BLAKE2b-256 |
d60cd47047517843c9badece72315cd3c33b52ef185be6ca7098668d063f46bf
|
Provenance
The following attestation bundles were made for aither-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on aither-computer/aither-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aither-0.2.0-py3-none-any.whl -
Subject digest:
2d26834574e85ce1a6e70342dd6f818fcb8915eda26f758203994b0bbe0604f6 - Sigstore transparency entry: 870893611
- Sigstore integration time:
-
Permalink:
aither-computer/aither-sdk@df65995eb0ad8f01b1f9f58331173dc557ccdddc -
Branch / Tag:
refs/heads/main - Owner: https://github.com/aither-computer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@df65995eb0ad8f01b1f9f58331173dc557ccdddc -
Trigger Event:
push
-
Statement type: