Calibrate Python Library
The Calibrate Python SDK provides convenient, typed access to the Calibrate
agent evaluation platform API. Authenticate with an API key (sk_…) scoped
to your organization to run agent tests and poll their results.
Table of Contents
- Documentation
- Installation
- Pre Requisites
- Reference
- Quick Start
- Usage
- Environments
- Async Client
- Exception Handling
- Advanced
Documentation
API reference documentation is available here.
Installation
pip install calibrate-sdk
Pre-requisites
You need to have a Calibrate API key. You can get the API key from the UI.
Reference
A full reference for this library is available here.
Quick Start
from calibrate import Calibrate
client = Calibrate(api_key="sk_...")
# List the agents in your organization
agents = client.agents.list()
# Kick off a test run for an agent and poll for the result
run = client.agent_tests.run(agent_uuid="<agent-uuid>")
result = client.agent_tests.get_run(task_id=run.task_id)
Usage
Instantiate and use the client with the following:
from calibrate import Calibrate
client = Calibrate(
api_key="<value>",
)
client.agents.verify_connection(
agent_uuid="f47ac10b-58cc-4372-a567-0e02b2c3d479",
)
Environments
This SDK allows you to configure different environments for API requests.
from calibrate import Calibrate
from calibrate.environment import CalibrateEnvironment
client = Calibrate(
environment=CalibrateEnvironment.DEFAULT,
)
Async Client
The SDK also exports an async client so that you can make non-blocking calls to our API. Note that if you are constructing an Async httpx client class to pass into this client, use httpx.AsyncClient() instead of httpx.Client() (e.g. for the httpx_client parameter of this client).
import asyncio
from calibrate import AsyncCalibrate
client = AsyncCalibrate(
api_key="<value>",
)
async def main() -> None:
await client.agents.verify_connection(
agent_uuid="f47ac10b-58cc-4372-a567-0e02b2c3d479",
)
asyncio.run(main())
Exception Handling
When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error will be thrown.
from calibrate.core.api_error import ApiError
try:
client.agents.verify_connection(...)
except ApiError as e:
print(e.status_code)
print(e.body)
Advanced
Access Raw Response Data
The SDK provides access to raw response data, including headers, through the .with_raw_response property.
The .with_raw_response property returns a "raw" client that can be used to access the .headers and .data attributes.
from calibrate import Calibrate
client = Calibrate(...)
response = client.agents.with_raw_response.verify_connection(...)
print(response.headers) # access the response headers
print(response.status_code) # access the response status code
print(response.data) # access the underlying object
Retries
The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long as the request is deemed retryable and the number of retry attempts has not grown larger than the configured retry limit (default: 2).
Which status codes are retried depends on the retryStatusCodes generator configuration:
legacy (current default): retries on
recommended: retries on
- 408 (Timeout)
- 409 (Conflict)
- 429 (Too Many Requests)
- 502 (Bad Gateway)
- 503 (Service Unavailable)
- 504 (Gateway Timeout)
Use the max_retries request option to configure this behavior.
client.agents.verify_connection(..., request_options={
"max_retries": 1
})
Timeouts
The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
from calibrate import Calibrate
client = Calibrate(..., timeout=20.0)
# Override timeout for a specific method
client.agents.verify_connection(..., request_options={
"timeout_in_seconds": 1
})
Custom Client
You can override the httpx client to customize it for your use-case. Some common use-cases include support for proxies
and transports.
import httpx
from calibrate import Calibrate
client = Calibrate(
...,
httpx_client=httpx.Client(
proxy="http://my.test.proxy.example.com",
transport=httpx.HTTPTransport(local_address="0.0.0.0"),
),
)
Metadata
Release files for calibrate-sdk 0.0.67
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| calibrate_sdk-0.0.67.tar.gz | 89.6 kB | Without provenance | Details for calibrate_sdk-0.0.67.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| calibrate_sdk-0.0.67-py3-none-any.whl | Python 3 | none | any | Details for calibrate_sdk-0.0.67-py3-none-any.whl |
Total release size: 262.2 kB
Release files / calibrate_sdk-0.0.67.tar.gz
| Download URL | calibrate_sdk-0.0.67.tar.gz |
|---|---|
| Size | 89.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c3d9cecb7c148001e7e0d077bbb56ee6194cf0798b863fc0518411b9aebc8618
|
|
BLAKE2b-256 checksum How to use checksums |
b14ff2f9f1937d3d64ee487153aa790156f2e8ecd4d790f308cb25cc846fbd60
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.10.21 Linux/6.17.0-1022-azure
|
Release files / calibrate_sdk-0.0.67-py3-none-any.whl
| Download URL | calibrate_sdk-0.0.67-py3-none-any.whl |
|---|---|
| Size | 172.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1f4dc7f0da47ae2b594809d6eb5c3c6a2f6888e591926ca215120593de583113
|
|
BLAKE2b-256 checksum How to use checksums |
c21db8043af244ee665e079c32474d2300e5ad0b8bbbec7af1ac1c7f42a2c59f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.10.21 Linux/6.17.0-1022-azure
|
Security for calibrate-sdk 0.0.67
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.