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

The package is not yet published to PyPI. Install from source:

pip install /path/to/preclinical/sdk/python

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.0.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.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: preclinical-0.2.0.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.0.tar.gz
Algorithm Hash digest
SHA256 ee4885faf762d11af466054d053f40908fd52205785c1f922ab70ab096c73e41
MD5 766dc564f53dcdfcfcb3bf62eb69db14
BLAKE2b-256 354f6b20bbbb94c06d31cf7676f678cf4c50d3daca74128ba98397ce6bafc1b4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: preclinical-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 25ce08c1e838a2c026cdd4f9e636e5ba303845169c161fea5549ecc4b3140dda
MD5 e0226f00eeb6aa1b86b54815355ed193
BLAKE2b-256 976dc07488a417c542b5fe3a5b435b47bbc1e7b437ffc13a6c5507f5e70da7bf

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