A client library for accessing Circuit Breaker Labs API
Project description
Circuit Breaker Labs Python Client
[!Note] This project was automatically generated by OpenAPI Python Client from this OpenAPI spec.
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:
-
Every path/method combo becomes a Python module with four functions:
sync: Blocking request that returns parsed data (if successful) orNonesync_detailed: Blocking request that always returns aRequest, optionally withparsedset if the request was successful.asyncio: Likesyncbut async instead of blockingasyncio_detailed: Likesync_detailedbut async instead of blocking
-
All path/query params, and bodies become method arguments.
-
If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above)
-
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"))
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file circuit_breaker_labs-1.0.8.tar.gz.
File metadata
- Download URL: circuit_breaker_labs-1.0.8.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c3a24292dafa6853787c97175d6ad5c55fe67246b5945eba68907d7cfa3c6e8
|
|
| MD5 |
ce1d0aa6677224604842017471f3d665
|
|
| BLAKE2b-256 |
7bba12eba51dcc3f2e2308a396c69fde6d1fb9d12aeb9224a11a5de63d40f319
|
Provenance
The following attestation bundles were made for circuit_breaker_labs-1.0.8.tar.gz:
Publisher:
release.yml on circuitbreakerlabs/circuitbreakerlabs-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
circuit_breaker_labs-1.0.8.tar.gz -
Subject digest:
3c3a24292dafa6853787c97175d6ad5c55fe67246b5945eba68907d7cfa3c6e8 - Sigstore transparency entry: 1520550137
- Sigstore integration time:
-
Permalink:
circuitbreakerlabs/circuitbreakerlabs-python@44db1f668a526404c523c3a196b1626ca08263e7 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/circuitbreakerlabs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@44db1f668a526404c523c3a196b1626ca08263e7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file circuit_breaker_labs-1.0.8-py3-none-any.whl.
File metadata
- Download URL: circuit_breaker_labs-1.0.8-py3-none-any.whl
- Upload date:
- Size: 44.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99a9e18674e2cd74003d8e214593a427098948cae25f04a783bc89c5d3231e72
|
|
| MD5 |
c9d8f1f64a2905dc13f44d83757d832c
|
|
| BLAKE2b-256 |
0041807a4f5e755940c8f534cc4c9ff39e8183661ce94cdd09e3ce007a389690
|
Provenance
The following attestation bundles were made for circuit_breaker_labs-1.0.8-py3-none-any.whl:
Publisher:
release.yml on circuitbreakerlabs/circuitbreakerlabs-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
circuit_breaker_labs-1.0.8-py3-none-any.whl -
Subject digest:
99a9e18674e2cd74003d8e214593a427098948cae25f04a783bc89c5d3231e72 - Sigstore transparency entry: 1520550170
- Sigstore integration time:
-
Permalink:
circuitbreakerlabs/circuitbreakerlabs-python@44db1f668a526404c523c3a196b1626ca08263e7 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/circuitbreakerlabs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@44db1f668a526404c523c3a196b1626ca08263e7 -
Trigger Event:
push
-
Statement type: