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.2.tar.gz (56.0 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.2-py3-none-any.whl (58.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: polarity_keystone-0.2.2.tar.gz
  • Upload date:
  • Size: 56.0 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.2.tar.gz
Algorithm Hash digest
SHA256 0d09dad0df1423dffd57d32baefe7742d677b528596d911281604bfe73852f01
MD5 2d8aa288d1d767d7da080e3de9aeeede
BLAKE2b-256 ebb0ec85121e40631dd99d479f018f36a75038e914b8e404ade39e723bd2593e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polarity_keystone-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0ec6d1b117385d39c04f1f03da92eb241d61b2a220c9b63164ab5e1dc325d3de
MD5 1cefe129b35993aec935f6f9c989385f
BLAKE2b-256 c264ad49b001bdaa6e24df2cbe69073f68fd1a6cf5eb2d59d4b2454fd32fc507

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