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 and a JSON Schema, then writes Pydantic v2 models to codex/protocol/types.py. The process runs entirely from the native helper in this repo; no manual scripts needed.
  • 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.14.tar.gz (45.9 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.14-cp312-abi3-win_amd64.whl (4.4 MB view details)

Uploaded CPython 3.12+Windows x86-64

codex_python-0.2.14-cp312-abi3-musllinux_1_2_x86_64.whl (7.7 MB view details)

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

codex_python-0.2.14-cp312-abi3-musllinux_1_2_aarch64.whl (7.9 MB view details)

Uploaded CPython 3.12+musllinux: musl 1.2+ ARM64

codex_python-0.2.14-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.14-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.14-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.7 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.14.tar.gz.

File metadata

  • Download URL: codex_python-0.2.14.tar.gz
  • Upload date:
  • Size: 45.9 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.14.tar.gz
Algorithm Hash digest
SHA256 fead261fedbab9e15d46710bcc80877f267a570165fe37a1132ddc45e1ec207b
MD5 fa5560749f100aa047c0bcabe3afa078
BLAKE2b-256 d4a91665acefdaf325d3c0340105c3d09701c6f33758d1289dcb5e03ccb57023

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_python-0.2.14.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.14-cp312-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for codex_python-0.2.14-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 3991583a5a97d3ac2e2ad6eb14e5c02738e4c50094d9108f2f88af27df27354c
MD5 ede11758ca52980aaee9f21667386e9b
BLAKE2b-256 efbbf0f0ad1e065dee0fc5bec1becdab7bff0b61c52766085eb58d3c09cef33f

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_python-0.2.14-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.14-cp312-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for codex_python-0.2.14-cp312-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d2bbfabfd8ee3d7494bfa6cd53ed93689e9117691686ac36adb39d900f39c54a
MD5 cd34493c0f6b32a8119db546983ccc8a
BLAKE2b-256 ff8c9bb3f8653a7bdeae055da7deda481dbf41c1623752e3d66bd8e58840669e

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_python-0.2.14-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.14-cp312-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for codex_python-0.2.14-cp312-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 5fe46c73f93f471fb210ffd8c1b1427a40c8b0ec031b8e265657323e70ff7baf
MD5 1080420646f5a74a40dfcbb24e186170
BLAKE2b-256 3f754a606f0aa2dcfcec73395f24ceb09aca8c4db368086fd04e3618d896c1cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_python-0.2.14-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.14-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for codex_python-0.2.14-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2a7e9d2284c1104cd33cb76ffd8ea0e9fecc508efaf8ef1a3b813117af9d4d7d
MD5 d8299b639e553062445531de3f02d304
BLAKE2b-256 3c9bba02c0a54b84614de1de5cb128a1d05d11d4289b7f7b23edb57b6e12cee5

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_python-0.2.14-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.14-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for codex_python-0.2.14-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ceaf0b2f2eeeac3d5334b5bda8551dbda80990e3730305799c235a605b25bd3a
MD5 6ef38b8b7e241729cfaa501a935416b7
BLAKE2b-256 efbc8ba73b42bbf736d8065c3a71e9a3cdd3d259b827e8ac3b25545431c7c64a

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_python-0.2.14-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.14-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.14-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 2deaa0fec367b67a38fe783a0c607f53cda0e24d621b0b284df8755b299a5c2c
MD5 8f12b8c24b635337acef1b83ddfc8d48
BLAKE2b-256 6cdf7336f9ea8601d1a072c9e05f4e6e754a0002233d1194517c2cbbcc01b030

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_python-0.2.14-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