Skip to main content

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 session
  • AppServerClient: 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-level Codex facade
  • 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 Codex instance
  • 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

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


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-1.114.1.tar.gz (68.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-1.114.1-cp314-cp314t-win_arm64.whl (47.3 MB view details)

Uploaded CPython 3.14tWindows ARM64

codex_python-1.114.1-cp313-cp313t-win_arm64.whl (47.3 MB view details)

Uploaded CPython 3.13tWindows ARM64

codex_python-1.114.1-cp312-abi3-win_arm64.whl (47.3 MB view details)

Uploaded CPython 3.12+Windows ARM64

codex_python-1.114.1-cp312-abi3-win_amd64.whl (51.8 MB view details)

Uploaded CPython 3.12+Windows x86-64

codex_python-1.114.1-cp312-abi3-musllinux_1_2_x86_64.whl (52.6 MB view details)

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

codex_python-1.114.1-cp312-abi3-musllinux_1_2_aarch64.whl (48.8 MB view details)

Uploaded CPython 3.12+musllinux: musl 1.2+ ARM64

codex_python-1.114.1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (52.4 MB view details)

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

codex_python-1.114.1-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (48.6 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ ARM64

codex_python-1.114.1-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (94.4 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-1.114.1.tar.gz.

File metadata

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

File hashes

Hashes for codex_python-1.114.1.tar.gz
Algorithm Hash digest
SHA256 482c9d78d3b167fd22c920f87b87f5362018b2144b69c91274176be7ec27386a
MD5 c2c80c883704cd7a0ba679d926c8a1f1
BLAKE2b-256 9d5e58c44ed274151e6857313dcafddc42583070ea0e78f0848581c3ff8a809f

See more details on using hashes here.

Provenance

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

Publisher: release-published.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-1.114.1-cp314-cp314t-win_arm64.whl.

File metadata

File hashes

Hashes for codex_python-1.114.1-cp314-cp314t-win_arm64.whl
Algorithm Hash digest
SHA256 0aeebc28d7f0c2cb27f3f06bf02f63e7d1328485133ffcd2b8ea0f772bd79087
MD5 55d0bf1e9c8dc23d7608fd32092363f7
BLAKE2b-256 6a507c0bfcdbd6117140bc2d14b783f5b8ba41dbd7a2668e922b81956c03d1c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_python-1.114.1-cp314-cp314t-win_arm64.whl:

Publisher: release-published.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-1.114.1-cp313-cp313t-win_arm64.whl.

File metadata

File hashes

Hashes for codex_python-1.114.1-cp313-cp313t-win_arm64.whl
Algorithm Hash digest
SHA256 89806fca9d00649f4f792949fa5007bb52f45c50540ae2c7fb4c511c30e0dcc0
MD5 7ba8c90d64e44084fe171ab6987176af
BLAKE2b-256 610b8e131fd817339f697c2fb0371e5d9543197e90e9a5ae24ac974a7de2e39a

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_python-1.114.1-cp313-cp313t-win_arm64.whl:

Publisher: release-published.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-1.114.1-cp312-abi3-win_arm64.whl.

File metadata

File hashes

Hashes for codex_python-1.114.1-cp312-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 68ea6b416f76644d350e6dfdd72de59656b04f8820ab545adb6caa2fa0e9c3cf
MD5 0d6d754fae423335eb31a89841b9da15
BLAKE2b-256 8fac758639e5fb74f677b9199e92f73c8f710c63ed82cd4fb4ed70c57959b244

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_python-1.114.1-cp312-abi3-win_arm64.whl:

Publisher: release-published.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-1.114.1-cp312-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for codex_python-1.114.1-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 abe4c9ef79600a5a6abb1f64da7487215a270e9456b4a5539385ac57f3f1fc40
MD5 4c47b1b5187fdd2e048dc4793fddfc96
BLAKE2b-256 426d74898d5d7f4c9c5cb704c11004ae8814616b1a54c90f71d0ab06337d9e1d

See more details on using hashes here.

Provenance

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

Publisher: release-published.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-1.114.1-cp312-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for codex_python-1.114.1-cp312-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ea45538de3f2869bd353047520c1c9708448c3c233efd1a30a799af49f24cd5f
MD5 8efba211e87cb08620f594fffb474571
BLAKE2b-256 74c395e57aa00bad5a0ea58a4703225890d66dd630fcfbd66a70554ff9da13b8

See more details on using hashes here.

Provenance

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

Publisher: release-published.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-1.114.1-cp312-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for codex_python-1.114.1-cp312-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 e0271d4df93db6bffbc482dd829583cb942fb55ba265eb37867c4d209f75f2a0
MD5 979738c341f92130c8ea7291ecb2178b
BLAKE2b-256 711e93100496ca68db447547939fb9595d8f3d0a508f0e32c026cffcbfdcf202

See more details on using hashes here.

Provenance

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

Publisher: release-published.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-1.114.1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for codex_python-1.114.1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c58ff1afb33d33eac085f59a003cb13069860846e31b23aeae10975018ffb772
MD5 cf6469ff7a9ecc1b3b04ebcf0f6c2ce4
BLAKE2b-256 140aabc719a13a3fee85bfda831de13faf7ef78de31739e663c2705cc436431d

See more details on using hashes here.

Provenance

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

Publisher: release-published.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-1.114.1-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for codex_python-1.114.1-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6a59bd6904da7cddfd403d1c2710a256e217e1dccf945bf7f33c39db67238c47
MD5 d6219cddd5d1816244e9da34c5461a3c
BLAKE2b-256 0190596b86f41079e9c0c705087d61eee334802bd0663dbef95bc50b8d753c00

See more details on using hashes here.

Provenance

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

Publisher: release-published.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-1.114.1-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for codex_python-1.114.1-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 440414012bec1b6ea13ac3d3019411a3e15f4fd50adbdffa016474935d51b4f8
MD5 9e184d2d62e6bc675e7d8ecf47c8c5fd
BLAKE2b-256 d8896c07f337fc44e362c7695d7e30758de720784e084f785d78a681477ccffe

See more details on using hashes here.

Provenance

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

Publisher: release-published.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