Skip to content

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

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

AGINDOW SDK for Python

Install

Detect supported API integration changes and configure verified repair in Python applications. Use Python 3.11+ and agindow==0.1.0a2 in your virtual environment. Embedded execution needs no separate AGINDOW key or account. Your application still owns vendor credentials. This pre-alpha package has its own version spelling; the release notice records whether it is published.

bash
python -m pip install agindow==0.1.0a2

Initialize

Agindow loads during construction. sdk.ready is a boolean, not an awaitable. If loading fails, it is false and sdk.load_error retains the exception; guarded calls preserve the original outcome through bypass. Start in observe mode. A true ready value means the engine loaded, not that drift detection has been selected. Call sdk.close() when the instance is no longer needed.

initialize.py · Python
from agindow import Agindow
sdk = Agindow(mode="observe")
print("Engine loaded:", sdk.ready)
if sdk.load_error is not None:
    print("Inspection unavailable; guarded calls will bypass.")
sdk.close()

Guard an existing API call

Save this complete example as orders.py, set API_URL to your HTTPS JSON order endpoint, then run python orders.py. The @sdk.guard decorator wraps the existing Python function. Keep vendor authentication, request headers and timeouts in that function or your current client. The function remains synchronous and returns its ordinary API result; observe does not mutate it or enforce policy blocks. Use operation="write" for writes. This unconfigured example has no selected evidence windows, so an empty event list is expected after a successful read.

orders.py · Python
import json
import os
from urllib.request import urlopen
from agindow import Agindow

sdk = Agindow(mode="observe")
sdk.on("drift", lambda event: print("Drift:", event.verdict))

@sdk.guard(tool="orders.get", operation="read")
def get_order() -> object:
    with urlopen(os.environ["API_URL"], timeout=10) as response:
        order: object = json.load(response)
        return order

try:
    print("API result:", get_order())
    print("AGINDOW events:", [event.type for event in sdk.recent()])
finally:
    sdk.close()

Guard an async operation

Save as orders_async.py and run python orders_async.py with the same API_URL. Decorate an async def and await the guarded function normally. This standard-library example puts blocking HTTP work in asyncio.to_thread; use your existing async client directly when you have one. Original exceptions and cancellation propagate. Cancelling an await does not prove that a blocking thread or a vendor operation stopped. The SDK supplies a callable boundary, not a Python framework adapter.

orders_async.py · Python
import asyncio
import json
import os
from urllib.request import urlopen
from agindow import Agindow

sdk = Agindow(mode="observe")

def fetch_order() -> object:
    with urlopen(os.environ["API_URL"], timeout=10) as response:
        order: object = json.load(response)
        return order

@sdk.guard(tool="orders.get", operation="read")
async def get_order() -> object:
    return await asyncio.to_thread(fetch_order)

async def main() -> None:
    print("API result:", await get_order())
    print("AGINDOW events:", [event.type for event in sdk.recent()])

try:
    asyncio.run(main())
finally:
    sdk.close()

Inspect events

sdk.on(kind, listener) returns an unsubscribe callable; register before guarded calls. sdk.recent() returns a tuple of local events with a default capacity of 100. A drift event reports configured findings; repair means an accepted payload change was applied; blocked reports a policy halt; bypass reports unavailable or skipped inspection; error is diagnostic metadata. No success event is emitted. An empty tuple does not prove that an API is drift-free. Local history is not a durable audit archive. Python fields use names such as event.drift_class and event.latency_us.

events.py · Python
from agindow import Agindow, Event
sdk = Agindow(mode="observe")

def on_drift(event: Event) -> None:
    print(event.tool, event.phase, event.drift_class)

unsubscribe = sdk.on("drift", on_drift)
sdk.on("repair", lambda event: print("Applied repair:", event.byte_identical))
# Subscribe before guarded calls, then inspect the bounded local history.
print(sdk.recent())
unsubscribe()
sdk.close()

Configure detection

Construct Agindow(selection=selection, mode="observe") with a JSON-compatible dictionary. Scope it by tenant, connection, vendor, operation and segment; operation in the selection must match the tool, such as orders.get. Each field specifies request/response side, a JSON Pointer, complete raw JSON documents in baseline/live windows, and enumeration. Collect representative independent evidence for the same operation. The SDK does not learn baselines automatically. Missing or insufficient evidence can produce no finding. Python Verdict uses drift_class and does not expose the Node detector-name arrays. Follow the full runnable Python example before interpreting findings.

Enable verified repair

Selective repair is opt-in. Use SelectiveRepair, RenameRule and a RepairCheck verifier through selective_repair. Python rule fields are source/target. The runnable local example below models a reviewed CRM response rename and checks an independent application snapshot. Replace its reviewed facts and callable for your own integration. A schema check or matching field values alone cannot establish intended meaning. Keep the verifier synchronous and local; load authoritative evidence before the call. Evaluate in observe, then use sdk.configure(mode="repair") to permit application. Confidence must reach 0.97 (0.99 in strict), and supported capture, policy and verification gates must accept. These thresholds are not measured accuracy. A repair event means an actual patch was applied. Runtime payload repair does not edit source files or open PRs.

repair.py · Python
import json
from agindow import Agindow, RenameRule, RepairCheck, SelectiveRepair
# Reviewed application snapshot, loaded independently before the call.
names = {"customer-123": "Ada"}
def verify(check: RepairCheck) -> bool:
    before = json.loads(check.before)
    after = json.loads(check.after)
    return bool(check.rule.migration == "crm-name-v2-reviewed"
                and after.get("id") in names and before.get("id") == after.get("id")
                and before.get("contact_name") == names[after["id"]]
                and after.get("display_name") == names[after["id"]])
sdk = Agindow(mode="observe", selective_repair=SelectiveRepair(
    rules=(RenameRule(tool="crm.customer", side="response", source="contact_name",
                      target="display_name", migration="crm-name-v2-reviewed", confidence=1.0),),
    verify=verify))
# Local illustration of a reviewed migration, not a vendor request.
@sdk.guard(tool="crm.customer", operation="read")
def customer() -> dict[str, str]:
    return {"id": "customer-123", "contact_name": "Ada"}
try:
    sdk.configure(mode="repair")  # After evaluating the rule in observe.
    print(customer())
    print([event for event in sdk.recent() if event.type == "repair"])
finally:
    sdk.close()

Scopes, configuration and cleanup

sdk.wrap(fn, ...) is the callable alternative to a decorator. Use with sdk.context(mode="observe"): or async with sdk.context(mode="observe"): for scoped overrides. ContextVar state belongs to this SDK and the current task; executing calls retain their snapshot. sdk.configure(**changes) changes future calls, while decorator keyword options can override instance/context settings. Close the instance in a finally block; later guarded calls bypass. The reference retains small sync/async scope examples and complete signatures.

Advanced boundaries

guard_remote and guard_remote_async explicitly call a configured remote HTTP host; setting endpoint metadata does not move local calls to a service. No managed execution host is supplied. Python has no Node simulation method, HTTP/framework adapters, report CLI or guest audit drain. Pydantic-preserving projections and sync/async cancellation containment are local host behavior, not a guarantee of all framework or streaming coverage. A response-phase halt can follow a completed upstream write and cannot undo it. Both SDKs package the same detection engine; their language APIs remain different.