Skip to main content

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 · TypeScript 0.0.3 Companion docs: SDK reference Source of truth: Chat and Proxy API · Proxy API · Errors and rate limits. This page maps the public package surfaces at version 0.0.3.

Install and import

PythonTypeScript
Installpip install trinitite==0.0.3npm install @trinitite/sdk@0.0.3
Importfrom trinitite import Trinititeimport { Trinitite } from "@trinitite/sdk"
RuntimePython 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

PythonTypeScript
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:

PythonTypeScript
api_keyapiKey
base_urlbaseUrl
max_retriesmaxRetries
http_clienthttpClient
app_infoappInfo
custom_headerscustomHeaders
strict_validationstrictValidation
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);
OperationPythonTypeScript
Set baselinetr.govern(...)await tr.govern({...})
Create scopetr.scope(name, goal=...)await tr.scope(name, { goal: ... })
Create agenttr.agent(name, goal=...)await tr.agent(name, { goal: ... })
Get clienttr.client(provider, credential=...)tr.client(provider, { credential })
Send call.create(model=..., messages=...)await .create({ model, messages })
Normalizetr.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:

PythonTypeScript
flow_idflowId
mask_manifest_hashmaskManifestHash
routed_modelroutedModel
routing_reasonroutingReason
routing_scoreroutingScore
failover_triggeredfailoverTriggered
failover_stepfailoverStep
scope_idscopeId
cost_centercostCenter
cost_usdcostUsd
correction_value_usdcorrectionValueUsd
value_usdvalueUsd

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:

PythonTypeScript
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.

ClassPython contextTypeScript context
ForcedVerdictInProdErrorexception messageattemptedVerdict
UpgradeRequiredrequired_key, current_plan, upgrade_urlrequiredKey, currentPlan, upgradeUrl
DeploymentBlockedErrorgate_receipt_id, failuresgateReceiptId, failures
ControlPlaneErrorexception messagestatus, path, method, attempts
GovernanceBlockedErrorresult_idresultId
ValidationErrorexception messageschemaId, errors
EventsStreamUnavailableErrorevent_types, scopeeventTypes, scope
ObservabilityStreamUnavailableErrorscope, verdict, subsystemscope, 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_analysis
  • correction_advantage
  • prompt_bom

Root methods follow language casing:

PythonTypeScript
get_baseline()getBaseline()
from_posture(...)await fromPosture(...)
client_transportclientTransport
boot_resultbootResult
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.