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

Uploaded CPython 3.14tWindows ARM64

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

Uploaded CPython 3.13tWindows ARM64

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

Uploaded CPython 3.12+Windows ARM64

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

Uploaded CPython 3.12+Windows x86-64

codex_python-1.114.0-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.0-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.0-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.0-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.0-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.0.tar.gz.

File metadata

  • Download URL: codex_python-1.114.0.tar.gz
  • Upload date:
  • Size: 67.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-1.114.0.tar.gz
Algorithm Hash digest
SHA256 63b3651b2cbbd2159b7ea9df79a07d3a600b1059a4ccce2a6beca2cd16c98e8c
MD5 6a87c1e1ebd80a3c85a6df2c11e8b273
BLAKE2b-256 b814ed0133479fcfc2b0575d6c8f60afdcfc5ed080badca12eb6cbe1ecb509d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_python-1.114.0.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.0-cp314-cp314t-win_arm64.whl.

File metadata

File hashes

Hashes for codex_python-1.114.0-cp314-cp314t-win_arm64.whl
Algorithm Hash digest
SHA256 5c60f9a01b54f4d74002bc0477ce6f309c52974e1e951cb35d04cd7e55bc3dcc
MD5 04ceb7758b189be80930742d191654c2
BLAKE2b-256 ef8d4135133ca84f5d5231ebf1f216c9bb599a4dd7b50961a183aeb11a466cab

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_python-1.114.0-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.0-cp313-cp313t-win_arm64.whl.

File metadata

File hashes

Hashes for codex_python-1.114.0-cp313-cp313t-win_arm64.whl
Algorithm Hash digest
SHA256 3bc0d83e50a2b67e8fdc08ef8e6ee4093f6ec3d0858dba6c30a4f2b84bbb8572
MD5 e8c25cc40a49da4752ad01209de58293
BLAKE2b-256 2dd1bb56f4fb69435a341d64ca741d005847b84cea644c6ae90daaf9640d689b

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_python-1.114.0-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.0-cp312-abi3-win_arm64.whl.

File metadata

File hashes

Hashes for codex_python-1.114.0-cp312-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 e70acfa87f8c190a8dd32b8a22ef0dc9f24c96fc53035352fe2d4f92c4a22481
MD5 f1a89f80d5d8a068e2b11f454507a189
BLAKE2b-256 10f7991750015ce1c1eae2a2c7029c67418e396dcf0d9952daaf33a8b0c54247

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.114.0-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 9f9f68f818372356754cbd857452e12ea81fda2c63cfec4ac3b0bfacf0948b78
MD5 782b6d8c6219034a9aa9f32913789b8d
BLAKE2b-256 a42c11788d8677daa3a7ee0ec5e596b80390e24c73a69a22f995d37b7717537e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.114.0-cp312-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 90ce03d32c43c352d5d8c5349d0eb2d9ea52c2011d78c1ce55f0ffd38b7a549f
MD5 be16072aa3f610108cadade4542f620f
BLAKE2b-256 2cbd056c1f7ba93cca3e43b2f910ebabae933d851d0d75c82cbcb5a0cae247df

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.114.0-cp312-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 69d2c47fb42ba1996375e1d66828ae1f22cdaa1dd2480b67eee90666f0a10ba0
MD5 ae12381a66534b7f06e727409f6d13a9
BLAKE2b-256 54834343db1be2078b2564657ecdfe5cf3877bba06f2430d61a4699a38315064

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.114.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3ce9e0249f6245f5d0fa0b015c9166561f33a8d1ae7bee95c473f8e827acf74c
MD5 e45a278eb2dfef0a4c9901b2ebf9e3b6
BLAKE2b-256 44e80a7ec5754c9d1aeac4546179d9cf306456645485b61f21087628eeacea37

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.114.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9876b8db0a35fa143c6eb0a04e879704e67328a88956b791dd2b877b5a073440
MD5 3adfd9366ff7e1473a06935aa042c3d0
BLAKE2b-256 0e7417f8e5a79b572ed0ba23cf2d8bbe1a762d63877078c434c5261bb2c19652

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_python-1.114.0-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.0-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.0-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 bba565879d28b5f01549f439a654f3e49d9b152c07cf331305bed0cea69d74c7
MD5 0797007db6f66e9ee93cc45834372d1b
BLAKE2b-256 7d645cea662a390ab417ccf1098776fb636771b250335cdcfe4618a6fadf020f

See more details on using hashes here.

Provenance

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