Skip to content

Latest commit

 

History

History
63 lines (49 loc) · 2.16 KB

python.md

File metadata and controls

63 lines (49 loc) · 2.16 KB

Python SDK

Use the framework-neutral operation boundary for request-response, stream, and delivered-work operations. A framework adapter can delegate to the same boundary.

Install

python -m pip install reproit-sdk==1.0.0

Open one project, prepare the operation, and run the application callback:

from reproit_sdk import ManagedEngineProject, OperationPreparation, run_operation

project = ManagedEngineProject.open(
    project_toml=project_toml,
    build_repository_id=build_repository_id,
    source_revision=source_revision,
    project_token_provider=load_project_token,
)
preparation = OperationPreparation(
    begin=begin_payload,
    inputs=input_payloads,
    completion="return",
)
result = run_operation(
    project,
    preparation,
    lambda operation: application_call(),
    classify_failure,
)

Use return for request-response, stream-end for stream, and acknowledgment or task-end for delivered work.

The Python layer owns subject discovery, operation context, and Failure translation. The packaged shared engine owns candidate policy, World closure, encryption, delivery, and cleanup. A successful operation is deleted locally.

Automatic observations

Inside run_operation, the SDK automatically captures supported standard-library clock, environment, filesystem, HTTP, randomness, subprocess, SQLite, and queue observations. Application code does not call a capture API for each observation.

The HTTP adapter covers simple urllib.request.urlopen calls made during the operation. It records a later full read() of at most 32 KiB and replays it without live network access. It preserves the live response object and body behavior during capture. Direct http.client calls and partial response reads are unsupported.

The operation stays local if an HTTP response is partial, oversized, malformed, or contains an authentication or cookie header. The operation also stays local when an observation is unsupported or cannot be assigned to exactly one active operation. This behavior prevents incomplete or sensitive Worlds from leaving the process.

Verify SDK source

./tools/with-core.sh python -m pytest sdks/python/tests