Braintrust Core
Braintrust Core is a Python package that provides shared core dependencies for other packages within the Braintrust ecosystem. It is primarily an internal utility library, with user-facing functionality for logging, tracing, evaluations, and CLI workflows typically exposed through the main `braintrust` SDK. The current version is 0.0.59, and it generally follows the release cadence of the broader Braintrust Python SDKs.
Warnings
- gotcha The `braintrust-core` package is primarily an internal dependency. For Braintrust functionality like logging, tracing, evaluations, or CLI interactions, users should typically install and use the main `braintrust` package (e.g., `pip install braintrust autoevals`).
- gotcha Functionality that might appear in a 'core' package can be subject to refactoring and consolidation into the main `braintrust` SDK. For instance, the `@braintrust/core` (TypeScript) package's functionality was explicitly folded into the main `braintrust` package. While this was for TypeScript, it indicates a pattern that Python users should be aware of regarding `braintrust-core`.
- deprecated Direct imports or reliance on specific modules within `braintrust-core` are not officially supported APIs and may change or be removed without prior notice, as it's an internal utility package.
Install
-
pip install braintrust-core
Imports
- Eval
from braintrust import Eval
- init
from braintrust import init
Quickstart
import os
from autoevals import LevenshteinScorer
from braintrust import Eval
# Set your Braintrust API key from environment variables
# BRAINTRUST_API_KEY='sk-...' (Replace with your actual key or set in environment)
api_key = os.environ.get('BRAINTRUST_API_KEY', 'YOUR_API_KEY_HERE')
# Define an evaluation
eval_run = Eval(
"Say Hi Bot",
data=lambda: [
{"input": "Foo", "expected": "Hi Foo"},
{"input": "Bar", "expected": "Hello Bar"},
],
task=lambda input: "Hi " + input,
scores=[LevenshteinScorer],
api_key=api_key # Pass API key here or ensure BRAINTRUST_API_KEY env var is set
)
# Run the evaluation
# To run this, you would typically execute it via the Braintrust CLI:
# BRAINTRUST_API_KEY=YOUR_API_KEY braintrust eval your_script_name.py
# Or, to run directly in Python, if your API key is configured:
# result = eval_run.run()
# print(result)
print("To run this evaluation, set BRAINTRUST_API_KEY and use the Braintrust CLI: braintrust eval <your_script.py>")