codex-python
Python SDK for Codex with bundled codex binaries inside platform wheels.
This package exposes two supported APIs:
Codex: a simple, local convenience interface backed by a private stdio app-server sessionAppServerClient: a richer app-server client for thread management, streaming events, approvals, and typed protocol access
Canonical import paths:
- use
from codex import ...for the high-levelCodexfacade - use
from codex.app_server import ...for the raw app-server client and app-server option types
Install
pip install codex-python
Which API should I use?
Codex
Use Codex when you want the smallest surface area for local automation:
- one private local app-server session per
Codexinstance - stateless
run*()convenience (fresh internal thread per call) - stateful thread workflows when needed via
start_thread()/resume_thread() - simple request/response usage
- optional streaming over the exec event stream
- structured output via
TurnOptions(output_schema=...)
AppServerClient
Use AppServerClient when you want a deeper integration:
- persistent app-server connection
- thread objects and turn streams
- protocol-native notifications
- server-driven requests such as tool callbacks and approvals
- typed protocol models and raw JSON-RPC access when needed
Quickstart: Codex
from codex import Codex, ThreadStartOptions
client = Codex()
# Simplest one-shot call.
summary = client.run_text("Diagnose the failing tests and propose a fix")
print(summary)
# One-shot call with thread-scoped defaults for that run's fresh internal thread.
summary = client.run_text(
"Diagnose the failing tests in this repo",
thread_options=ThreadStartOptions(
cwd="/repo",
model="gpt-5",
),
)
print(summary)
Use thread_options= on run(), run_text(), run_json(), and run_model() when you want to
set defaults on the fresh internal thread created for that one-shot call. Use
start_thread() / resume_thread() when later runs should share context.
More Codex examples: docs/exec_api.md
Quickstart: AppServerClient
from codex.app_server import AppServerClient, AppServerClientInfo, AppServerInitializeOptions
initialize_options = AppServerInitializeOptions(
client_info=AppServerClientInfo(
name="my_integration",
title="My Integration",
version="0.1.0",
)
)
with AppServerClient.connect_stdio(initialize_options=initialize_options) as client:
thread = client.start_thread()
summary = thread.run_text("Briefly summarize this repository's purpose.")
print(summary)
More app-server examples: docs/app_server.md
For websocket transport, install the optional extra: pip install "codex-python[websocket]".
Dynamic tools
Decorator-driven dynamic tools are available on both SDK surfaces.
Codex
from codex import Codex, dynamic_tool
@dynamic_tool
def lookup_ticket(id: str) -> str:
"""Look up a support ticket by id."""
return f"Ticket {id}: Login requests time out in eu-west-1."
client = Codex()
summary = client.run_text(
"Use the lookup_ticket dynamic tool for ticket 123 and summarize the result.",
tools=[lookup_ticket],
)
print(summary)
AppServerClient
For a complete app-server example using the same decorator-driven flow, see examples/app_server_dynamic_tool.py.
Structured output
Codex
from codex import Codex, TurnOptions
schema = {
"type": "object",
"properties": {"summary": {"type": "string"}},
"required": ["summary"],
"additionalProperties": False,
}
client = Codex()
payload = client.run_json("Summarize repository status", TurnOptions(output_schema=schema))
print(payload["summary"])
AppServerClient
from pydantic import BaseModel
from codex.app_server import AppServerClient, AppServerTurnOptions
class Summary(BaseModel):
summary: str
with AppServerClient.connect_stdio() as client:
thread = client.start_thread()
result = thread.run_model(
"Summarize repository status",
Summary,
)
print(result.summary)
run_model() uses Summary both as the validation model and, by default, as the output schema sent
to Codex. If you want JSON back without validation, you can also pass the model class directly to
output_schema, for example thread.run_json(..., AppServerTurnOptions(output_schema=Summary)).
Streaming
Codex stream
from codex import Codex
from codex.protocol import types as protocol
client = Codex()
stream = client.run("Investigate this bug")
for event in stream:
if isinstance(event, protocol.ItemAgentMessageDeltaNotification):
print(event.params.delta, end="", flush=True)
print()
Codex.run*() starts a fresh internal thread for each call. Use
start_thread() or resume_thread() when you want later runs to share context.
High-level Codex helpers raise ThreadRunError on failed or interrupted terminal turns and
preserve the final turn metadata on the exception for debugging and UI handling.
App-server stream
from codex.app_server import AppServerClient
from codex.protocol import types as protocol
with AppServerClient.connect_stdio() as client:
thread = client.start_thread()
stream = thread.run("Investigate this bug")
for event in stream:
if isinstance(event, protocol.ItemAgentMessageDeltaNotification):
print(event.params.delta, end="", flush=True)
print()
Advanced app-server usage, including typed stable RPC domains such as client.models and the raw client.rpc fallback: docs/app_server_advanced.md
Examples
- examples/basic_conversation.py: minimal
Codexflow - examples/basic_dynamic_tool.py: high-level
Codexdynamic tool flow - examples/app_server_conversation.py: minimal app-server flow
- examples/app_server_websocket_conversation.py: minimal websocket app-server flow
- examples/app_server_stream_events.py: protocol-native app-server streaming
- examples/app_server_tool_handler.py: typed app-server request handling
- examples/app_server_dynamic_tool.py: decorator-driven dynamic tool registration
Bundled binary behavior
By default, the SDK resolves the bundled binary at:
codex/vendor/<target-triple>/codex-app-server/{codex-app-server|codex-app-server.exe}
The bundled app-server runs directly. If it is not present, for example in a source checkout, the
SDK falls back to codex app-server using codex on PATH.
You can override the executable path with:
CodexOptions(codex_path_override=...)codex.app_server.AppServerProcessOptions(codex_path_override=...)
Overrides named codex-app-server* run directly; other overrides run with the app-server
subcommand.
Development
make lint
make test
make test emits a terminal coverage report, writes coverage.xml, and enforces the repository
coverage gate.
If you want to test vendored-binary behavior locally, fetch binaries into codex/vendor:
python scripts/fetch_codex_binary.py --target-triple x86_64-unknown-linux-musl
Metadata
Release files for codex-python 1.153.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| codex_python-1.153.3.tar.gz | 116.5 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| codex_python-1.153.3-cp312-abi3-win_arm64.whl | CPython 3.12 | abi3 | Windows ARM64 | Details |
| codex_python-1.153.3-cp312-abi3-win_amd64.whl | CPython 3.12 | abi3 | Windows x86-64 | Details |
| codex_python-1.153.3-cp312-abi3-musllinux_1_2_x86_64.whl | CPython 3.12 | abi3 | Linux musl 1.2+ x86-64 | Details |
| codex_python-1.153.3-cp312-abi3-musllinux_1_2_aarch64.whl | CPython 3.12 | abi3 | Linux musl 1.2+ ARM64 | Details |
| codex_python-1.153.3-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.12 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| codex_python-1.153.3-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.12 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| codex_python-1.153.3-cp312-abi3-macosx_11_0_arm64.whl | CPython 3.12 | abi3 | macOS 11.0+ ARM64 | Details |
| codex_python-1.153.3-cp312-abi3-macosx_10_12_x86_64.whl | CPython 3.12 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 595.6 MB
Release files / codex_python-1.153.3.tar.gz
| Download URL | codex_python-1.153.3.tar.gz |
|---|---|
| Size | 116.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6462d8f177915be5e6599351f827d3b13c47ed7df4ff2f61086b29f00c0001bc
|
|
BLAKE2b-256 checksum How to use checksums |
208fc72385209570ec3b97cf62468c6b8ac222f990ec0c887ef45bd8f7ef407f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 4, 2026.
Transparency logRelease files / codex_python-1.153.3-cp312-abi3-win_arm64.whl
| Download URL | codex_python-1.153.3-cp312-abi3-win_arm64.whl |
|---|---|
| Size | 74.1 MB |
| Tags | CPython 3.12 Windows ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
f6bd59c85c0fde3ee70a35f0fb256a0bc5cd66b76c82cc803147bfb1f07b5005
|
|
BLAKE2b-256 checksum How to use checksums |
ae5961491d6365ba4b60312ab4fbf9d69b113f49bdd75701ff63e648fc5e8e15
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 4, 2026.
Transparency logRelease files / codex_python-1.153.3-cp312-abi3-win_amd64.whl
| Download URL | codex_python-1.153.3-cp312-abi3-win_amd64.whl |
|---|---|
| Size | 64.2 MB |
| Tags | CPython 3.12 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
356bee11ba01f1a7a1a50c7bd4f0229a27f2022149a5b4ed67b84975d13663b8
|
|
BLAKE2b-256 checksum How to use checksums |
802b11ac161074e27a5eddcdf596eaefccd7c8578a74bbf5f3ff7f16645e98da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 4, 2026.
Transparency logRelease files / codex_python-1.153.3-cp312-abi3-musllinux_1_2_x86_64.whl
| Download URL | codex_python-1.153.3-cp312-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 80.1 MB |
| Tags | CPython 3.12 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
5ff569e3f507ccadf3dd789515e514eb627aea32a7ef5148a067a6f18643433c
|
|
BLAKE2b-256 checksum How to use checksums |
f395f279eaa4112989470f893e7c1a1a0c4694ebb5b48dc80c38c6e9b3c170c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 4, 2026.
Transparency logRelease files / codex_python-1.153.3-cp312-abi3-musllinux_1_2_aarch64.whl
| Download URL | codex_python-1.153.3-cp312-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 74.8 MB |
| Tags | CPython 3.12 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
b6acbdebecb922d903a543d254095488ed614d4281e9618aedf82f8da768bf3a
|
|
BLAKE2b-256 checksum How to use checksums |
4871d7f6ad3ebd3b66c8e77f53d57480e4fd1337fa7250a37eb70c2c51613361
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 4, 2026.
Transparency logRelease files / codex_python-1.153.3-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | codex_python-1.153.3-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 79.9 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
79c3eb9b6865f46dbaa4de8c95f70cfb8d973006ab01ee8684bacd582c3a8d0f
|
|
BLAKE2b-256 checksum How to use checksums |
3018be2da9737d5c6d813df6357ae45475ece759aa4b5aeafc7756ed5049ad15
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 4, 2026.
Transparency logRelease files / codex_python-1.153.3-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | codex_python-1.153.3-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 74.6 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
649080a27862c3dabe1254881f4e1362b05dc6222b4ec8fff1d82f9fdb02ccb0
|
|
BLAKE2b-256 checksum How to use checksums |
d88ce368173ca2363914cb42e4b164f098f2a2ec386480ca299dbdc46dddf9ea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 4, 2026.
Transparency logRelease files / codex_python-1.153.3-cp312-abi3-macosx_11_0_arm64.whl
| Download URL | codex_python-1.153.3-cp312-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 71.3 MB |
| Tags | CPython 3.12 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
4bd4dd1a54408836f1eb5862f8153b6ca3a3a650ad7226c67f70454439963c86
|
|
BLAKE2b-256 checksum How to use checksums |
553de9dcaaa8b93e87d52bff600b4d91e9bd193ee9156a62b06dc230d3bfbdaf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 4, 2026.
Transparency logRelease files / codex_python-1.153.3-cp312-abi3-macosx_10_12_x86_64.whl
| Download URL | codex_python-1.153.3-cp312-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 76.5 MB |
| Tags | CPython 3.12 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
f48ad330ccd6a15df296f79476d3da2e44eeb23971b45727bcff181f9cf32aa9
|
|
BLAKE2b-256 checksum How to use checksums |
24962e0e78ee987d40d0b1a48ba19bd64c993b5183c2a9ac6a2e6aa5532d70b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 4, 2026.
Transparency log