Unified entry point for Respan tracing and instrumentation plugins
Project description
Respan Python SDK
respan.ai | Documentation | PyPI
A comprehensive Python SDK for Respan monitoring, evaluation, and analytics APIs. Build, test, and evaluate your AI applications with ease.
🚀 Features
- 📊 Dataset Management - Create, manage, and analyze datasets from your AI logs
- 🔬 Experiment Framework - Run A/B tests with different prompts and model configurations
- 📈 AI Evaluation - Evaluate model outputs with built-in and custom evaluators
- 📝 Log Management - Comprehensive logging and monitoring for AI applications
📦 Installation
pip install respan
Or with Poetry:
poetry add respan
🔑 Quick Start
1. Set up your API key
export RESPAN_API_KEY="your-api-key-here"
Or create a .env file:
RESPAN_API_KEY=your-api-key-here
RESPAN_BASE_URL=https://api.respan.ai # optional
2. Basic Usage
from respan import DatasetAPI, ExperimentAPI, EvaluatorAPI
# Initialize clients
dataset_client = DatasetAPI(api_key="your-api-key")
experiment_client = ExperimentAPI(api_key="your-api-key")
evaluator_client = EvaluatorAPI(api_key="your-api-key")
# Create a dataset from logs
dataset = dataset_client.create({
"name": "My Dataset",
"description": "Dataset for evaluation",
"type": "sampling",
"sampling": 100
})
# List available evaluators
evaluators = evaluator_client.list()
print(f"Available evaluators: {len(evaluators.results)}")
# Run evaluation
evaluation = dataset_client.run_dataset_evaluation(
dataset_id=dataset.id,
evaluator_slugs=["accuracy-evaluator", "relevance-evaluator"]
)
🏗️ Core APIs
Dataset API
Manage datasets and run evaluations on your AI model outputs:
from respan import DatasetAPI, DatasetCreate
client = DatasetAPI(api_key="your-api-key")
# Create dataset
dataset = client.create(DatasetCreate(
name="Production Logs",
type="sampling",
sampling=1000
))
# Add logs to dataset
client.add_logs_to_dataset(
dataset_id=dataset.id,
start_time="2024-01-01T00:00:00Z",
end_time="2024-01-02T00:00:00Z"
)
# Run evaluations
evaluation = client.run_dataset_evaluation(
dataset_id=dataset.id,
evaluator_slugs=["accuracy-evaluator"]
)
Experiment API
Run A/B tests with different model configurations:
from respan import ExperimentAPI, ExperimentCreate, ExperimentColumnType
client = ExperimentAPI(api_key="your-api-key")
# Create experiment
experiment = client.create(ExperimentCreate(
name="Prompt A/B Test",
description="Testing different system prompts",
columns=[
ExperimentColumnType(
name="Version A",
model="gpt-4",
temperature=0.7,
prompt_messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "{{user_input}}"}
]
),
ExperimentColumnType(
name="Version B",
model="gpt-4",
temperature=0.3,
prompt_messages=[
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "{{user_input}}"}
]
)
]
))
# Run experiment
results = client.run_experiment(experiment_id=experiment.id)
Evaluator API
Discover and use AI evaluators:
from respan import EvaluatorAPI
client = EvaluatorAPI(api_key="your-api-key")
# List all evaluators
evaluators = client.list()
# Get specific evaluator details
evaluator = client.get("accuracy-evaluator")
print(f"Evaluator: {evaluator.name}")
print(f"Description: {evaluator.description}")
Prompt API
Manage prompts and their versions:
from respan import PromptAPI
from respan_sdk.respan_types.prompt_types import Prompt, PromptVersion
client = PromptAPI(api_key="your-api-key")
# Create a prompt
prompt = client.create()
# Create a version for the prompt
version = client.create_version(prompt.id, PromptVersion(
prompt_version_id="v1",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
],
model="gpt-4o-mini",
temperature=0.7
))
# List all prompts
prompts = client.list()
# Get specific prompt with versions
prompt_details = client.get(prompt.id)
Log API
Create and manage AI application logs:
from respan import LogAPI, RespanLogParams
client = LogAPI(api_key="your-api-key")
# Create log entry
log = client.create(RespanLogParams(
model="gpt-4",
input="What is machine learning?",
output="Machine learning is a subset of AI...",
status_code=200,
prompt_tokens=10,
completion_tokens=50
))
🔄 Async Support
All APIs support both synchronous and asynchronous operations:
import asyncio
from respan import DatasetAPI
async def main():
client = DatasetAPI(api_key="your-api-key")
# Use 'await' with 'a' prefixed methods for async
datasets = await client.alist()
dataset = await client.aget(dataset_id="123")
print(f"Found {datasets.count} datasets")
asyncio.run(main())
📚 Examples
Check out the examples/ directory for complete workflows:
- Simple Evaluator Example - Basic evaluator operations
- Dataset Workflow - Complete dataset management
- Experiment Workflow - A/B testing with experiments
- Prompt Workflow - Prompt and version management
# Run examples
python examples/simple_evaluator_example.py
python examples/dataset_workflow_example.py
python examples/experiment_workflow_example.py
python examples/prompt_workflow_example.py
🧪 Testing
The SDK includes comprehensive tests for both unit testing and real API integration:
# Install development dependencies
poetry install
# Run all tests
python -m pytest tests/ -v
# Run specific test suites
python -m pytest tests/test_dataset_api_real.py -v
python -m pytest tests/test_experiment_api_real.py -v
📖 API Reference
Core Classes
DatasetAPI- Dataset management and evaluationExperimentAPI- A/B testing and experimentationEvaluatorAPI- AI model evaluation toolsLogAPI- Application logging and monitoringPromptAPI- Prompt and version management
Type Safety
All APIs include comprehensive type definitions:
from respan import (
Dataset, DatasetCreate, DatasetUpdate,
Experiment, ExperimentCreate, ExperimentUpdate,
Evaluator, EvaluatorList,
RespanLogParams, LogList,
PromptAPI
)
from respan_sdk.respan_types.prompt_types import (
Prompt, PromptVersion
)
🔧 Configuration
Environment Variables
RESPAN_API_KEY=your-api-key-here # Required
RESPAN_BASE_URL=https://api.respan.ai # Optional
Client Initialization
# Using environment variables
dataset_client = DatasetAPI() # Reads from RESPAN_API_KEY
prompt_client = PromptAPI() # Reads from RESPAN_API_KEY
# Explicit configuration
client = DatasetAPI(
api_key="your-api-key",
base_url="https://api.respan.ai"
)
📋 Requirements
- Python 3.9+
- httpx >= 0.25.0
- respan-sdk >= 0.4.63
📄 License
Apache 2.0 - see LICENSE for details.
🤝 Contributing
We welcome contributions! Please see our Contributing Guide for details.
📞 Support
- 📧 Email: team@respan.ai
- 📖 Documentation: https://docs.respan.ai
- 🐛 Issues: GitHub Issues
Built with ❤️ by the Respan team
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
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 respan_ai-4.1.0.tar.gz.
File metadata
- Download URL: respan_ai-4.1.0.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6dbc95d35279345eae0159ca85f3108c54d20b215d50a253e155055cfbb0f08
|
|
| MD5 |
52484449c62713536a48f7020e63630f
|
|
| BLAKE2b-256 |
8bbae1badf9a629170fa38aad6de49a3c2c2505f783a84988297bba74609b4c6
|
Provenance
The following attestation bundles were made for respan_ai-4.1.0.tar.gz:
Publisher:
publish.yml on respanai/respan
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
respan_ai-4.1.0.tar.gz -
Subject digest:
c6dbc95d35279345eae0159ca85f3108c54d20b215d50a253e155055cfbb0f08 - Sigstore transparency entry: 1341258176
- Sigstore integration time:
-
Permalink:
respanai/respan@df85c67cf797442d0af1329832c233b5ba96d7c0 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/respanai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@df85c67cf797442d0af1329832c233b5ba96d7c0 -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file respan_ai-4.1.0-py3-none-any.whl.
File metadata
- Download URL: respan_ai-4.1.0-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa011d8620404eaa0e47414537f58205ff964029d88a6b8bff64b73ff17fcfde
|
|
| MD5 |
21e0572427d8e94251abd96ebb4a6938
|
|
| BLAKE2b-256 |
64bd4aba73c8d704a432f252f793760a1fc45cbdf0b03220710d452befcfc37c
|
Provenance
The following attestation bundles were made for respan_ai-4.1.0-py3-none-any.whl:
Publisher:
publish.yml on respanai/respan
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
respan_ai-4.1.0-py3-none-any.whl -
Subject digest:
aa011d8620404eaa0e47414537f58205ff964029d88a6b8bff64b73ff17fcfde - Sigstore transparency entry: 1341258245
- Sigstore integration time:
-
Permalink:
respanai/respan@df85c67cf797442d0af1329832c233b5ba96d7c0 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/respanai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@df85c67cf797442d0af1329832c233b5ba96d7c0 -
Trigger Event:
workflow_run
-
Statement type: