Python SDK#
Python SDK for AI Observability and LLM Monitoring
Complete SDK for instrumenting Python applications with WatchLLM's semantic caching and cost optimization layer. Monitor LLM calls, agent steps, errors, and performance metrics with automatic PII redaction and intelligent batching.
Quick Start#
pip install watchllm-sdk-pythonfrom watchllm import WatchLLMClient, EventType, Status
client = WatchLLMClient(
api_key='your-api-key',
project_id='your-project-id'
)
# Track LLM calls
client.track({
'type': EventType.LLM_CALL,
'status': Status.SUCCESS,
'model': 'gpt-4',
'input': 'Hello, how are you?',
'output': 'I am doing well, thank you!',
'tokens': {'prompt': 10, 'completion': 20},
'cost': 0.002
})Complete Documentation#
For comprehensive guides, API reference, and advanced usage patterns, see the full Python SDK Documentation.
Key Features#
- Thread-Safe: Designed for both synchronous and asynchronous Python applications
- Automatic Batching: Efficient event batching for optimal performance
- PII Redaction: Automatic sensitive data protection
- Agent Monitoring: Track complex agent workflows and step execution
- Error Tracking: Comprehensive error monitoring and debugging
- Cost Estimation: Real-time cost calculation and optimization insights
Installation#
pip install watchllm-sdk-pythonOr with specific package managers:
# poetry
poetry add watchllm-sdk-python
# conda
conda install watchllm-sdk-pythonBasic Usage#
from watchllm import WatchLLMClient, Status
client = WatchLLMClient(
api_key=os.getenv('WATCHLLM_API_KEY'),
project_id=os.getenv('WATCHLLM_PROJECT_ID')
)
# Simple LLM call tracking
client.track({
'type': 'llm_call',
'status': Status.SUCCESS,
'model': 'gpt-4',
'input': 'What is the capital of France?',
'output': 'The capital of France is Paris.',
'tokens': {'prompt': 8, 'completion': 7},
'cost': 0.0014
})Related Resources#
- Node.js SDK Documentation - Node.js SDK overview
- SDK Comparison Guide - Compare Node.js and Python SDKs
- Type Reference - Complete type definitions
- Examples - Code examples and boilerplate
Learn More#
Visit the complete Python SDK documentation for:
- Advanced configuration options
- Agent workflow monitoring
- Error handling patterns
- Performance optimization
- Troubleshooting guides