Add Python SDK public API and examples#14446
Conversation
Co-authored-by: Codex <noreply@openai.com>
2026-03-12 Switch the repo-source Python SDK real coverage over to a pinned runtime-package flow backed by GitHub release artifacts instead of PATH or explicit binary overrides. - add sdk/python/_runtime_setup.py to download the release codex archive for a requested CODEX_PYTHON_RUNTIME_VERSION, stage a temporary codex-cli-bin package, and install it into a target Python environment with cleanup - refactor real integration tests to run repo-source SDK code against an isolated site-packages target that contains the staged codex-cli-bin runtime - update examples and notebook bootstrap to install and use the runtime package, and stop consulting CODEX_PYTHON_SDK_CODEX_BIN or PATH - switch the failing turn-run and model-selection examples to runtime-compatible model selection for the pinned release binary - keep the main SDK runtime resolution model unchanged: explicit codex_bin or installed codex-cli-bin Validation: - python3 -m pytest sdk/python/tests - RUN_REAL_CODEX_TESTS=1 CODEX_PYTHON_RUNTIME_VERSION=0.115.0-alpha.11 python3 -m pytest sdk/python/tests/test_real_app_server_integration.py Co-authored-by: Codex <noreply@openai.com>
1655fc4 to
3cf1306
Compare
Remove CODEX_PYTHON_RUNTIME_VERSION from the repo bootstrap path and always provision the checked-in pinned codex-cli-bin runtime version for examples, notebook, and real integration coverage. This keeps repo-source Python execution aligned with one binary contract, rewires the real integration harness and notebook bootstrap to use the pinned runtime directly, and updates the docs to describe automatic pinned-runtime provisioning instead of env-driven overrides. Validation: - RUN_REAL_CODEX_TESTS=1 python3 -m pytest sdk/python/tests -rs - RUN_REAL_CODEX_TESTS=1 python3 -m pytest sdk/python/tests/test_real_app_server_integration.py -rs Co-authored-by: Codex <noreply@openai.com>
Update the repo-run examples that still hardcoded gpt-5 so they use the same gpt-5.4 path already succeeding elsewhere in this runtime. This fixes the quickstart, lifecycle, multimodal, parity, CLI, retry, and kitchen-sink examples that were failing with the runtime-side tool_search compatibility error under gpt-5. Validation: - ran all 25 sdk/python example scripts locally - no examples reported failed turns after the model update - remaining empty-item outputs are limited to 02_turn_run and 03_turn_stream_events for follow-up investigation Co-authored-by: Codex <noreply@openai.com>
Update the sync and async turn-run examples to read the thread after a completed turn and print the persisted item count instead of the empty immediate TurnResult.items list. This makes the example output match the current app-server behavior, where the completed turn payload can have empty items even though the persisted thread turn later contains the generated items. Validation: - python3 sdk/python/examples/02_turn_run/sync.py - python3 sdk/python/examples/02_turn_run/async.py Co-authored-by: Codex <noreply@openai.com>
owenlin0
left a comment
There was a problem hiding this comment.
this is a great start! just some initial thoughts about keeping the SDK as thin a wrapper around app-server as possible. will have to think about the public interface a bit more
| turn_id: str | ||
| status: TurnStatus | ||
| error: TurnError | None | ||
| text: str |
There was a problem hiding this comment.
Instead of defining our own types, wherever possible it'd be great to just use the generated Python types directly. So instead of defining a TurnResult, could we just use the auto-generated Turn object? this would mean no text and usage fields, which I think is actually good IMO
my thinking is that we take a lot of thought in developing the app-server API and it should be the canonical interface, so the more we expose it directly the better
There was a problem hiding this comment.
Same goes for the various types below
Remove the SDK alias/result layers so the wrapper surface returns canonical generated app-server models directly. - delete public type alias modules and regenerate v2_all.py against current schema - return InitializeResponse from metadata and generated Turn from run() - update docs, examples, notebook, and tests to use canonical generated models and repo-only text extraction helpers Validation: - PYTHONPATH=sdk/python/src python3 -m pytest sdk/python/tests - GH_TOKEN="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" RUN_REAL_CODEX_TESTS=1 PYTHONPATH=sdk/python/src python3 -m pytest sdk/python/tests -rs Co-authored-by: Codex <noreply@openai.com>
Rename the public SDK wrapper objects from Turn/AsyncTurn to TurnHandle/AsyncTurnHandle so the wrapper control object is clearly distinct from the canonical generated app-server Turn model. Update the top-level exports, public API docs, runtime behavior test coverage, and the Python SDK codegen helper so future generated method signatures preserve the new wrapper names. Co-authored-by: Codex <noreply@openai.com>
…-16) Normalize validated initialize metadata back onto InitializeResponse so successful metadata access exposes populated serverInfo fields even when they were derived from userAgent. Also make async lifecycle guidance explicit in the public surface by documenting async with AsyncCodex() as the preferred entrypoint and aligning the AsyncCodex metadata error message with that model. Co-authored-by: Codex <noreply@openai.com>
|
|
||
|
|
||
| @dataclass(slots=True) | ||
| class TurnHandle: |
There was a problem hiding this comment.
WIP
I kept the wrapper layer for now since it’s still where the per-turn control methods live, but renamed it to TurnHandle/AsyncTurnHandle so we don’t have two different public things both called Turn. The generated app-server Turn stays the canonical returned type, and this wrapper is just the handle around that flow but lmk if we would rather do it differently.
…6-03-16) - bump the repo-managed runtime bootstrap to rust-v0.116.0-alpha.1 so example and integration paths match the current SDK thread/start schema - make release artifact download more robust by retrying metadata lookups without stale auth and preferring deterministic release asset URLs - refresh generated Python artifacts and signature expectations so artifact drift tests pass on the current branch shape - replace the checked-in local image asset with a generated temporary PNG used by the examples and notebook local-image flow - add lightweight tests for pinned runtime doc drift and invalid-auth fallback in runtime metadata resolution Co-authored-by: Codex <noreply@openai.com>
- make 03_turn_stream_events a clean streaming example with curated event output - add 14_turn_controls as a separate steer and interrupt demo with concise summaries - update the notebook and runtime-backed example assertions to match the new example shapes Co-authored-by: Codex <noreply@openai.com>
owenlin0
left a comment
There was a problem hiding this comment.
this looks quite nice! I think we can layer on some nice convenience methods (borrowed from TS SDK) that we can do as a followup to make the common case easy:
- Add a convenience
Thread.run()/AsyncThread.run()method that returns the final assistant response and collected items. - Have those methods accept plain strings as input instead of having to construct
TextInput.
(in addition to the lower-level thread.turn(...) method that returns a turn handle, if the client needs to steer/interrupt/etc.)
owenlin0
left a comment
There was a problem hiding this comment.
naming nit: public_api.py -> api.py?
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
TL;DR
WIP esp the examples
Thin the Python SDK public surface so the wrapper layer returns canonical app-server generated models directly.
Codex/AsyncCodex/Thread/Turnand input helpers, but removes alias-only type layers and custom result modelsmetadatanow returnsInitializeResponseandrun()returns the generated app-serverTurnv2_all.pyagainst current schemaValidation
PYTHONPATH=sdk/python/src python3 -m pytest sdk/python/testsGH_TOKEN="$(gh auth token)" RUN_REAL_CODEX_TESTS=1 PYTHONPATH=sdk/python/src python3 -m pytest sdk/python/tests -rs