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.1.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.1-cp314-cp314t-win_arm64.whl (26.7 MB view details)

Uploaded CPython 3.14tWindows ARM64

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

Uploaded CPython 3.13tWindows ARM64

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

Uploaded CPython 3.12+Windows ARM64

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

Uploaded CPython 3.12+Windows x86-64

codex_python-1.0.1-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.1-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.1-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.1-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.1-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.1.tar.gz.

File metadata

  • Download URL: codex_python-1.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 67c4cc43c3ddbac2d927e2483a78b92f79c56ecb19261e270696c28e23cebb0e
MD5 e2da378dd621d48c808dea950365e78f
BLAKE2b-256 c5c71faa15fad013e8089699ed2839bbb8324ebf2843f7c9447908612bb549e6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.0.1-cp314-cp314t-win_arm64.whl
Algorithm Hash digest
SHA256 fc6d37bce7655723edfc9c88b5e196bcfbb758329e588d9d4aaccce4e4774b31
MD5 12b2d636149e42badf731928e76f8b3b
BLAKE2b-256 3568db0f6c62f27db446b3f96537cbf8449aeff1bcb27403fb8e1c41be52d79c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.0.1-cp313-cp313t-win_arm64.whl
Algorithm Hash digest
SHA256 241490e6a458e16bf89eff9dde119238625d9d95e9a1f508bae29f51cd3846e7
MD5 d4065b2e2d7f8859f8b10d83537ece07
BLAKE2b-256 9a6041912ea76e21ecd0d3135307737f85623d94cc25e349e3836a03f78c3016

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.0.1-cp312-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 00d3567d616a0cb134d6fb1068bead40d204071db3549cc9280470e361328d6c
MD5 f132799205ebde7b91684cca9d7659d4
BLAKE2b-256 4c155d35e88170d822f489009d449a56e87853d1705771c229554ef507720871

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: codex_python-1.0.1-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 29.3 MB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for codex_python-1.0.1-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 6770fd7b2cd70a35f583c3ea4cca6453dd9ae6b9d3c19ce92b242cfa9849f690
MD5 aacafa82f5850c81743cf34efdbe98d3
BLAKE2b-256 21d3c07e5be2087adf9846e35579fca8631eef02f87c380bdb3e50e63e0ac652

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.0.1-cp312-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c2f5245da0ca7b27ce54a3a5d688265809971b7632518c32a07b9d2d0ad62c2c
MD5 c3dfd084a23562287e30b013afe67ca1
BLAKE2b-256 fc725a2146cea4e3aab6ca1fdb0a95b32d9e808b81ce2213b84715e3d41e101c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.0.1-cp312-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 7f41b6685adc477fb344a8af86410080d45a6d4c0a518c5d33cc9b630c7815f2
MD5 fd36134ffd8e539d9b63331111ac9b7f
BLAKE2b-256 89779baa010284443e682275cc938fd8a79fc93d2c2269ea40d3408022b4586a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.0.1-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0b0cc6c0e32a158ad99d4a55c7bc27ea09b31662246ae6acaaf2853e23b5d8ba
MD5 515f866126b1b0cd6bf9abd015cd4399
BLAKE2b-256 a789e002d358119e7e25901fc4baa948321231e592b9d08fa8d2c6d81c071d00

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.0.1-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 905660b91f8e20ad268b7eb45edd0f025f66d4f5c66e41e1e2b5a212f3d314f9
MD5 4c3891b811312151c1120e94bf61c2d6
BLAKE2b-256 6e67af19fe042f41ad1b82d9ef12dd304a46d4ff16fed3b4960c29a42f690a91

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_python-1.0.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.0.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.0.1-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 7d104236e9669e2ce9562b9b71492d330e68291d4e4c707e519af9bcc337c69b
MD5 6cbbdcd0045764a1fd0be4d19e88a215
BLAKE2b-256 935d6fc630ccdeacfacdf055f3c347969120b5ae246afcea24944b02083d67e5

See more details on using hashes here.

Provenance

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