Skip to main content

Unofficial Python SDK for the OpenAI Codex CLI.

Project description

Unofficial Codex SDK (Python)

Unofficial, community-maintained Python SDK for the Codex CLI.

This project is not an official OpenAI SDK. It wraps the codex CLI from @openai/codex, spawning the CLI and exchanging JSONL events over stdin/stdout.

Installation

pip install codex-sdk-unofficial

Requires Python 3.10+ and a codex executable on your PATH (or pass codex_path_override).

Status

  • Package name: codex-sdk-unofficial
  • Import name: codex_sdk
  • Current version: 0.1.1
  • Stability: alpha

Quickstart

from codex_sdk import Codex, __version__

print("codex_sdk version:", __version__)

codex = Codex()
thread = codex.start_thread()
turn = thread.run("Diagnose the test failure and propose a fix")

print(turn.final_response)
print(turn.items)

Call run() repeatedly on the same Thread to continue a conversation.

next_turn = thread.run("Implement the fix")

Streaming responses

run() buffers events until completion. To react to intermediate progress, use run_streamed().

streamed = thread.run_streamed("Diagnose the test failure and propose a fix")
for event in streamed.events:
    if event["type"] == "item.completed":
        print("item", event["item"])
    elif event["type"] == "turn.completed":
        print("usage", event["usage"])

Structured output

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

turn = thread.run("Summarize repository status", {"output_schema": schema})
print(turn.final_response)

Attaching images

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

Resuming an existing thread

thread = codex.resume_thread("thread_id_here")
thread.run("Implement the fix")

Working directory and execution options

thread = codex.start_thread(
    {
        "working_directory": "/path/to/project",
        "skip_git_repo_check": True,
        "sandbox_mode": "workspace-write",
    }
)

Overriding CLI environment

codex = Codex(
    {
        "env": {"PATH": "/usr/local/bin"},
    }
)

Global --config overrides

codex = Codex(
    {
        "config": {
            "show_raw_agent_reasoning": True,
            "sandbox_workspace_write": {"network_access": True},
        }
    }
)

Publish Checklist

  1. Update pyproject.toml version and src/codex_sdk/__init__.py __version__.
  2. Run tests:
    PYTHONPATH=src uv run pytest -q
    
  3. Build artifacts:
    uv run --with build python -m build
    
  4. Commit and create a version tag:
    git add .
    git commit -m "release: v0.1.1"
    git tag -a v0.1.1 -m "v0.1.1"
    
  5. Push GitHub branch + tags:
    git push origin main --tags
    
  6. Publish to PyPI (after creating a trusted publisher or API token):
    uv run --with twine twine upload dist/*
    

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_sdk_unofficial-0.1.1.tar.gz (19.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

codex_sdk_unofficial-0.1.1-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file codex_sdk_unofficial-0.1.1.tar.gz.

File metadata

  • Download URL: codex_sdk_unofficial-0.1.1.tar.gz
  • Upload date:
  • Size: 19.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for codex_sdk_unofficial-0.1.1.tar.gz
Algorithm Hash digest
SHA256 fd57fee526b36628da8951f05a1d60c422143bd8cda0986633b851e82ce916a6
MD5 1d2f72e3529fe9d20f88f1e831fb4b71
BLAKE2b-256 b1038e48478d0e8fe6dc79a91a0af19428f33561925e659d729cd0ccad4b6061

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_sdk_unofficial-0.1.1.tar.gz:

Publisher: publish.yml on Goodbuilder34/codex-sdk-unofficial

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_sdk_unofficial-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for codex_sdk_unofficial-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 84b6a300862ce2bc94aff75217d19d659f5ff0926dbf21454e3adc35a466139c
MD5 11a257a08e831fdc7387a69db42da4b6
BLAKE2b-256 12c2aa8f3793a3e604e2977c4ce120c9cf9bc34b4a4b9ef0e8da2f7ee3ea7a27

See more details on using hashes here.

Provenance

The following attestation bundles were made for codex_sdk_unofficial-0.1.1-py3-none-any.whl:

Publisher: publish.yml on Goodbuilder34/codex-sdk-unofficial

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