Skip to main content

Circuit Breaker Labs Python Client

Python Version Ruff MyPy uv PyPI - Version

Installation

Install from PyPi directly:

uv pip install circuit-breaker-labs

Or install using a wheel/sdist distributed with each release.

Nix flake usage

Minimal flake using this package as an input:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
    cbl-lib.url = "github:circuitbreakerlabs/circuitbreakerlabs-python";
  };

  outputs = { nixpkgs, flake-utils, cbl-lib, ... }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs {
          inherit system;
          overlays = [ cbl-lib.overlays.${system}.default ];
        };
      in {
        devShells.default = pkgs.mkShell {
          packages = [
            (pkgs.python314.withPackages (ps: [ ps.cblLib ]))
          ];
        };
      });
}

Quick check:

nix develop --command python -c "from circuit_breaker_labs import Client; client = Client(base_url='https://api.circuitbreakerlabs.ai/v1/'); print(type(client).__name__)"

Usage

First, create a client:

from circuit_breaker_labs import Client

client = Client(base_url="https://api.circuitbreakerlabs.ai/v1/")

To see which test case groups your API key can use:

import os

from circuit_breaker_labs.api.test_case_groups import get_test_case_groups_get

with client as client:
    test_case_groups = get_test_case_groups_get.sync(
        client=client,
        cbl_api_key=os.environ["CBL_API_KEY"],
    )

Now build a request and use it when calling an endpoint

import os

from circuit_breaker_labs.api.evaluations import singleturn_evaluate_system_prompt_post
from circuit_breaker_labs.models import SingleTurnEvaluateSystemPromptRequest

with client as client:
    request = SingleTurnEvaluateSystemPromptRequest(
        threshold=0.5,
        variations=3,
        maximum_iteration_layers=2,
        test_case_groups=["suicidal_ideation"],
        system_prompt=os.environ["SYSTEM_PROMPT"],
        openrouter_model_name="anthropic/claude-3.7-sonnet",
    )

    response = singleturn_evaluate_system_prompt_post.sync(
        client=client,
        cbl_api_key=os.environ["CBL_API_KEY"],
        body=request,
    )

Or do the same thing with an async version:

import os

from circuit_breaker_labs.api.evaluations import singleturn_evaluate_system_prompt_post
from circuit_breaker_labs.models import SingleTurnEvaluateSystemPromptRequest

async with client as client:
    request = SingleTurnEvaluateSystemPromptRequest(
        threshold=0.5,
        variations=3,
        maximum_iteration_layers=2,
        test_case_groups=["suicidal_ideation"],
        system_prompt=os.environ["SYSTEM_PROMPT"],
        openrouter_model_name="anthropic/claude-3.7-sonnet",
    )

    response = await singleturn_evaluate_system_prompt_post.asyncio(
        client=client,
        cbl_api_key=os.environ["CBL_API_KEY"],
        body=request,
    )

Want to test multi-turn conversations instead? Use the multi-turn endpoint (async version also available):

import os

from circuit_breaker_labs.api.evaluations import multi_turn_evaluate_system_prompt_post
from circuit_breaker_labs.models import MultiTurnEvaluateSystemPromptRequest

with client as client:
    request = MultiTurnEvaluateSystemPromptRequest(
        threshold=0.6,
        max_turns=6,
        test_case_groups=["suicidal_ideation"],
        system_prompt=os.environ["SYSTEM_PROMPT"],
        openrouter_model_name="anthropic/claude-3.7-sonnet",
    )

    response = multi_turn_evaluate_system_prompt_post.sync(
        client=client,
        cbl_api_key=os.environ["CBL_API_KEY"],
        body=request,
    )

Things to know:

  1. Every path/method combo becomes a Python module with four functions:

    1. sync: Blocking request that returns parsed data (if successful) or None
    2. sync_detailed: Blocking request that always returns a Request, optionally with parsed set if the request was successful.
    3. asyncio: Like sync but async instead of blocking
    4. asyncio_detailed: Like sync_detailed but async instead of blocking
  2. All path/query params, and bodies become method arguments.

  3. If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above)

  4. Any endpoint which did not have a tag will be in circuit_breaker_labs.api.default

Advanced customizations

There are more settings on the generated Client class which let you control more runtime behavior, check out the docstring on that class for more info. You can also customize the underlying httpx.Client or httpx.AsyncClient (depending on your use-case):

from circuit_breaker_labs import Client

def log_request(request):
    print(f"Request event hook: {request.method} {request.url} - Waiting for response")

def log_response(response):
    request = response.request
    print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}")

client = Client(
    base_url="https://api.circuitbreakerlabs.ai/v1/",
    httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}},
)

# Or get the underlying httpx client to modify directly with client.get_httpx_client() or client.get_async_httpx_client()

You can even set the httpx client directly, but beware that this will override any existing settings (e.g., base_url):

import httpx
from circuit_breaker_labs import Client

client = Client(
    base_url="https://api.circuitbreakerlabs.ai/v1/",
)
# Note that base_url needs to be re-set, as would any shared cookies, headers, etc.
client.set_httpx_client(httpx.Client(base_url="https://api.circuitbreakerlabs.ai/v1/", proxies="http://localhost:8030"))

Metadata

Release files for circuit-breaker-labs 1.0.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for circuit-breaker-labs 1.0.11
File Size Uploaded Provenance Actions
circuit_breaker_labs-1.0.11.tar.gz 19.9 kB With provenance Details for circuit_breaker_labs-1.0.11.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for circuit-breaker-labs 1.0.11
File Interpreter ABI Platform Actions
circuit_breaker_labs-1.0.11-py3-none-any.whl Python 3 none any Details for circuit_breaker_labs-1.0.11-py3-none-any.whl

Total release size: 82.5 kB

Release files / circuit_breaker_labs-1.0.11.tar.gz

Download URL circuit_breaker_labs-1.0.11.tar.gz
Size 19.9 kB
Tags Source
SHA-256 checksum
How to use checksums
9892b4d037c9bd50ef3aaff45a1a0d950d86f14171b1daaffe8a8fdd0391966f
BLAKE2b-256 checksum
How to use checksums
dee0d79bdf73457c2afa9daa4a6dfea1bde09f108e54c43a33c993d738e53379
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 12, 2026.

Transparency log

Release files / circuit_breaker_labs-1.0.11-py3-none-any.whl

Download URL circuit_breaker_labs-1.0.11-py3-none-any.whl
Size 62.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f7f3ff2e160f366d3843fb3d95cd79328e113069b3c12df764d28173832cef70
BLAKE2b-256 checksum
How to use checksums
2b158c7de4e4d72d370cc8db6013252189edeb9193328fab81c37438c47001db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 12, 2026.

Transparency log

Security for circuit-breaker-labs 1.0.11

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for circuit_breaker_labs-1.0.11.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 12, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page