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.

The SDK mirrors the TypeScript SDK behavior:

  • Spawns codex exec --experimental-json
  • Streams JSONL events
  • Supports thread resume, structured output schemas, images, sandbox/model options

Install

pip install codex-python

Quickstart

from codex import Codex

client = Codex()
thread = client.start_thread()

result = thread.run("Diagnose the failing tests and propose a fix")
print(result.final_response)
print(result.items)

Streaming

from codex import Codex

client = Codex()
thread = client.start_thread()

stream = thread.run_streamed("Investigate this bug")
for event in stream.events:
    if event["type"] == "item.completed":
        print(event["item"])
    elif event["type"] == "turn.completed":
        print(event["usage"])

Structured output

from codex import Codex, TurnOptions

schema = {
    "type": "object",
    "properties": {"summary": {"type": "string"}},
    "required": ["summary"],
    "additionalProperties": False,
}

client = Codex()
thread = client.start_thread()
result = thread.run("Summarize repository status", TurnOptions(output_schema=schema))
print(result.final_response)

Input with local images

from codex import Codex

client = Codex()
thread = client.start_thread()
result = thread.run(
    [
        {"type": "text", "text": "Describe these screenshots"},
        {"type": "local_image", "path": "./ui.png"},
        {"type": "local_image", "path": "./diagram.jpg"},
    ]
)

Resume a thread

from codex import Codex

client = Codex()
thread = client.resume_thread("thread_123")
thread.run("Continue from previous context")

Options

  • CodexOptions: codex_path_override, base_url, api_key, config, env
  • ThreadOptions: model, sandbox_mode, working_directory, skip_git_repo_check, model_reasoning_effort, network_access_enabled, web_search_mode, web_search_enabled, approval_policy, additional_directories
  • TurnOptions: output_schema, signal

Cancellation

import threading

from codex import Codex, TurnOptions

cancel = threading.Event()

client = Codex()
thread = client.start_thread()
stream = thread.run_streamed("Long running task", TurnOptions(signal=cancel))

cancel.set()
for event in stream.events:
    print(event)

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 always override with CodexOptions(codex_path_override=...).

Development

make lint
make test

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.0.0b3.tar.gz (12.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.0.0b3-cp314-cp314t-win_arm64.whl (26.7 MB view details)

Uploaded CPython 3.14tWindows ARM64

codex_python-1.0.0b3-cp313-cp313t-win_arm64.whl (26.7 MB view details)

Uploaded CPython 3.13tWindows ARM64

codex_python-1.0.0b3-cp312-abi3-win_arm64.whl (26.7 MB view details)

Uploaded CPython 3.12+Windows ARM64

codex_python-1.0.0b3-cp312-abi3-win_amd64.whl (29.3 MB view details)

Uploaded CPython 3.12+Windows x86-64

codex_python-1.0.0b3-cp312-abi3-musllinux_1_2_x86_64.whl (30.4 MB view details)

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

codex_python-1.0.0b3-cp312-abi3-musllinux_1_2_aarch64.whl (28.2 MB view details)

Uploaded CPython 3.12+musllinux: musl 1.2+ ARM64

codex_python-1.0.0b3-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (30.2 MB view details)

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

codex_python-1.0.0b3-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (28.1 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ ARM64

codex_python-1.0.0b3-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (51.2 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.0.0b3.tar.gz.

File metadata

  • Download URL: codex_python-1.0.0b3.tar.gz
  • Upload date:
  • Size: 12.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.0.0b3.tar.gz
Algorithm Hash digest
SHA256 c7bcc23b02365dee6929f1453634efa31f110b793cfe3c6ca25d08e64660ee4a
MD5 8b655b9a1c1f17ef0396e8424fdbe62f
BLAKE2b-256 3eed550faa293e5130751cfa01327a3dada9c63d88c85a3a6be447985790f3ab

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.0.0b3-cp314-cp314t-win_arm64.whl
Algorithm Hash digest
SHA256 9b638de4acd1df467dbf691a0d83052587b0c123b60c67d7bd2220b8d366b757
MD5 ae2ca0d9313098a6a539843ec56e85a2
BLAKE2b-256 6073e960358876e8375d7849b2de7a8fdafad4dd43bb4e84836648e0d01f73c4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.0.0b3-cp313-cp313t-win_arm64.whl
Algorithm Hash digest
SHA256 6bbcb4c76616bce6e47a8a7c3868e7e2c25b61326743b9954c5e5ea48598d7c9
MD5 355382e9e2ffcad6dbb960b1e685a21c
BLAKE2b-256 b286e9736098b6fbad0445a5048b85f101ed99405650fa751fc0230d55370269

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.0.0b3-cp312-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 cdc75af628f712a459242f1bf64bbc75c12f36ec42b8257060fb791f110423d6
MD5 e120faff46d5e1eff092637a0ad872ed
BLAKE2b-256 f7817a009680938ab178ed03dfb51fc689dcae72897b29186efc74d377be66c8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.0.0b3-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 bded55f6de11be7f6e35b785edadba54e2895494d03d22a7cb0800da91b2b9ce
MD5 814f5fc004d38e4e1ee2334e6e5a101b
BLAKE2b-256 e7e8b5ed84368b7b7a832cfd833b459063349442ec595e69701fb373a6c47452

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.0.0b3-cp312-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 274052c0eade5881b5d38e342319bf4bf88c052c2cd16072842830bd6266f139
MD5 d7de066c0ba763c23fcacaeae63fe4da
BLAKE2b-256 771f29323fbba5bade6145460ba2fd5a4aa43e5d2cfd256961726ee9fdc33a0f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.0.0b3-cp312-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 01c2d8cb8b142cf9929db5bfe6dbeb99bd2ff473de16b83c3402a0d1da0088ad
MD5 682f5753388580d6209ccc0b9c561c91
BLAKE2b-256 8bc1602d9fa53e355da2ae7eebf2f279b304fad0952b60c79f66f4762f29c070

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.0.0b3-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 15fcf85504311cd8a0134e6197cdf8f692c7414162dfea09dabb7e716b3ae83a
MD5 5ada865b38e963456b91c149d5b73d5f
BLAKE2b-256 3fef215c123d16d9e3544e089e918c07a0342aac9cae4df700c9a7d58f71c64d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.0.0b3-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f077ce26c34c9915b2274077ae33d8425224d22e2c20e76916f90701eb58b124
MD5 0ec3cf38a51cf2d6b1830a5d2a086bee
BLAKE2b-256 7b72e710cca64da761c577c48318fa37133c6a5fd7df9fc7466039b80cf6e48d

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_python-1.0.0b3-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.0.0b3-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.0.0b3-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 dc5da8924d324263058642d619cc8df2cfd529399433127bfe3781f2d38a663a
MD5 3d63924e9971c15a820a8264fc1ec515
BLAKE2b-256 f7e6f05b6ebde432f7e6436b5c9c4fbf083eb54dcd727062a44a17888f175c97

See more details on using hashes here.

Provenance

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