A minimal Python library scaffold for codex-python
Project description
codex-python
Native Python bindings for Codex (in‑process execution). Ships as a single package (codex-python) with platform wheels that include the native extension.
- Python: 3.12–3.13 (CI also attempts 3.14)
- Import name:
codex - PyPI: https://pypi.org/project/codex-python/
Install
pip install codex-python
If there’s no prebuilt wheel for your platform/Python, pip will build from source. You’ll need a Rust toolchain and maturin; see “Developing” below.
Quickstart
Run a prompt and collect structured events (typed):
from codex.api import run_exec, CodexClient
from codex.config import CodexConfig, ApprovalPolicy, SandboxMode
cfg = CodexConfig(
model="gpt-5",
model_provider="openai",
approval_policy=ApprovalPolicy.ON_REQUEST,
sandbox_mode=SandboxMode.WORKSPACE_WRITE,
)
# One-shot
events = run_exec("Explain this repo", config=cfg)
# Conversation (streaming)
client = CodexClient(config=cfg)
for ev in client.start_conversation("Add a smoke test"):
print(ev.id, ev.msg)
Notes
Event.msgis typed as a unionEventMsg(also available atcodex.EventMsg).- For raw dict streaming from the native layer, use
codex.native.start_exec_stream.
Configuration (Pydantic)
Use CodexConfig to pass overrides mirrored from Rust ConfigOverrides.
from codex.config import CodexConfig, ApprovalPolicy, SandboxMode
cfg = CodexConfig(
model="gpt-5",
model_provider="openai",
approval_policy=ApprovalPolicy.ON_REQUEST,
sandbox_mode=SandboxMode.WORKSPACE_WRITE,
cwd="/path/to/project",
include_apply_patch_tool=True,
)
CodexConfig.to_dict()emits only fields you set, with enums serialized to kebab‑case strings expected by the core.- For tests and introspection,
codex.native.preview_config(config_overrides=..., load_default_config=...)returns a compact snapshot of the effective configuration.
Troubleshooting
- “codex_native extension not installed”
- Install with
pip install codex-python(wheel) or build locally (see below).
- Install with
- maturin develop fails without a virtualenv
- Use
python -m venv .venv && source .venv/bin/activate(or conda), or runmake dev-nativewhich falls back to build+pip install when no venv is present.
- Use
Developing
Prerequisites
- Python 3.12/3.13
- Rust toolchain (cargo)
- maturin (for native builds)
- uv (optional, for fast Python builds and dev tooling)
Common tasks
- Lint:
make lint(ruff + mypy) - Test:
make test(pytest) - Format:
make fmt - Build native locally:
make dev-native - Generate protocol types from upstream:
make gen-protocol
Protocol types
make gen-protocolgenerates TS types (via Codex or cargo) into.generated/tsand then writes Pydantic models tocodex/protocol/types.py.- Generated models use
model_config = ConfigDict(extra='allow')and place it at the end of each class.
Releasing
- Bump
codex/__init__.pyandcrates/codex_native/Cargo.tomlversions. - Update
CHANGELOG.md. - Tag and push:
git tag -a vX.Y.Z -m "codex-python X.Y.Z" && git push origin vX.Y.Z. - GitHub Actions (publish.yml) builds native wheels across platforms and an sdist, then publishes them via Trusted Publishing (OIDC).
Project layout
.
├── codex/ # Python package
├── crates/codex_native/ # PyO3 native extension
├── scripts/ # generators and helpers
├── .github/workflows/ # CI, publish, native wheels
└── Makefile # common tasks
Links
- Codex repo: https://github.com/openai/codex
- uv: https://docs.astral.sh/uv/
- maturin: https://www.maturin.rs/
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-0.2.7.tar.gz.
File metadata
- Download URL: codex_python-0.2.7.tar.gz
- Upload date:
- Size: 35.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da99f88aa02b48005c2e42116292166870c81756e60e6fd27b4d0cf48e3fde4e
|
|
| MD5 |
70c2c334560c85f3d03c274d94e7d739
|
|
| BLAKE2b-256 |
823298f30432b2fce13bc98b3e181c19b96956254b5282eaa8dc8df689db48ef
|
File details
Details for the file codex_python-0.2.7-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: codex_python-0.2.7-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 4.8 MB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
228d4e7e7be42f8a3c062a644124d2028c498cb8ce8bb93bb6d0be7ded213dc0
|
|
| MD5 |
8c515d6afde624c934ce854b219bc279
|
|
| BLAKE2b-256 |
96d144e4eb604e709a8f496fe9dddd7ca9b08d1caf5abcd8de63bef793914e07
|
File details
Details for the file codex_python-0.2.7-cp312-abi3-win_amd64.whl.
File metadata
- Download URL: codex_python-0.2.7-cp312-abi3-win_amd64.whl
- Upload date:
- Size: 4.5 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 |
d47bc2e911de40d481696988267f4b7e294db962dc1aaf7182e9481896a818c6
|
|
| MD5 |
f631147246342f0ec09d13f0171bf477
|
|
| BLAKE2b-256 |
40287849a8b29e9d220eb61a2a263320cfd4dfb58bc489afd0178df15936084a
|
Provenance
The following attestation bundles were made for codex_python-0.2.7-cp312-abi3-win_amd64.whl:
Publisher:
publish.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-0.2.7-cp312-abi3-win_amd64.whl -
Subject digest:
d47bc2e911de40d481696988267f4b7e294db962dc1aaf7182e9481896a818c6 - Sigstore transparency entry: 513976859
- Sigstore integration time:
-
Permalink:
gersmann/codex-python@38b0d25a8f8193b31977dd9991ec283bcf1ba5e1 -
Branch / Tag:
refs/tags/v0.2.7-rc4 - Owner: https://github.com/gersmann
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@38b0d25a8f8193b31977dd9991ec283bcf1ba5e1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file codex_python-0.2.7-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: codex_python-0.2.7-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 7.6 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 |
b6a22e7032689135355051ffb94323fa97f9a8e673b797e6918b9237f02204ea
|
|
| MD5 |
ee09dbc591a58104a8e8108379dfadd8
|
|
| BLAKE2b-256 |
79e23a1bec616d2453aa62acf77f1c9f941a89b6e10b50ec09bb7e86d2ced08d
|
Provenance
The following attestation bundles were made for codex_python-0.2.7-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish.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-0.2.7-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
b6a22e7032689135355051ffb94323fa97f9a8e673b797e6918b9237f02204ea - Sigstore transparency entry: 513976872
- Sigstore integration time:
-
Permalink:
gersmann/codex-python@38b0d25a8f8193b31977dd9991ec283bcf1ba5e1 -
Branch / Tag:
refs/tags/v0.2.7-rc4 - Owner: https://github.com/gersmann
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@38b0d25a8f8193b31977dd9991ec283bcf1ba5e1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file codex_python-0.2.7-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: codex_python-0.2.7-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 7.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 |
b3bd14b7a8c55112ee40d8888c4e72e9ee648e5ad736a9afc51b01153324bea8
|
|
| MD5 |
9ac42d7e5998c9798b648f807acb6a0d
|
|
| BLAKE2b-256 |
70542c9402f4e69f2a1a1c6b24272057edacd4b25296c8bb72a1accb344694d6
|
Provenance
The following attestation bundles were made for codex_python-0.2.7-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
publish.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-0.2.7-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
b3bd14b7a8c55112ee40d8888c4e72e9ee648e5ad736a9afc51b01153324bea8 - Sigstore transparency entry: 513976886
- Sigstore integration time:
-
Permalink:
gersmann/codex-python@38b0d25a8f8193b31977dd9991ec283bcf1ba5e1 -
Branch / Tag:
refs/tags/v0.2.7-rc4 - Owner: https://github.com/gersmann
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@38b0d25a8f8193b31977dd9991ec283bcf1ba5e1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file codex_python-0.2.7-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.
File metadata
- Download URL: codex_python-0.2.7-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
- Upload date:
- Size: 9.8 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 |
a856dbc9628fea26e3d1fc25330377036d86f6a93a6be8face78b69013d2d57e
|
|
| MD5 |
c3b0146de66e8c2d534480664201998c
|
|
| BLAKE2b-256 |
941d892bd7339878a4a19ec1bfedfa1dcfe4f518316c0fd680894d4b47df7731
|
Provenance
The following attestation bundles were made for codex_python-0.2.7-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:
Publisher:
publish.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-0.2.7-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl -
Subject digest:
a856dbc9628fea26e3d1fc25330377036d86f6a93a6be8face78b69013d2d57e - Sigstore transparency entry: 513976895
- Sigstore integration time:
-
Permalink:
gersmann/codex-python@38b0d25a8f8193b31977dd9991ec283bcf1ba5e1 -
Branch / Tag:
refs/tags/v0.2.7-rc4 - Owner: https://github.com/gersmann
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@38b0d25a8f8193b31977dd9991ec283bcf1ba5e1 -
Trigger Event:
push
-
Statement type: