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.7.tar.gz (35.1 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.7-cp313-cp313-macosx_11_0_arm64.whl (4.8 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12+Windows x86-64

codex_python-0.2.7-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.7-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.7-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.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

Hashes for codex_python-0.2.7.tar.gz
Algorithm Hash digest
SHA256 da99f88aa02b48005c2e42116292166870c81756e60e6fd27b4d0cf48e3fde4e
MD5 70c2c334560c85f3d03c274d94e7d739
BLAKE2b-256 823298f30432b2fce13bc98b3e181c19b96956254b5282eaa8dc8df689db48ef

See more details on using hashes here.

File details

Details for the file codex_python-0.2.7-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for codex_python-0.2.7-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 228d4e7e7be42f8a3c062a644124d2028c498cb8ce8bb93bb6d0be7ded213dc0
MD5 8c515d6afde624c934ce854b219bc279
BLAKE2b-256 96d144e4eb604e709a8f496fe9dddd7ca9b08d1caf5abcd8de63bef793914e07

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for codex_python-0.2.7-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 d47bc2e911de40d481696988267f4b7e294db962dc1aaf7182e9481896a818c6
MD5 f631147246342f0ec09d13f0171bf477
BLAKE2b-256 40287849a8b29e9d220eb61a2a263320cfd4dfb58bc489afd0178df15936084a

See more details on using hashes here.

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

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.7-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for codex_python-0.2.7-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b6a22e7032689135355051ffb94323fa97f9a8e673b797e6918b9237f02204ea
MD5 ee09dbc591a58104a8e8108379dfadd8
BLAKE2b-256 79e23a1bec616d2453aa62acf77f1c9f941a89b6e10b50ec09bb7e86d2ced08d

See more details on using hashes here.

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

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.7-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for codex_python-0.2.7-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b3bd14b7a8c55112ee40d8888c4e72e9ee648e5ad736a9afc51b01153324bea8
MD5 9ac42d7e5998c9798b648f807acb6a0d
BLAKE2b-256 70542c9402f4e69f2a1a1c6b24272057edacd4b25296c8bb72a1accb344694d6

See more details on using hashes here.

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

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.7-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.7-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 a856dbc9628fea26e3d1fc25330377036d86f6a93a6be8face78b69013d2d57e
MD5 c3b0146de66e8c2d534480664201998c
BLAKE2b-256 941d892bd7339878a4a19ec1bfedfa1dcfe4f518316c0fd680894d4b47df7731

See more details on using hashes here.

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

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