Brokle Platform Python SDK for OpenTelemetry-native LLM observability and tracing
Project description
Brokle Python SDK
OpenTelemetry-native observability for AI applications.
The Brokle Python SDK provides comprehensive observability, tracing, and auto-instrumentation for LLM applications. Choose your integration level:
🎯 Three Integration Patterns
Pattern 1: Wrapper Functions Wrap existing SDK clients (OpenAI, Anthropic) for automatic observability and platform features.
Pattern 2: Universal Decorator
Framework-agnostic @observe() decorator with automatic hierarchical tracing. Works with any AI library.
Pattern 3: Native SDK (Sync & Async) Full platform capabilities with OpenAI-compatible interface. Context manager support with automatic resource cleanup.
Installation
pip install brokle
Setup
export BROKLE_API_KEY="bk_your_api_key_here"
export BROKLE_HOST="http://localhost:8080"
Quick Start
Pattern 1: Wrapper Functions
# Wrap existing SDK clients for automatic observability
from openai import OpenAI
from anthropic import Anthropic
from brokle import wrap_openai, wrap_anthropic
# OpenAI wrapper
openai_client = wrap_openai(
OpenAI(api_key="sk-..."),
tags=["production"],
session_id="user_session_123"
)
# Anthropic wrapper
anthropic_client = wrap_anthropic(
Anthropic(api_key="sk-ant-..."),
tags=["claude", "analysis"]
)
response = openai_client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Hello!"}]
)
# ✅ Automatic Brokle observability and tracing
Pattern 2: Universal Decorator
# Automatic hierarchical tracing with just @observe()
from brokle import observe
import openai
client = openai.OpenAI()
@observe(name="parent-workflow")
def main_workflow(data: str):
# Parent span automatically created
result1 = analyze_data(data)
result2 = summarize_findings(result1)
return f"Final result: {result1} -> {result2}"
@observe(name="data-analysis")
def analyze_data(data: str):
# Child span automatically linked to parent
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": f"Analyze: {data}"}]
)
return response.choices[0].message.content
@observe(name="summarization")
def summarize_findings(analysis: str):
# Another child span automatically linked to parent
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": f"Summarize: {analysis}"}]
)
return response.choices[0].message.content
# Automatic hierarchical tracing - no manual workflow management needed
result = main_workflow("User behavior data from Q4 2024")
# ✅ Complete span hierarchy: parent -> analyze_data + summarize_findings
Pattern 3: Native SDK
Sync Client:
from brokle import Brokle
# Context manager (recommended)
with Brokle(
api_key="bk_...",
host="http://localhost:8080"
) as client:
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Hello!"}],
tags=["production"] # Analytics tags
)
print(f"Response: {response.choices[0].message.content}")
Async Client:
from brokle import AsyncBrokle
import asyncio
async def main():
async with AsyncBrokle(
api_key="bk_...",
) as client:
response = await client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Hello!"}],
tags=["async", "production"] # Analytics tags
)
print(f"Response: {response.choices[0].message.content}")
asyncio.run(main())
Why Choose Brokle?
- ⚡ <3ms Overhead: High-performance observability
- 📊 Complete Visibility: Real-time analytics and quality scoring
- 🔧 OpenTelemetry Native: Standards-based tracing and metrics
- 🛠️ Three Patterns: Start simple, scale as needed
Next Steps
- 📖 Integration Patterns Guide - Detailed examples
- ⚡ Quick Reference - Fast setup guide
- 🔧 API Reference - Complete documentation
- 💻 Examples - Pattern-based code examples
Examples
Check the examples/ directory:
pattern1_wrapper_functions.py- Wrapper functionspattern2_decorator.py- Universal decorator
Support
- Issues: GitHub Issues
- Docs: docs.brokle.com
- Email: support@brokle.com
Simple. Powerful. OpenTelemetry-native observability for AI.
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 brokle-0.2.14.tar.gz.
File metadata
- Download URL: brokle-0.2.14.tar.gz
- Upload date:
- Size: 74.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0a9a7ba12a0637cc64ec985bc73794595829eae4ddd47e6521aa4906c9ea691
|
|
| MD5 |
1ddb2491dbc010877fe3534d57133f30
|
|
| BLAKE2b-256 |
c928d8511243e697991aa00cf67e4025240ab8b9d79fd48976b8f7b5d51efaea
|
Provenance
The following attestation bundles were made for brokle-0.2.14.tar.gz:
Publisher:
publish.yml on brokle-ai/brokle-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
brokle-0.2.14.tar.gz -
Subject digest:
d0a9a7ba12a0637cc64ec985bc73794595829eae4ddd47e6521aa4906c9ea691 - Sigstore transparency entry: 748759632
- Sigstore integration time:
-
Permalink:
brokle-ai/brokle-python@016d8d3be6e35ee8bae714dc1d0705408ad8b89e -
Branch / Tag:
refs/tags/v0.2.14 - Owner: https://github.com/brokle-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@016d8d3be6e35ee8bae714dc1d0705408ad8b89e -
Trigger Event:
release
-
Statement type:
File details
Details for the file brokle-0.2.14-py3-none-any.whl.
File metadata
- Download URL: brokle-0.2.14-py3-none-any.whl
- Upload date:
- Size: 80.8 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 |
7312d19f2e65a8e24a49026cae92f33e414feef9e497e2b78acfd5bfecbb7a3f
|
|
| MD5 |
28606a5f46fecbc93396af0a7908ac36
|
|
| BLAKE2b-256 |
a8ccedab9022cfb1e3eb9eb32acfc8a60bc7cac635252c7f3bd8d2dd1c408a3c
|
Provenance
The following attestation bundles were made for brokle-0.2.14-py3-none-any.whl:
Publisher:
publish.yml on brokle-ai/brokle-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
brokle-0.2.14-py3-none-any.whl -
Subject digest:
7312d19f2e65a8e24a49026cae92f33e414feef9e497e2b78acfd5bfecbb7a3f - Sigstore transparency entry: 748759637
- Sigstore integration time:
-
Permalink:
brokle-ai/brokle-python@016d8d3be6e35ee8bae714dc1d0705408ad8b89e -
Branch / Tag:
refs/tags/v0.2.14 - Owner: https://github.com/brokle-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@016d8d3be6e35ee8bae714dc1d0705408ad8b89e -
Trigger Event:
release
-
Statement type: