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

Uploaded CPython 3.14tWindows ARM64

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

Uploaded CPython 3.13tWindows ARM64

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

Uploaded CPython 3.12+Windows ARM64

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

Uploaded CPython 3.12+Windows x86-64

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

File metadata

  • Download URL: codex_python-1.0.0b2.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.0b2.tar.gz
Algorithm Hash digest
SHA256 e4a37050b0abf117d40194b2cf00a182c5276e196df1cb072bf779f08014906a
MD5 b6bcae6ecfd3d14f77a4964f0e69b565
BLAKE2b-256 70c97389fb8606c07042ebd379c648bb80e3d094b40993ba48198f5d7f95a98b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.0.0b2-cp314-cp314t-win_arm64.whl
Algorithm Hash digest
SHA256 36befc6afeab4ced85eb483051f76bc3d28d55179525f128ce9940a0dc029e89
MD5 9f37bdfaee8d7d4279f7b5358fb106c2
BLAKE2b-256 3607624f6737c1806cef04a7f235faf12a9fbe9ba739e81b40447c60a466b5c4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.0.0b2-cp313-cp313t-win_arm64.whl
Algorithm Hash digest
SHA256 3a5ba1e137f9053a949d83d79608a16ad94ad8c4c33b2fe3c6638cb0f2c2d2e7
MD5 5c201fd25ece682a7279405953a3edad
BLAKE2b-256 4f060fbf8996b0f4221f5fb2eefd5d5b1cbad88a749eb95c8c2e14a6b916e1e3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.0.0b2-cp312-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 b7a35aa2eb7de4e39d0682cf53c9465daf53ea0d004ca6abf2231792b35ec470
MD5 034ef17a0d12081f3d623dd5d10f1e97
BLAKE2b-256 31cc18e19dbd2601dc3a71fe80052b596ed72dbae8cbfc43ded1c280184369d5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.0.0b2-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 984af2777096b30f7646a9563e5d9dab60e505ce767c3ea8ab0417da0f9a5c5a
MD5 2efbe072a8be16f6b139659e7c8feace
BLAKE2b-256 84baf706827e44c2e05d5d606ec23e2d888e775006b6d0b84398a5d9873bc589

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.0.0b2-cp312-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2df5a3e9eb3850c96b67bd1fb0dd7e02744027248312927497f15cd1b34d399c
MD5 aab3853c13270342e6be80d0a6a438e4
BLAKE2b-256 89ff7875a530a5e9c10f8fd3496ae0e2d788091962cfd197a5166c6ca251b5ca

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.0.0b2-cp312-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 7549884e8263414b2101280ddde149b7cc5c301ffcae6c84be0d40341faa006f
MD5 ae941534d5641b10410a0201a30352af
BLAKE2b-256 058bf9e2cb8a7966e30e632eaa094dc619c9051a9e6688ca87ebb87af1449074

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.0.0b2-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a1198f835063fcb9a06ddab97a6dbc1e3e6a86c43414040ff786eeff24f07a3d
MD5 b953b79d1f011a1d0698a7f431ee0b6f
BLAKE2b-256 3ce936024c84d0396b02f7d1b1961d5666293306150058e477720b51ddf42585

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codex_python-1.0.0b2-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c7e31caa7179d6e157fe68324cca98c0de28ee9b5c7f72e560bcfcac2cc12309
MD5 554c9a4f85aaa4ddb9e4faacea256551
BLAKE2b-256 7f7234454beed85bf0fbfe7fae9a6a7c4a7e0f251fcdf35a79d7547291b697b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_python-1.0.0b2-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.0b2-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.0b2-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 fbcf9828a879e670e78d65b1e00845a2c0beee8adb9dc29ec2128a5f6569a08c
MD5 23ea9ed1f5b02d107a1c6c54703f2375
BLAKE2b-256 caaaa8be6bfae98bd693549bec5ee7a740cd08a906a42103c9fa83e3e24f0482

See more details on using hashes here.

Provenance

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