{"id":2418,"library":"braintrust","title":"Braintrust Python SDK","description":"The Braintrust Python SDK is the official library for logging, tracing, and evaluating AI applications with Braintrust. It enables developers to instrument LLM calls, manage prompts, run evaluations, and track performance. The current version is 0.14.0, and the library is actively maintained with frequent updates. [2]","status":"active","version":"0.14.0","language":"en","source_language":"en","source_url":"https://github.com/braintrustdata/braintrust-sdk-python","tags":["AI","MLOps","evaluation","LLM","tracing","observability"],"install":[{"cmd":"pip install braintrust","lang":"bash","label":"Core SDK"},{"cmd":"pip install \"braintrust[all]\"","lang":"bash","label":"All Optional Extras"},{"cmd":"pip install \"braintrust[cli,openai-agents,otel,performance,temporal]\"","lang":"bash","label":"Specific Optional Extras"}],"dependencies":[{"reason":"Minimum Python version required.","package":"python","version":">=3.10.0","optional":false},{"reason":"Commonly used for defining scorers in evaluation workflows. [7, 14]","package":"autoevals","optional":true},{"reason":"For faster JSON serialization with the 'performance' extra. [2]","package":"orjson","optional":true},{"reason":"Required for integrating with OpenAI models using `braintrust.wrap_openai()`. [14]","package":"openai","optional":true}],"imports":[{"symbol":"Eval","correct":"from braintrust import Eval"},{"symbol":"init_logger","correct":"import braintrust\nbraintrust.init_logger(...)"},{"symbol":"wrap_openai","correct":"import braintrust\nclient = braintrust.wrap_openai(openai.OpenAI(...))"},{"note":"The braintrust-langchain package is deprecated; its functionality is now integrated directly into the main 'braintrust' package. [3]","wrong":"import braintrust_langchain","symbol":"braintrust_langchain","correct":"from braintrust import LangchainCallback"}],"quickstart":{"code":"import os\nfrom braintrust import Eval\n\ndef is_equal(expected, output):\n    return expected == output\n\n# Ensure BRAINTRUST_API_KEY is set in your environment variables.\n# For local execution: export BRAINTRUST_API_KEY=\"<YOUR_API_KEY>\"\n# For production: Use secrets management or similar.\napi_key = os.environ.get('BRAINTRUST_API_KEY', '')\n\nif not api_key:\n    print(\"Warning: BRAINTRUST_API_KEY environment variable not set. Evaluation will not be logged to Braintrust.\")\n    # In a real scenario, you might raise an error or handle accordingly.\n\n# The Eval function itself implicitly uses the API key from the environment\n# when .run() is called or when integrated with the Braintrust CLI.\nEval(\n    \"Say Hi Bot\",\n    data=lambda: [\n        {\"input\": \"Foo\", \"expected\": \"Hi Foo\"},\n        {\"input\": \"Bar\", \"expected\": \"Hello Bar\"},\n    ],\n    task=lambda input: \"Hi \" + input,\n    scores=[is_equal],\n).run()\n\nprint(\"Evaluation complete. Check your Braintrust dashboard.\")","lang":"python","description":"This quickstart demonstrates how to run a simple evaluation using the `braintrust.Eval` class. It defines a basic task and a scoring function, then executes the evaluation. The `BRAINTRUST_API_KEY` environment variable is required for the results to be logged to your Braintrust dashboard. [2, 7]"},"warnings":[{"fix":"Upgrade your Python environment to 3.10 or newer.","message":"Starting with v0.4.0, Braintrust Python SDK requires Python 3.10 or higher. Older Python versions are no longer supported. [17]","severity":"breaking","affected_versions":"<0.4.0"},{"fix":"Uninstall the deprecated packages and use the latest `braintrust` package, which includes the integration directly. E.g., `pip install \"braintrust[openai-agents]\"` for agent integrations. [2, 3]","message":"The separate `braintrust-langchain` and `braintrust-adk` packages are deprecated. Their functionality for LangChain and Google ADK integrations has been moved into the main `braintrust` package. [3]","severity":"deprecated","affected_versions":"All versions of braintrust-langchain/braintrust-adk"},{"fix":"Set the `BRAINTRUST_API_KEY` environment variable in your execution environment. For example: `export BRAINTRUST_API_KEY=\"<YOUR_API_KEY>\"`.","message":"Authentication to Braintrust requires an API key, which must be set as the `BRAINTRUST_API_KEY` environment variable. Without this, operations like logging traces or running evaluations will not connect to your Braintrust project. [2, 9, 12]","severity":"gotcha","affected_versions":"All"},{"fix":"Install `autoevals` via `pip install autoevals`.","message":"For defining custom scoring functions in evaluation workflows, the `autoevals` package is frequently used alongside `braintrust`. If you encounter 'LevenshteinScorer not found' or similar errors, it's likely due to missing `autoevals`. [7, 14]","severity":"gotcha","affected_versions":"All"},{"fix":"Call `braintrust.init_logger()` at the earliest possible point in your application startup, preceding Temporal Worker initialization.","message":"When integrating with Temporal Workflows, the Braintrust logger (`braintrust.init()`) must be initialized *before* creating your Temporal Worker to ensure proper span connection and traceability. [12]","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}