Skip to main content

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

preclinical-0.2.2.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

preclinical-0.2.2-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file preclinical-0.2.2.tar.gz.

File metadata

  • Download URL: preclinical-0.2.2.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for preclinical-0.2.2.tar.gz
Algorithm Hash digest
SHA256 21b026584e00c02ba1c8b8d88b2e6b6426e1c46bec7a9d60ec213cfa95ae98ac
MD5 78854c1fe84507f23f9d58ebf74a3c5b
BLAKE2b-256 7fdf3c32eb99d9eb039c9aa03953abf67b0f0e2bc8849d8fd168f2803d86d955

See more details on using hashes here.

File details

Details for the file preclinical-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: preclinical-0.2.2-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

Hashes for preclinical-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 de4c0333a16e85c055269749b97737488d958a93f405701db4e318196983c53b
MD5 b354cbccf695fbbfa7345e93e0d7cf02
BLAKE2b-256 24490de3e0540c231b973b68ced2cbc7318a06a411bb4446dca4fa4d104f0cb0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page