Python SDK for the Preclinical healthcare AI safety testing platform
Project description
Preclinical Python SDK
Python SDK for the Preclinical healthcare AI safety testing platform.
Installation
pip install preclinical
Quick Start
from preclinical import Preclinical, CreateTestParams
# Pass api_key directly, or set the PRECLINICAL_API_KEY environment variable
client = Preclinical(api_key="sk_live_...")
# Start a test
test = client.tests.run_and_wait(
CreateTestParams(agent_id="your-agent-id", test_mode="demo")
)
print(f"Status: {test.status}")
print(f"Pass rate: {test.pass_rate}%")
# Get detailed results
results = client.tests.results(test.id)
for r in results.data:
status = "PASS" if r.passed else "FAIL"
print(f"[{status}] {r.scenario_name}")
Usage
from preclinical import Preclinical, CreateAgentParams, CreateTestParams
# Initialize (context manager closes the HTTP client)
with Preclinical(api_key="sk_live_...") as client:
# Agents
agents = client.agents.list()
agent = client.agents.create(CreateAgentParams(
name="My Agent",
provider="openai",
config={"api_key": "sk-...", "base_url": "https://api.openai.com/v1", "target_model": "gpt-4o"},
))
client.agents.validate(agent.id)
# Tests
created = client.tests.create(CreateTestParams(agent_id=agent.id))
test = client.tests.get(created.id)
results = client.tests.results(created.id)
# Scenario runs (with transcript)
run = client.scenario_runs.get(results.data[0].id)
for entry in run.transcript:
print(f"[{entry['role']}]: {entry['content']}")
# Scenarios
scenarios = client.scenarios.list()
# Webhooks
webhooks = client.webhooks.list()
Async Usage
An AsyncPreclinical client is available for async applications (FastAPI, etc.):
from preclinical import AsyncPreclinical, CreateTestParams
async def run_test():
async with AsyncPreclinical(api_key="sk_live_...") as client:
test = await client.tests.run_and_wait(
CreateTestParams(agent_id="your-agent-id", test_mode="demo")
)
print(f"Pass rate: {test.pass_rate}%")
The async client mirrors the sync API exactly -- all methods are async and the client supports async with.
Documentation
Full API docs at docs.preclinical.co
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 preclinical-0.2.1.tar.gz.
File metadata
- Download URL: preclinical-0.2.1.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
486cc8f6df67f5cca041f4ee3e33a65e38a6e636e07fc4ef4065ce7cba20f540
|
|
| MD5 |
4087534fea25a26f9e8ceec3e4b674ed
|
|
| BLAKE2b-256 |
19ef7af7f0fe5067de2986fbdfa52970e75854e30425e4491eae9631f6101f00
|
File details
Details for the file preclinical-0.2.1-py3-none-any.whl.
File metadata
- Download URL: preclinical-0.2.1-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a312ce557f2280751a08e8abdb82ee2168f70f1decc89cd29884b0634ba90012
|
|
| MD5 |
189594f5e4a894ca91be7276752eca89
|
|
| BLAKE2b-256 |
b198e3c7ba0eb775eebb41c75599b30728637a9c322d5db262e74584fa148bd6
|