The official Python SDK for logging, tracing, and evaluating AI applications with Braintrust.
Install the SDK:
pip install braintrust
Save this evaluation as eval_tutorial.py:
from braintrust import Eval def is_equal(expected, output): return expected == output Eval( "Say Hi Bot", data=lambda: [ {"input": "Foo", "expected": "Hi Foo"}, {"input": "Bar", "expected": "Hello Bar"}, ], task=lambda input: "Hi " + input, scores=[is_equal], )
Install the standalone bt CLI and run:
BRAINTRUST_API_KEY="YOUR_API_KEY" bt eval eval_tutorial.py
Install extras as needed for specific workflows:
pip install "braintrust[audio]" pip install "braintrust[cli]" pip install "braintrust[openai-agents]" pip install "braintrust[otel]" pip install "braintrust[temporal]" pip install "braintrust[all]"
Available extras:
audio: installs PyAV for Opus/Ogg session recording on Python 3.12+performance: installsorjsonfor faster JSON serializationcli: installs optional dependencies used by the Braintrust CLIopenai-agents: installs OpenAI Agents integration supportotel: installs OpenTelemetry integration dependenciestemporal: installs Temporal integration dependenciesall: installs all optional extras
The braintrust install commands for AWS CloudFormation are deprecated. Use the
CloudFormation guide
to manage existing stacks.
braintrust[audio] requires Python 3.12+ and uses PyAV's bundled FFmpeg codecs.
On Python 3.10–3.11, the extra does not install PyAV; use PCM/WAV recording.
Each Opus/Ogg segment is an independent file with exact playable duration. Installing the extra does not
enable capture; framework adapters still require their audio opt-ins and privacy
permission. Without PyAV, default recording warns once and uses raw PCM. Explicit
Opus configuration requires the extra. PCM/WAV need no native codecs.
Audio uploads use Attachment.upload() directly. Span customizers and masking
apply to trace records published afterward; removing an attachment reference does
not prevent or undo its upload.
- Python SDK docs: https://docs.braintrust.dev/sdks/python/versions/latest
- Braintrust docs: https://docs.braintrust.dev
- Repo publishing guide: https://github.com/braintrustdata/braintrust-sdk-python/blob/main/docs/publishing.md
- Source code: https://github.com/braintrustdata/braintrust-sdk-python/tree/main/py
Apache-2.0