Python SDK for Codex CLI with bundled platform binaries
Project description
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
client = Codex()
summary = client.run_text("Diagnose the failing tests and propose a fix")
print(summary)
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]".
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/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
Bundled binary behavior
By default, the SDK resolves the bundled binary at:
codex/vendor/<target-triple>/codex/{codex|codex.exe}
If the bundled binary is not present, for example in a source checkout, the SDK falls back to
codex on PATH.
You can override the executable path with:
CodexOptions(codex_path_override=...)codex.app_server.AppServerProcessOptions(codex_path_override=...)
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file codex_python-1.114.0.tar.gz.
File metadata
- Download URL: codex_python-1.114.0.tar.gz
- Upload date:
- Size: 67.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63b3651b2cbbd2159b7ea9df79a07d3a600b1059a4ccce2a6beca2cd16c98e8c
|
|
| MD5 |
6a87c1e1ebd80a3c85a6df2c11e8b273
|
|
| BLAKE2b-256 |
b814ed0133479fcfc2b0575d6c8f60afdcfc5ed080badca12eb6cbe1ecb509d8
|
Provenance
The following attestation bundles were made for codex_python-1.114.0.tar.gz:
Publisher:
release-published.yml on gersmann/codex-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codex_python-1.114.0.tar.gz -
Subject digest:
63b3651b2cbbd2159b7ea9df79a07d3a600b1059a4ccce2a6beca2cd16c98e8c - Sigstore transparency entry: 1101945229
- Sigstore integration time:
-
Permalink:
gersmann/codex-python@9aebfdd02f358b7b205e453da4118c98008d44d7 -
Branch / Tag:
refs/tags/v1.114.0 - Owner: https://github.com/gersmann
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-published.yml@9aebfdd02f358b7b205e453da4118c98008d44d7 -
Trigger Event:
release
-
Statement type:
File details
Details for the file codex_python-1.114.0-cp314-cp314t-win_arm64.whl.
File metadata
- Download URL: codex_python-1.114.0-cp314-cp314t-win_arm64.whl
- Upload date:
- Size: 47.3 MB
- Tags: CPython 3.14t, Windows ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c60f9a01b54f4d74002bc0477ce6f309c52974e1e951cb35d04cd7e55bc3dcc
|
|
| MD5 |
04ceb7758b189be80930742d191654c2
|
|
| BLAKE2b-256 |
ef8d4135133ca84f5d5231ebf1f216c9bb599a4dd7b50961a183aeb11a466cab
|
Provenance
The following attestation bundles were made for codex_python-1.114.0-cp314-cp314t-win_arm64.whl:
Publisher:
release-published.yml on gersmann/codex-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codex_python-1.114.0-cp314-cp314t-win_arm64.whl -
Subject digest:
5c60f9a01b54f4d74002bc0477ce6f309c52974e1e951cb35d04cd7e55bc3dcc - Sigstore transparency entry: 1101945509
- Sigstore integration time:
-
Permalink:
gersmann/codex-python@9aebfdd02f358b7b205e453da4118c98008d44d7 -
Branch / Tag:
refs/tags/v1.114.0 - Owner: https://github.com/gersmann
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-published.yml@9aebfdd02f358b7b205e453da4118c98008d44d7 -
Trigger Event:
release
-
Statement type:
File details
Details for the file codex_python-1.114.0-cp313-cp313t-win_arm64.whl.
File metadata
- Download URL: codex_python-1.114.0-cp313-cp313t-win_arm64.whl
- Upload date:
- Size: 47.3 MB
- Tags: CPython 3.13t, Windows ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3bc0d83e50a2b67e8fdc08ef8e6ee4093f6ec3d0858dba6c30a4f2b84bbb8572
|
|
| MD5 |
e8c25cc40a49da4752ad01209de58293
|
|
| BLAKE2b-256 |
2dd1bb56f4fb69435a341d64ca741d005847b84cea644c6ae90daaf9640d689b
|
Provenance
The following attestation bundles were made for codex_python-1.114.0-cp313-cp313t-win_arm64.whl:
Publisher:
release-published.yml on gersmann/codex-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codex_python-1.114.0-cp313-cp313t-win_arm64.whl -
Subject digest:
3bc0d83e50a2b67e8fdc08ef8e6ee4093f6ec3d0858dba6c30a4f2b84bbb8572 - Sigstore transparency entry: 1101945268
- Sigstore integration time:
-
Permalink:
gersmann/codex-python@9aebfdd02f358b7b205e453da4118c98008d44d7 -
Branch / Tag:
refs/tags/v1.114.0 - Owner: https://github.com/gersmann
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-published.yml@9aebfdd02f358b7b205e453da4118c98008d44d7 -
Trigger Event:
release
-
Statement type:
File details
Details for the file codex_python-1.114.0-cp312-abi3-win_arm64.whl.
File metadata
- Download URL: codex_python-1.114.0-cp312-abi3-win_arm64.whl
- Upload date:
- Size: 47.3 MB
- Tags: CPython 3.12+, Windows ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e70acfa87f8c190a8dd32b8a22ef0dc9f24c96fc53035352fe2d4f92c4a22481
|
|
| MD5 |
f1a89f80d5d8a068e2b11f454507a189
|
|
| BLAKE2b-256 |
10f7991750015ce1c1eae2a2c7029c67418e396dcf0d9952daaf33a8b0c54247
|
Provenance
The following attestation bundles were made for codex_python-1.114.0-cp312-abi3-win_arm64.whl:
Publisher:
release-published.yml on gersmann/codex-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codex_python-1.114.0-cp312-abi3-win_arm64.whl -
Subject digest:
e70acfa87f8c190a8dd32b8a22ef0dc9f24c96fc53035352fe2d4f92c4a22481 - Sigstore transparency entry: 1101945560
- Sigstore integration time:
-
Permalink:
gersmann/codex-python@9aebfdd02f358b7b205e453da4118c98008d44d7 -
Branch / Tag:
refs/tags/v1.114.0 - Owner: https://github.com/gersmann
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-published.yml@9aebfdd02f358b7b205e453da4118c98008d44d7 -
Trigger Event:
release
-
Statement type:
File details
Details for the file codex_python-1.114.0-cp312-abi3-win_amd64.whl.
File metadata
- Download URL: codex_python-1.114.0-cp312-abi3-win_amd64.whl
- Upload date:
- Size: 51.8 MB
- Tags: CPython 3.12+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f9f68f818372356754cbd857452e12ea81fda2c63cfec4ac3b0bfacf0948b78
|
|
| MD5 |
782b6d8c6219034a9aa9f32913789b8d
|
|
| BLAKE2b-256 |
a42c11788d8677daa3a7ee0ec5e596b80390e24c73a69a22f995d37b7717537e
|
Provenance
The following attestation bundles were made for codex_python-1.114.0-cp312-abi3-win_amd64.whl:
Publisher:
release-published.yml on gersmann/codex-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codex_python-1.114.0-cp312-abi3-win_amd64.whl -
Subject digest:
9f9f68f818372356754cbd857452e12ea81fda2c63cfec4ac3b0bfacf0948b78 - Sigstore transparency entry: 1101945301
- Sigstore integration time:
-
Permalink:
gersmann/codex-python@9aebfdd02f358b7b205e453da4118c98008d44d7 -
Branch / Tag:
refs/tags/v1.114.0 - Owner: https://github.com/gersmann
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-published.yml@9aebfdd02f358b7b205e453da4118c98008d44d7 -
Trigger Event:
release
-
Statement type:
File details
Details for the file codex_python-1.114.0-cp312-abi3-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: codex_python-1.114.0-cp312-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 52.6 MB
- Tags: CPython 3.12+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90ce03d32c43c352d5d8c5349d0eb2d9ea52c2011d78c1ce55f0ffd38b7a549f
|
|
| MD5 |
be16072aa3f610108cadade4542f620f
|
|
| BLAKE2b-256 |
2cbd056c1f7ba93cca3e43b2f910ebabae933d851d0d75c82cbcb5a0cae247df
|
Provenance
The following attestation bundles were made for codex_python-1.114.0-cp312-abi3-musllinux_1_2_x86_64.whl:
Publisher:
release-published.yml on gersmann/codex-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codex_python-1.114.0-cp312-abi3-musllinux_1_2_x86_64.whl -
Subject digest:
90ce03d32c43c352d5d8c5349d0eb2d9ea52c2011d78c1ce55f0ffd38b7a549f - Sigstore transparency entry: 1101945350
- Sigstore integration time:
-
Permalink:
gersmann/codex-python@9aebfdd02f358b7b205e453da4118c98008d44d7 -
Branch / Tag:
refs/tags/v1.114.0 - Owner: https://github.com/gersmann
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-published.yml@9aebfdd02f358b7b205e453da4118c98008d44d7 -
Trigger Event:
release
-
Statement type:
File details
Details for the file codex_python-1.114.0-cp312-abi3-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: codex_python-1.114.0-cp312-abi3-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 48.8 MB
- Tags: CPython 3.12+, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69d2c47fb42ba1996375e1d66828ae1f22cdaa1dd2480b67eee90666f0a10ba0
|
|
| MD5 |
ae12381a66534b7f06e727409f6d13a9
|
|
| BLAKE2b-256 |
54834343db1be2078b2564657ecdfe5cf3877bba06f2430d61a4699a38315064
|
Provenance
The following attestation bundles were made for codex_python-1.114.0-cp312-abi3-musllinux_1_2_aarch64.whl:
Publisher:
release-published.yml on gersmann/codex-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codex_python-1.114.0-cp312-abi3-musllinux_1_2_aarch64.whl -
Subject digest:
69d2c47fb42ba1996375e1d66828ae1f22cdaa1dd2480b67eee90666f0a10ba0 - Sigstore transparency entry: 1101945469
- Sigstore integration time:
-
Permalink:
gersmann/codex-python@9aebfdd02f358b7b205e453da4118c98008d44d7 -
Branch / Tag:
refs/tags/v1.114.0 - Owner: https://github.com/gersmann
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-published.yml@9aebfdd02f358b7b205e453da4118c98008d44d7 -
Trigger Event:
release
-
Statement type:
File details
Details for the file codex_python-1.114.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: codex_python-1.114.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 52.4 MB
- Tags: CPython 3.12+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ce9e0249f6245f5d0fa0b015c9166561f33a8d1ae7bee95c473f8e827acf74c
|
|
| MD5 |
e45a278eb2dfef0a4c9901b2ebf9e3b6
|
|
| BLAKE2b-256 |
44e80a7ec5754c9d1aeac4546179d9cf306456645485b61f21087628eeacea37
|
Provenance
The following attestation bundles were made for codex_python-1.114.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release-published.yml on gersmann/codex-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codex_python-1.114.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
3ce9e0249f6245f5d0fa0b015c9166561f33a8d1ae7bee95c473f8e827acf74c - Sigstore transparency entry: 1101945391
- Sigstore integration time:
-
Permalink:
gersmann/codex-python@9aebfdd02f358b7b205e453da4118c98008d44d7 -
Branch / Tag:
refs/tags/v1.114.0 - Owner: https://github.com/gersmann
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-published.yml@9aebfdd02f358b7b205e453da4118c98008d44d7 -
Trigger Event:
release
-
Statement type:
File details
Details for the file codex_python-1.114.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: codex_python-1.114.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 48.6 MB
- Tags: CPython 3.12+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9876b8db0a35fa143c6eb0a04e879704e67328a88956b791dd2b877b5a073440
|
|
| MD5 |
3adfd9366ff7e1473a06935aa042c3d0
|
|
| BLAKE2b-256 |
0e7417f8e5a79b572ed0ba23cf2d8bbe1a762d63877078c434c5261bb2c19652
|
Provenance
The following attestation bundles were made for codex_python-1.114.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
release-published.yml on gersmann/codex-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codex_python-1.114.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
9876b8db0a35fa143c6eb0a04e879704e67328a88956b791dd2b877b5a073440 - Sigstore transparency entry: 1101945600
- Sigstore integration time:
-
Permalink:
gersmann/codex-python@9aebfdd02f358b7b205e453da4118c98008d44d7 -
Branch / Tag:
refs/tags/v1.114.0 - Owner: https://github.com/gersmann
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-published.yml@9aebfdd02f358b7b205e453da4118c98008d44d7 -
Trigger Event:
release
-
Statement type:
File details
Details for the file codex_python-1.114.0-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.
File metadata
- Download URL: codex_python-1.114.0-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
- Upload date:
- Size: 94.4 MB
- Tags: CPython 3.12+, macOS 10.12+ universal2 (ARM64, x86-64), macOS 10.12+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bba565879d28b5f01549f439a654f3e49d9b152c07cf331305bed0cea69d74c7
|
|
| MD5 |
0797007db6f66e9ee93cc45834372d1b
|
|
| BLAKE2b-256 |
7d645cea662a390ab417ccf1098776fb636771b250335cdcfe4618a6fadf020f
|
Provenance
The following attestation bundles were made for codex_python-1.114.0-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:
Publisher:
release-published.yml on gersmann/codex-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codex_python-1.114.0-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl -
Subject digest:
bba565879d28b5f01549f439a654f3e49d9b152c07cf331305bed0cea69d74c7 - Sigstore transparency entry: 1101945432
- Sigstore integration time:
-
Permalink:
gersmann/codex-python@9aebfdd02f358b7b205e453da4118c98008d44d7 -
Branch / Tag:
refs/tags/v1.114.0 - Owner: https://github.com/gersmann
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-published.yml@9aebfdd02f358b7b205e453da4118c98008d44d7 -
Trigger Event:
release
-
Statement type: