Language compatibility
Python and TypeScript share the same root, governed call shape, result fields, and error families. Syntax and async behavior differ.
Status: Beta · Python
0.0.3· TypeScript0.0.3Companion docs: SDK reference Source of truth: Chat and Proxy API · Proxy API · Errors and rate limits. This page maps the public package surfaces at version0.0.3.
Install and import
| Python | TypeScript | |
|---|---|---|
| Install | pip install trinitite==0.0.3 | npm install @trinitite/sdk@0.0.3 |
| Import | from trinitite import Trinitite | import { Trinitite } from "@trinitite/sdk" |
| Runtime | Python 3.10+ | Node.js |
The scoped npm package is a direct alias. It depends on trinitite@0.0.3 and re-exports its JavaScript and type declarations.
Construct
| Python | TypeScript |
|---|---|
Trinitite() | new Trinitite() |
Trinitite(env="test", api_key=key) | new Trinitite({ env: "test", apiKey: key }) |
Trinitite(config=Config(...)) | new Trinitite(new Config({...})) |
with Trinitite() as tr: | const tr = new Trinitite(); try { ... } finally { tr.close(); } |
Construction and close() are synchronous in both languages. Python supplies a synchronous context manager. TypeScript callers close the root directly.
Config
Most names map by normal language casing:
| Python | TypeScript |
|---|---|
api_key | apiKey |
base_url | baseUrl |
max_retries | maxRetries |
http_client | httpClient |
app_info | appInfo |
custom_headers | customHeaders |
strict_validation | strictValidation |
Config.from_env() | Config.fromEnv() |
with_timeout(...) | withTimeout(...) |
with_custom_header(...) | withCustomHeader(...) |
Both versions resolve URLs in this order: explicit base URL, region, then environment default. Both validate the API key prefix against prod, test, or dev.
Governed call
response = tr.client(
"openai",
credential="cred_openai_prod",
).chat.completions.create(
model="gpt-4o",
messages=messages,
)
r = tr.result(response)
const response = await tr.client("openai", {
credential: "cred_openai_prod",
}).chat.completions.create({
model: "gpt-4o",
messages,
});
const r = tr.result(response);
| Operation | Python | TypeScript |
|---|---|---|
| Set baseline | tr.govern(...) | await tr.govern({...}) |
| Create scope | tr.scope(name, goal=...) | await tr.scope(name, { goal: ... }) |
| Create agent | tr.agent(name, goal=...) | await tr.agent(name, { goal: ... }) |
| Get client | tr.client(provider, credential=...) | tr.client(provider, { credential }) |
| Send call | .create(model=..., messages=...) | await .create({ model, messages }) |
| Normalize | tr.result(response) | tr.result(response) |
Python auto-creates its local trinitite-base baseline record on the first governed touch. In TypeScript 0.0.3, getBaseline() remains null until await tr.govern(...) runs. Calls in both languages still use the governed proxy.
Per-call governance controls use snake_case in both packages because they are part of the request body. Examples include force_verdict, cost_ceiling_usd_per_call, governance_risk_max, latency_p95_ms, and failover_on.
Result
Result fields map directly by casing:
| Python | TypeScript |
|---|---|
flow_id | flowId |
mask_manifest_hash | maskManifestHash |
routed_model | routedModel |
routing_reason | routingReason |
routing_score | routingScore |
failover_triggered | failoverTriggered |
failover_step | failoverStep |
scope_id | scopeId |
cost_center | costCenter |
cost_usd | costUsd |
correction_value_usd | correctionValueUsd |
value_usd | valueUsd |
The unchanged names are body, status, headers, ok, response, id, verdict, diff, violations, compliance, risk, rationale, retrieval, provenance, receipt, and review.
Python result follow-ups are synchronous. TypeScript result follow-ups return promises:
| Python | TypeScript |
|---|---|
r.explain() | await r.explain() |
r.unmask(text) | await r.unmask(text) |
r.links() | await r.links() |
r.receipt.verify() | await r.receipt.verify() |
r.improve(eval_id=..., count=...) | await r.improve({ evalId: ..., count: ... }) |
Python ReceiptHandle is dict-like, so r.receipt["id"] and r.receipt.get("id") work. TypeScript uses r.receipt.get("id"), has(key), and toJSON().
Errors
The class names match across languages. Error context follows snake_case in Python and camelCase in TypeScript.
| Class | Python context | TypeScript context |
|---|---|---|
ForcedVerdictInProdError | exception message | attemptedVerdict |
UpgradeRequired | required_key, current_plan, upgrade_url | requiredKey, currentPlan, upgradeUrl |
DeploymentBlockedError | gate_receipt_id, failures | gateReceiptId, failures |
ControlPlaneError | exception message | status, path, method, attempts |
GovernanceBlockedError | result_id | resultId |
ValidationError | exception message | schemaId, errors |
EventsStreamUnavailableError | event_types, scope | eventTypes, scope |
ObservabilityStreamUnavailableError | scope, verdict, subsystem | scope, verdict, subsystem |
In Python, catch errors around the direct call. In TypeScript, catch promise rejections from awaited network calls. Constructor validation errors are synchronous in both languages.
Core handles
Most root namespace names are identical. These three retain underscores in both languages:
gap_analysiscorrection_advantageprompt_bom
Root methods follow language casing:
| Python | TypeScript |
|---|---|
get_baseline() | getBaseline() |
from_posture(...) | await fromPosture(...) |
client_transport | clientTransport |
boot_result | bootResult |
results.wait_for_correlation(...) | await results.waitForCorrelation(...) |
Python 0.0.3 also exposes tr.tools, the root tr.unmask(...) helper, and tr.govern.input(...) plus tr.govern.output(...). For the matching TypeScript workflows, use the typed transport namespaces available on the root, including tr.masking, and the standard governed client call.
Where to go next
- Use Get started for complete Python and TypeScript call examples.
- Use this page for promise boundaries and exact casing differences.
- Read Verdicts and modes before branching application behavior on a verdict.