Skip to main content

evalgate-sdk Python reference

Practical reference for evalgate-sdk — generated OpenAPI access, purpose-built helpers, async usage, tracing, evaluations, judges, test suites, and CLI commands.
The evalgate-sdk package is the Python surface for EvalGate’s evaluation control plane. Purpose-built helpers use snake_case names. The generated OpenAPI client provides structural access to every public REST operation by stable operation ID; it does not imply that every operation has a dedicated convenience method. PRODUCT_CAPABILITY_CONTRACT exposes the same versioned workflow-navigation map as evalgate capabilities --format json. Agents can discover the web route, native Python/TypeScript commands, public operations, artifacts, and next step for each governed core workflow without scraping help text. From contract schema 3, capabilities that span operations with different permissions also declare those operations, and select_capability_operation() resolves a stated intent plus already-demonstrated context to one supported operation, or to a typed missing-precondition reason. Both SDKs run the same selection vectors, so the two surfaces cannot drift apart on what a caller may do. The context you pass is informational: it states what has been demonstrated and never itself grants authority, unrecognised values are ignored rather than honoured, and the named command still authorizes for itself when it runs.
select_capability_operation() is source-side only. PyPI remains at 3.6.0, and the selection API postdates even the 3.10.0 TypeScript release, so it is not available from any published Python package. Source parity between the two SDK trees is not published parity.

Install

PyPI remains at 3.6.0 and predates the current 3.10.0 TypeScript release. The install commands above provide that separately governed published package; client-aware setup, Red Team evidence export, init --local, and other 3.10.0 workflows must not be assumed available from PyPI until a matching release is verified. See feature status.
For the current TypeScript and Python CLI source, evalgate login completes a human-approved device flow and stores the session outside the repository in the operating-system user configuration directory. Windows uses %APPDATA%\evalgate\config.json, macOS uses ~/Library/Application Support/evalgate/config.json, and Linux uses ${XDG_CONFIG_HOME:-~/.config}/evalgate/config.json; managed environments may set an absolute EVALGATE_CONFIG_HOME. Repository configuration cannot provide a bearer key or redirect a saved/environment key to another API origin. Alternate origins require HTTPS except localhost and loopback development. The source candidate also exposes evalgate init --local for a cloud coding agent that needs a deterministic gate before any hosted setup. That command requires no account, browser, organization, GitHub remote, API key, or network request and creates no hosted identity. This is a source-parity statement, not a claim about the older package currently published on PyPI.
Current source ignores the legacy repository-local .evalgate/config.json credential. Reconfigure it, remove the file, and rotate the key if it may have entered Git history. Check feature status before assuming this source behavior is present in the current PyPI package.
The canonical PyPI package name is evalgate-sdk. Import it as evalgate_sdk. If you have the legacy pauly4010-evalgate-sdk package installed, migrate to evalgate-sdk.
The CrewAI and AutoGen tracing adapters are lightweight wrappers and do not install those frameworks. Install the CrewAI or AutoGen package used by your application separately.

Import and initialize

Set EVALGATE_API_KEY and EVALGATE_ORGANIZATION_ID in your environment, then call init() with no arguments:

Async usage

The Python SDK is async-first. Use asyncio.run() for top-level scripts, or await inside an async function:

Call any public OpenAPI operation

OpenApiClient consumes the generated operation registry shared with the public OpenAPI contract. Its operation_id type is a generated Literal union, and the runtime validates paths, query names, headers, body requirements, pagination, and cancellation.
Paginated operations use a bounded async iterator. A cancellation event stops an in-flight request with the stable CANCELLED SDK error.

Client methods

The purpose-built modules below use Pythonic snake_case names. They are convenience surfaces, not the public-operation inventory; use OpenApiClient for contract-generated access to operations not listed here.

Prompt Hub and Dataset Hub

The Python CLI exposes both evalgate datasets for the common governed lifecycle and evalgate api <operation-id> for the complete generated public operation registry.

Evaluation packs, Playground, and repository intelligence

The matching native CLI workflow is evalgate repo followed by evalgate packs after reviewing its evidence; evalgate playground turns selected traces into governed cases. Repository scanning reads protected source at one exact commit and never executes repository code; source detection is not represented as runtime confirmation.

Traces

Evaluations

Prompt versions

Prompt-version operations use the generated OpenAPI contract in Python. This keeps path encoding, required parameters, and body validation on the same generated surface as the other public operations without adding a duplicate convenience layer.

LLM judge

create_test_suite

Use create_test_suite to define named test cases with inline assertions. Import TestSuiteConfig and TestSuiteCase from evalgate_sdk.types to get full type hints:
repetitions runs every case independently more than once. minimum_pass_rate controls how many trials must pass; it defaults to 1, so a single failed trial fails the case. Retries remain recovery attempts within one trial and are reported as flaky evidence when they recover. A case is also flaky when trial outcomes or serialized outputs differ.

Portable evaluators, trajectories, and backfills

Evaluators accept inputs, outputs, optional reference_outputs, context, attachments, and metadata. Scalar, tuple, keyed, and multi-result returns normalize to keyed boolean-or-number feedback.
Backfills never call the target model or alter captured observations. Their checkpoints are pinned to the evaluator version and the hashed observation set. create_dataset_snapshot, select_dataset_splits, and run_summary_evaluators provide content-hashed dataset versions, explicit split membership, and dataset-level metrics. The installed pytest plugin remains inert unless --evalgate-evidence or EVALGATE_EVIDENCE_PATH is set. Attach normalized inputs, outputs, references, and feedback from a running test with record_test_evidence(...):

Import LangSmith run exports

Use the pure converter to inspect a LangSmith export before writing anything, then send the same data through the collector-backed uploader:
The converter accepts a run list or {"runs": [...]}, groups runs by trace_id, orders spans by dotted_order, and preserves parent links, inputs and outputs, timing, errors, token usage, cost, tags, feedback summaries, and source IDs. Invalid and duplicate run IDs are reported instead of replaced with invented identities. Uploads use the shared trace collector in bounded batches and preserve partial failure details. This is an explicit import boundary; normal evaluation does not require the hosted LangSmith runtime. Companion open-source judge and gym/env exports follow the same import-boundary rule. Use the TypeScript SDK helpers importExternalJudgeBehaviors and importEnvRunToGoldenCase for Judgeval-shaped behavior scores and Orchard Env / OpenMLE-Gym shaped trajectories; EvalGate does not depend on those hosted runtimes.

WorkflowTracer

WorkflowTracer works the same way as in TypeScript — start and end workflows and agent spans, and record handoffs: For bounded local delegation comparisons, see Evaluate your subagents. Keep root outcomes, child diagnostics, and actual context attribution distinct.

OpenAI integration

Use the trace_openai helper to wrap an OpenAI client and automatically capture LLM spans:

CLI commands

Install the CLI with pip install evalgate-sdk and then run evalgate <command>.
--json is an alias for --format json on login, logout, whoami, link, status, and open. JSON and non-TTY mutation remains preview-only unless --apply is explicit. A saved human session is used only after an explicit credential and EVALGATE_API_KEY; link itself always requires the saved human session. An environment API key authorizes automation against an already established hosted context; it cannot bootstrap link and is unnecessary for init --local or gate.
Repository linkage is durable across branch and commit movement. Each cloud intake is separately pinned to targetSha. For example, a checkout two commits behind main remains linked and locally gate-ready; cloud evidence may target that older commit when GitHub proves it is reachable from main.
Product understanding is Experimental in the current source tree. It is local-only and is not a published-package, REST, or mounted-web availability claim. See Feature status.
Run these authenticated commands after the local gate is working:

GitHub Actions example

The Python CLI spells the one-shot command evalgate auto run; the TypeScript CLI uses npx @evalgate/sdk auto. Both CLIs expose bounded daemon cycles.

Purpose-built capability alignment

The generated OpenAPI registry is the authoritative cross-language operation inventory. Purpose-built APIs are listed separately and are not assumed to be identical.