Skip to main content

Python SDK client for the Keystone agent evaluation + sandboxed-execution platform

Project description

Keystone SDK for Python

Python client for the Keystone agent evaluation + sandboxed-execution platform. Shares a single source of truth with the TypeScript and Go SDKs — byte-identical cost estimates and prompt rendering across all three.

Install

pip install polarity-keystone

Zero external runtime dependencies — uses only urllib from the standard library.

Quick start

from polarity_keystone import (
    Keystone, traced,
    Factuality, ExactMatch, FileExists,
)

ks = Keystone(api_key="ks_live_...")

# Create an experiment and run it with three client-side scorers.
exp = ks.experiments.create("nightly-regression", spec_id="spec-123")
results = ks.experiments.run_and_wait(
    exp.id,
    scores=[
        Factuality(model="paragon-fast"),
        ExactMatch(expected_key="expected", case_sensitive=False),
        FileExists("output.txt", gate=True),
    ],
)
print(f"pass rate: {results.metrics.pass_rate:.0%}")

# Stream every trace for the experiment.
for trace in ks.export.traces(experiment_id=exp.id):
    print(trace["tool"], trace["cost"])

# Wrap an OpenAI/Anthropic client for auto-trace ingest
from openai import OpenAI
client = ks.wrap(OpenAI(), sandbox_id="sb-xxx")
client.chat.completions.create(model="gpt-4o", messages=[...])  # auto-reports

What's in the SDK

  • 9 client servicessandboxes, specs, experiments, alerts, agents, datasets, scoring, export, prompts
  • 28 built-in scorers across 5 families:
    • Heuristic (6): ExactMatch, Levenshtein, NumericDiff, JSONDiff, JSONValidity, SemanticListContains
    • LLM-judge (9): Factuality, Battle, ClosedQA, Humor, Moderation, Summarization, SQLJudge, Translation, Security
    • RAG (8): ContextPrecision, ContextRecall, ContextRelevancy, ContextEntityRecall, Faithfulness, AnswerRelevancy, AnswerSimilarity, AnswerCorrectness
    • Embedding (1): EmbeddingSimilarity
    • Sandbox invariants (5): FileExists, FileContains, CommandExits, SQLEquals, LLMJudge
  • @Scorer decorator — wrap any (scenario) -> score function
  • @traced decorator + context manager — auto-capture spans with AsyncLocalStorage-equivalent context propagation
  • Client wrappingks.wrap(openai_client, sandbox_id=...) adds transparent trace reporting for OpenAI + Anthropic (sync / async / streaming)
  • auto_instrument() — single call patches every installed provider (OpenAI, Anthropic, Mistral, Google GenAI, LiteLLM, Claude Agent SDK, DSPy, LangChain)
  • Prompt managementks.prompts.create(slug, template) / ks.prompts.get(slug) / Prompt.render(**vars) with server-side audit + byte-identical local renderer
  • Bulk exportks.export.traces(...), .spans(...), .scenarios(...), .scores(...) auto-paginate; ks.export.experiment(id) for full JSON or NDJSON dumps
  • OpenTelemetry bridgewrap() emits gen_ai.* metadata; register_otel_flush() piggy-backs on program shutdown

Versioning

Semver. 0.x = alpha/beta while the API shape settles.

License

MIT.

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

polarity_keystone-0.2.0.tar.gz (55.9 kB view details)

Uploaded Source

Built Distribution

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

polarity_keystone-0.2.0-py3-none-any.whl (58.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: polarity_keystone-0.2.0.tar.gz
  • Upload date:
  • Size: 55.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for polarity_keystone-0.2.0.tar.gz
Algorithm Hash digest
SHA256 49a88d4e2e3808a5c9ae7069dd33a49267d98f9532327ab9b79fd09513973d60
MD5 96108100ee61f450ec471abd5d9ced51
BLAKE2b-256 fdb5c8ef2c592edfb43f8d144f419df5a8f660379cb11ada78e27ac3bd77716e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polarity_keystone-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5f3f5aea2a7ba06582b991c3c6b1da8f07283d8e229dd9df41ecb21e79f79c0c
MD5 d9f07996a72a977b9f25f92dae5e95ba
BLAKE2b-256 34630a641b15db881418b55e479952ba32493281820ad083fc7641bb4895d65f

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