Skip to main content

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.

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.msg is typed as a union EventMsg (also available at codex.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).
  • maturin develop fails without a virtualenv
    • Use python -m venv .venv && source .venv/bin/activate (or conda), or run make dev-native which falls back to build+pip install when no venv is present.

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-protocol generates TS types (via Codex or cargo) into .generated/ts and then writes Pydantic models to codex/protocol/types.py.
  • Generated models use model_config = ConfigDict(extra='allow') and place it at the end of each class.

Releasing

  • Bump codex/__init__.py and crates/codex_native/Cargo.toml versions.
  • 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codex_python-0.2.10.tar.gz (35.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

codex_python-0.2.10-cp312-abi3-win_amd64.whl (4.5 MB view details)

Uploaded CPython 3.12+Windows x86-64

codex_python-0.2.10-cp312-abi3-musllinux_1_2_x86_64.whl (7.8 MB view details)

Uploaded CPython 3.12+musllinux: musl 1.2+ x86-64

codex_python-0.2.10-cp312-abi3-musllinux_1_2_aarch64.whl (8.0 MB view details)

Uploaded CPython 3.12+musllinux: musl 1.2+ ARM64

codex_python-0.2.10-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.6 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ x86-64

codex_python-0.2.10-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (7.6 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ ARM64

codex_python-0.2.10-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.8 MB view details)

Uploaded CPython 3.12+macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

File details

Details for the file codex_python-0.2.10.tar.gz.

File metadata

  • Download URL: codex_python-0.2.10.tar.gz
  • Upload date:
  • Size: 35.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for codex_python-0.2.10.tar.gz
Algorithm Hash digest
SHA256 b5afce0d2905645146638510564eaa580cd8d92e3e1aab506e369ebe20d966ac
MD5 49eaac474090cbf404d07485ed486502
BLAKE2b-256 cde2920df7d56e3b51f9d77e815be4c93b039418d1ea358b95f90b40e4d1fc34

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_python-0.2.10.tar.gz:

Publisher: publish.yml on gersmann/codex-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codex_python-0.2.10-cp312-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for codex_python-0.2.10-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a3a07317d44d641e9f6310a0378b55d5254f49264eb0f98fdc01bda3d372469a
MD5 23b321ebe8f70df4e888d12c7a400f24
BLAKE2b-256 b232344663e74cffd052f66a306fbc26df08f13de45729baf975ee2c54add1cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_python-0.2.10-cp312-abi3-win_amd64.whl:

Publisher: publish.yml on gersmann/codex-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codex_python-0.2.10-cp312-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for codex_python-0.2.10-cp312-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e765dd1d59325a1f17ad23568c73e6dbaad688c35dee4f99cffc3494712ce2bb
MD5 2627cc8154faab4ab01998628d997396
BLAKE2b-256 1e94b911002548e2afc752218fbd4a534e37518dc2eeb77f75cfc559f44d9394

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_python-0.2.10-cp312-abi3-musllinux_1_2_x86_64.whl:

Publisher: publish.yml on gersmann/codex-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codex_python-0.2.10-cp312-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for codex_python-0.2.10-cp312-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 b76444e22c016490b5ae0c522d83242fca6f6967df90c71edd6bfdd995ef9036
MD5 874d6d870b8518a26745d3d553db14b5
BLAKE2b-256 c61dfd027b4949f9ffb03e85b289e607685a4ccb60774ac827d9b65e582e56da

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_python-0.2.10-cp312-abi3-musllinux_1_2_aarch64.whl:

Publisher: publish.yml on gersmann/codex-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codex_python-0.2.10-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for codex_python-0.2.10-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9ff1d9f372b10e0a9bb0a2fb71cc84b69fd558790212b447e0b17f970640d6d7
MD5 bfa6c19c0cafb0bf3f6495847f603dce
BLAKE2b-256 cc9b8a0c37922e44f4cbdad0afb3f8c8f1a2b04a4d92ea4426b1a1f239f52f27

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_python-0.2.10-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on gersmann/codex-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codex_python-0.2.10-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for codex_python-0.2.10-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c1681eb508f80ef33274734c19815bffb5c4cddf7630ff353ecda07022d18a70
MD5 4db3ec7f6300b30071a3c341add25c2f
BLAKE2b-256 6eea67f2027047a10396d805d9bbd1ddc8cddfb1315178cf7918361355de5a99

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_python-0.2.10-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish.yml on gersmann/codex-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codex_python-0.2.10-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for codex_python-0.2.10-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 1529be893d63f3e0a49029314451c10409768ac3d161a233610ea6d07bed91e6
MD5 82f8e33937d4aca49ed45240f717d883
BLAKE2b-256 2e3234149c3549c1b2f3f65b45a2a861f47bd3d131ca9a47e3a7c1aed6b009a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_python-0.2.10-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:

Publisher: publish.yml on gersmann/codex-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page