Skip to main content

No project description provided

Project description

acodex

Typed Python SDK that wraps the codex CLI.

PyPI version Python versions License: Apache-2.0 codecov Docs

What is acodex?

acodex is a typed Python SDK that spawns the codex CLI and exchanges JSONL events over stdin/stdout. It provides both sync (Codex, Thread) and async (AsyncCodex, AsyncThread) clients, exposes a streaming event API, and supports structured JSON output via JSON Schema.

Why acodex

  • Fully typed public API (mypy-friendly).
  • Sync and async client surfaces.
  • Stream parsed ThreadEvent objects via run_streamed().
  • Completed turns include turn.final_response, turn.items, and turn.usage.
  • Attach local images (UserInputLocalImage) with stable input normalization for text.
  • Request structured JSON output via output_schema.
  • Resume conversations with resume_thread() (threads persisted under ~/.codex/sessions).
  • Cancellation via threading.Event / asyncio.Event (TurnOptions.signal).

Installation (uv)

Prerequisites: Codex CLI

acodex wraps an external CLI. Ensure codex is installed and available on PATH (or pass codex_path_override=... when constructing the client).

One installation option (requires Node.js >=16):

npm install -g @openai/codex
codex --version

Install acodex

uv add acodex

Run a script using the project environment:

uv run python your_script.py

pip install acodex also works, but uv is recommended.

Quickstart (sync)

from acodex import Codex

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 instance to continue the conversation.

Streaming events

Use run_streamed() to react to intermediate progress (tool calls, streaming responses, item updates, and final usage).

from acodex import Codex

codex = Codex()
thread = codex.start_thread()

streamed = thread.run_streamed("Implement the fix")
for event in streamed.events:
    if event.type == "item.completed":
        print("item", event.item)
    elif event.type == "turn.completed":
        print("usage", event.usage)
    elif event.type == "turn.failed":
        print("error", event.error.message)

Structured output (JSON schema)

Provide a JSON Schema per turn via output_schema. The agent returns a JSON response string in turn.final_response.

import json

from acodex import Codex

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

turn = Codex().start_thread().run("Summarize repository status", output_schema=schema)
payload = json.loads(turn.final_response)
print(payload["summary"], payload["status"])

Images in prompts

Provide structured input entries when you need to include images alongside text.

from acodex import Codex
from acodex.types.input import UserInputLocalImage, UserInputText

thread = Codex().start_thread()
turn = thread.run(
    [
        UserInputText(text="Describe this image"),
        UserInputLocalImage(path="./ui.png"),
    ],
)
print(turn.final_response)

Async (brief)

import asyncio

from acodex import AsyncCodex


async def main() -> None:
    thread = AsyncCodex().start_thread()
    turn = await thread.run("Hello from async")
    print(turn.final_response)


asyncio.run(main())

Configuration notes

  • Client options: Codex(codex_path_override=..., env=..., config=..., api_key=..., base_url=...)
  • Thread options: start_thread(working_directory=..., sandbox_mode=..., approval_policy=..., web_search_mode=...)

Links

License

Apache-2.0. See LICENSE.

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

acodex-0.0.1.tar.gz (137.6 kB view details)

Uploaded Source

Built Distribution

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

acodex-0.0.1-py3-none-any.whl (28.9 kB view details)

Uploaded Python 3

File details

Details for the file acodex-0.0.1.tar.gz.

File metadata

  • Download URL: acodex-0.0.1.tar.gz
  • Upload date:
  • Size: 137.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for acodex-0.0.1.tar.gz
Algorithm Hash digest
SHA256 e911adcafe628203442abe17139d1467236263c03cdecd93df3e94203be19d1c
MD5 d5487459e4934674f0450b29a8af23b2
BLAKE2b-256 f5ecf3d473abf73b4c829884e1d232b7162ae6dcd28f3a5a0e02f386dc744b54

See more details on using hashes here.

File details

Details for the file acodex-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: acodex-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 28.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for acodex-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 74a5dadee5b6dccc73064ed3bccaad6900c384a583dc94aace971f8732964870
MD5 9094b7a60743a8692e03f090a2e69808
BLAKE2b-256 3b84ce403188d96f4b07c0f9ee1d7b908a6bedae56e340287df8e0998758790c

See more details on using hashes here.

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