Skip to main content

Overview

This page explains how to use Basalt’s Experiments API with Python. Experiments help you organize, track, and compare different approaches in your AI workflows.

Installation

Ensure you have the Basalt SDK installed:

Client Initialization

Access the experiments API through the experiments property on the main Basalt client:
Create one Basalt instance per process and reuse it for the entire application lifetime. shutdown() permanently destroys the global OpenTelemetry TracerProvider — never call it between loop iterations or between requests. See Observability Concepts for details.

Creating Experiments

You can create experiments programmatically to register new tests or variants.

Synchronous Creation

Asynchronous Creation

Using Experiments with Observability

The most common use case is attaching an experiment context to your traces. This allows you to slice and dice your observability data by experiment.

Experiments in a Loop

When processing multiple items under one experiment, each start_observe() call naturally creates a separate trace — the context manager cleans up the OpenTelemetry context on exit, so the next iteration starts fresh.
Do not call basalt.shutdown() inside the loop or recreate the Basalt client per iteration. shutdown() permanently kills the TracerProvider — all subsequent traces would be silently dropped.