Skip to content

You are currently viewing documentation for0.1.0-alpha.2

Saved documentation for 0.1.0-alpha.2 (npm) / 0.1.0a1 (PyPI). Interactive tools use the current release. View latest documentation.

Python

Shared WASM, separate Python host

agindow==0.1.0a1, published on PyPI. Python 3.11+, pinned Wasmtime, and identical WASM bytes to Node. Install with pip install agindow==0.1.0a1. No separate Python detector or framework adapter is shipped.

Validated setup fixture

After pip install agindow==0.1.0a1, save the py tab as example.py and run python example.py. It proves sync/async wrapping, ContextVar scopes, return identity and one labelled closed-engine bypass. It does not demonstrate drift detection: use Quickstart for the configured statistical finding.

import { createAgindow } from 'agindow';
const sdk = createAgindow({ mode: 'observe' });
await sdk.ready;
const payload = { id: 'synthetic-customer' };
let calls = 0;
const read = sdk.guard(() => { calls++; return payload; }, { tool: 'vendor.read', operation: 'read' });
const result = read();
if (result !== payload || calls !== 1) throw Error('Fixture identity changed');
// A labelled unavailable-engine fixture produces one bypass without a hosted key.
const unavailable = createAgindow({ mode: 'observe' }, async () => { throw Error('Synthetic loading fault'); });
await unavailable.ready;
const fallback = unavailable.wrap(() => payload);
if (fallback() !== payload || unavailable.recent().filter(e => e.type === 'bypass').length !== 1) throw Error('Missing bypass');
sdk.configure({ mode: 'observe' });
console.log('Synthetic fixture: original result retained; unavailable engine bypassed once.');
import asyncio
from agindow import Agindow
sdk = Agindow(mode="observe")
payload = {"id": "synthetic-customer"}
@sdk.guard(tool="vendor.read", operation="read")
def read() -> dict[str, str]:
    return payload
@sdk.guard(tool="vendor.read", operation="read")
async def read_async() -> dict[str, str]:
    return payload
with sdk.context(mode="observe"):
    assert read() is payload
async def main() -> None:
    async with sdk.context(mode="observe"):
        assert await read_async() is payload
asyncio.run(main())
# A closed engine is a labelled availability fixture, not vendor drift.
sdk.close()
assert read() is payload
assert len([event for event in sdk.recent() if event.type == "bypass"]) == 1
print("Synthetic fixture: sync/async identity retained; closed engine bypassed once.")

Decorators and ContextVar scopes

Agindow.guard works as a decorator; wrap accepts callables. with sdk.context and async with sdk.context apply ContextVar overrides only to that SDK’s guarded calls, remain isolated across tasks and freeze for call completion. Sync stays sync, async stays async, and cancellation propagates. The py tab validates both scopes and original object identity.

Readiness and configuration

sdk.ready is a synchronous boolean after loading, unlike Node’s Promise; sdk.load_error retains failure. configure changes future calls. Snake_case keywords resolve explicit > environment > nearest JSON .agindowrc > defaults. The statistical guest and observe are defaults; configure windows to detect. sdk.close releases the guest; later calls bypass.

Remote and framework boundaries

guard_remote and guard_remote_async are explicit HTTP APIs, separate from local decorators. There are no Python framework adapters, built-in report CLI, distributed replay or hosted delivery. Use selective_repair with reviewed rename rules and a synchronous independent verifier to opt in; ordinary inspection stays non-mutating.

Method reference

Python uses snake_case configuration. Guard and wrap preserve the original callable type. It does not expose the Node adapter, simulation, CLI or drainAudit methods.

Method / inputReturn / failure
Agindow(**options)SDK instance; keyword configuration includes mode, selection and on_event. Invalid setup raises AgindowSetupError.
sdk.ready / sdk.load_errorBoolean readiness and retained loading failure. ready is not awaitable.
sdk.guard(fn?, tool=..., operation="read", **options)Decorator or wrapped callable with original sync/async behavior. Upstream errors propagate; policy may raise AgindowDriftError.
sdk.wrap(fn, tool=..., operation="read", **options)Wrapped callable; no automatic Python framework adapter.
sdk.context(**options)Sync/async context manager; scoped overrides for this SDK, isolated across tasks.
sdk.configure(**changes)None. Changes future calls.
sdk.on(kind, listener)Unsubscribe callable. Listener failures do not affect upstream execution.
sdk.recent()Tuple of recently retained events, limited by local capacity.
sdk.close()None. Releases the guest; subsequent guarded calls bypass.
guard_remote / guard_remote_async(original, envelope, options)RemoteResponse or fallback value, synchronously or asynchronously; explicit HTTP only.

Configured detection and next steps

Run the Python tab of Quickstart with python detect.py for a real local finding and unchanged/unconfigured/insufficient controls. Python readiness is boolean. Use the shared configuration reference for defaults and the event reference for snake_case field names.

Errors and outcomes

AgindowSetupError identifies deterministic setup misuse before execution. AgindowDriftError identifies a policy halt and exposes phase, verdict, retained outcome and feedback; preserve the original cause. Engine warming, loading failure and inspection faults emit bypass and preserve the original result or exception. A response-phase halt cannot undo a completed upstream write. A no-finding default call does not prove detection is active.

Continue

Use the pinned package for your application runtime and choose embedded or remote execution explicitly.