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, ThreadStartOptions

client = Codex()

# Simplest one-shot call.
summary = client.run_text("Diagnose the failing tests and propose a fix")
print(summary)

# One-shot call with thread-scoped defaults for that run's fresh internal thread.
summary = client.run_text(
    "Diagnose the failing tests in this repo",
    thread_options=ThreadStartOptions(
        cwd="/repo",
        model="gpt-5",
    ),
)
print(summary)

Use thread_options= on run(), run_text(), run_json(), and run_model() when you want to set defaults on the fresh internal thread created for that one-shot call. Use start_thread() / resume_thread() when later runs should share context.

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]".

Dynamic tools

Decorator-driven dynamic tools are available on both SDK surfaces.

Codex

from codex import Codex, dynamic_tool


@dynamic_tool
def lookup_ticket(id: str) -> str:
    """Look up a support ticket by id."""
    return f"Ticket {id}: Login requests time out in eu-west-1."


client = Codex()
summary = client.run_text(
    "Use the lookup_ticket dynamic tool for ticket 123 and summarize the result.",
    tools=[lookup_ticket],
)
print(summary)

AppServerClient

For a complete app-server example using the same decorator-driven flow, see examples/app_server_dynamic_tool.py.

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

Uploaded CPython 3.14tWindows ARM64

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

Uploaded CPython 3.13tWindows ARM64

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

Uploaded CPython 3.12+Windows ARM64

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

Uploaded CPython 3.12+Windows x86-64

codex_python-1.114.2-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.2-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.2-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.2-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.2-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.2.tar.gz.

File metadata

  • Download URL: codex_python-1.114.2.tar.gz
  • Upload date:
  • Size: 74.2 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.2.tar.gz
Algorithm Hash digest
SHA256 a31eef04fe215a5acb229d7c60d21763de7e3a491a8bed4726f626228bcdab01
MD5 ea24c7dc3d597859ef8aaad77d10df7c
BLAKE2b-256 a541cbe6f753abe903d9be11c5f961be2d405e0193fac4126e051fb3735fd7b8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.114.2-cp314-cp314t-win_arm64.whl
Algorithm Hash digest
SHA256 753f1dd30278aad8de4dfda461fe26ffb6e5ae113fe4cb509baca39edbfd972f
MD5 6ed108cb8ccc03c382d479287376abf2
BLAKE2b-256 fa4b55de4c888911a8bd27a8b29969b350c2326e256b7fb745885b5178b867c8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.114.2-cp313-cp313t-win_arm64.whl
Algorithm Hash digest
SHA256 0a8e5da7a9d7577c8de48e3c05b5e1ab304b005e119914846de1768c9880a9d9
MD5 99a104ce33a34ec04ca41476956de90c
BLAKE2b-256 2669cc3b41c7cb832c1890d23cd2ade991d2831d8ea8c06bf5f6ca67647830b0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.114.2-cp312-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 5d5eea6365d17844fd427a372780a178873e3f15e641d104a93eb8dd23355a4b
MD5 3adde06963e6fa90ba946468f0b33ef9
BLAKE2b-256 2ad516bf503176c417ae046fd8bf055c7393b51c4c874950edc7881abb038db7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.114.2-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f75b4371a6b25c1d2f7b00cde50fa7e4cb3880798477f87f16cc89e1feada3f5
MD5 9d1784e75df11b173f7f7e7699eb4883
BLAKE2b-256 426dca7a9da52fde034b180b0886a679d35ba16e681f1751c72a108af4bc3f28

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.114.2-cp312-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 7d3d8446b6ac6754af312913ac71361177e924045bed2ff6d1a544bd44f8b291
MD5 c9afb9610e20d367f2b8f1eabd3fba89
BLAKE2b-256 1b79821ac76cdd83e9130f0b6d0f6660df5687b0dec759ced57692887a0463b3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.114.2-cp312-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 68dd276061e277733b304ef85a7d505e3af477733038a191560743f1453bd61b
MD5 d164d6ff444638797eacf96c502106b9
BLAKE2b-256 1cebc8b0ab81ec30f4342fc0159107b54cc17ac9814a875daef41c5c5a3a833c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.114.2-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e2ff80d974eb7fc86eaeeeab392b8843de23da68bbf319fc7722114e607bbf9c
MD5 de9f6f55acfc60b5789b701a9f3dc99c
BLAKE2b-256 a8ec50d5f75f2f372181537138ba82d6df79f25220817ec7dc03699ee20ee147

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.114.2-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b53782827250b0c1cca31ae81bbc6844124587724261f0202a61255d4ca3af62
MD5 a723e6da7218483938dad2db80c3303b
BLAKE2b-256 22c03426fb605d825b0a3cd05944790173cf9b76caafce0d5f1e786baaa8eda2

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_python-1.114.2-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.2-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.2-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 ed5cfc711823cb42fd97ad18b1f6f34a090bc5fe574980fc2ea76d6ed4d009df
MD5 7958216c2e63e662f8bd6efc9ff02676
BLAKE2b-256 8131cceec5d42f262d21a6a295870218f0455fd4e8bffd617751e7e3b86fddbb

See more details on using hashes here.

Provenance

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