Skip to main content

Run Codex or Claude Code non-interactively from Python, backed by a Rust core.

Project description

codexcw (Python)

Run Codex or Claude Code non-interactively from Python, backed by a Rust core. The Codex agent wraps codex exec --json; the Claude agent wraps claude -p --output-format stream-json. Both expose iterables, callbacks, results, typed usage, and typed errors through the same API.

The selected agent executable must be on PATH and authenticated. Codex must support codex exec --json; Claude must support --output-format stream-json. Defaults are automation-friendly: ephemeral sessions and non-interactive execution, with Codex using a read-only sandbox and approval never.

The Claude agent is selected with Runner(agent=codexcw.AGENT_CLAUDE); its events are normalized into the same event model, with model selection via the haiku/sonnet/opus aliases (CLAUDE_MODEL_*).

Install

pip install codexcw

Usage

from codexcw import Runner, Request

runner = Runner()
result = runner.run(Request(prompt="diga oi"))
print(result.final_message)
print(result.usage.total_tokens)
print(result.usage.total_cost_usd)

Streaming

from codexcw import Runner, Request

runner = Runner()
session = runner.start(Request(prompt="resuma este repo"))
for event in session.events():
    if event.type == "item.completed" and event.item.type == "agent_message":
        print(event.item.text)
result = session.wait()

Account usage

from codexcw import AccountUsageRequest, get_account_usage

usage = get_account_usage(AccountUsageRequest(env={"CODEX_HOME": "/tmp/codex-home"}))
print(usage.rate_limits.primary.used_percent if usage.rate_limits.primary else None)
print(usage.token_usage.summary.lifetime_tokens if usage.token_usage else None)

from codexcw import get_claude_account_usage

claude_usage = get_claude_account_usage()
print(claude_usage.windows)

Running many agent instances

from codexcw import Runner, Request

runner = Runner()
group = runner.run_many(
    [Request(prompt="review package A"), Request(prompt="review package B")],
    max_concurrent=2,
)
for run_event in group.events():
    print(run_event.index, run_event.event.type)
results = group.wait()

Async

import asyncio
from codexcw import Request
from codexcw.aio import Runner

async def main():
    runner = Runner()
    session = await runner.start(Request(prompt="oi"))
    async for event in session.events():
        print(event.type)
    result = await session.wait()
    print(result.final_message)

asyncio.run(main())

License

CC0 1.0 Universal.

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

codexcw-0.4.0.tar.gz (72.6 kB view details)

Uploaded Source

Built Distributions

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

codexcw-0.4.0-cp39-abi3-win_amd64.whl (857.6 kB view details)

Uploaded CPython 3.9+Windows x86-64

codexcw-0.4.0-cp39-abi3-musllinux_1_1_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.1+ x86-64

codexcw-0.4.0-cp39-abi3-musllinux_1_1_aarch64.whl (1.0 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.1+ ARM64

codexcw-0.4.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (872.7 kB view details)

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

codexcw-0.4.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (834.3 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

codexcw-0.4.0-cp39-abi3-macosx_11_0_arm64.whl (792.2 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

codexcw-0.4.0-cp39-abi3-macosx_10_12_x86_64.whl (834.3 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file codexcw-0.4.0.tar.gz.

File metadata

  • Download URL: codexcw-0.4.0.tar.gz
  • Upload date:
  • Size: 72.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for codexcw-0.4.0.tar.gz
Algorithm Hash digest
SHA256 71f6ed592c99f3c6e135f8b1446f8ad34277199f197787acf0835f1a459535bd
MD5 24589c15db072e0b70aafeed42f3f5cc
BLAKE2b-256 d528004bd09d06080fc40d284714c2f71836647643e4df0a376f34cc2b903946

See more details on using hashes here.

Provenance

The following attestation bundles were made for codexcw-0.4.0.tar.gz:

Publisher: release-pypi.yml on c3-oss/codexcw

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codexcw-0.4.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: codexcw-0.4.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 857.6 kB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for codexcw-0.4.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 d2d507a9c3d026b8340c9e92d2b7f5675763ab264a66c030f5b170bfeb2d4ee5
MD5 e99225eb489d2c6ccff457ed0d2af6f5
BLAKE2b-256 41ad7a996f88cbf01ad137964814493605d64c4cdf9158282287bc10d0657ffd

See more details on using hashes here.

Provenance

The following attestation bundles were made for codexcw-0.4.0-cp39-abi3-win_amd64.whl:

Publisher: release-pypi.yml on c3-oss/codexcw

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codexcw-0.4.0-cp39-abi3-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for codexcw-0.4.0-cp39-abi3-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 9c237aa5fe3f4a89bff018546828fc41f61c03a9d543c398f449e7d273cf97f6
MD5 ea0f3750574e36ade161ed9ad2124b8f
BLAKE2b-256 1be3ce8f1d759aa79336de268aa1d8402aca009a459faa30e081566ff089fc5c

See more details on using hashes here.

Provenance

The following attestation bundles were made for codexcw-0.4.0-cp39-abi3-musllinux_1_1_x86_64.whl:

Publisher: release-pypi.yml on c3-oss/codexcw

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codexcw-0.4.0-cp39-abi3-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for codexcw-0.4.0-cp39-abi3-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 58d6d19ec779a15cea000ec9e1d88a009257ea11deaf2fb9d9666e3bc050bd54
MD5 888497c0ceb6227b51b03cd01feed6c3
BLAKE2b-256 70bc75b34c5d96ca154879ca6ccf79e6f3526eb4d7ab66874faeb982900f9258

See more details on using hashes here.

Provenance

The following attestation bundles were made for codexcw-0.4.0-cp39-abi3-musllinux_1_1_aarch64.whl:

Publisher: release-pypi.yml on c3-oss/codexcw

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codexcw-0.4.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for codexcw-0.4.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fc02fe553fbf086969d57de456c32a7c8332527f58f7394e2cab7b29814dbbe7
MD5 d4f230c1cc6a86f1c8743366ca543a31
BLAKE2b-256 04bc8f8545fcba9b77d81e44507058db5a288d156214ade27c9d0431d406e29d

See more details on using hashes here.

Provenance

The following attestation bundles were made for codexcw-0.4.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release-pypi.yml on c3-oss/codexcw

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codexcw-0.4.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for codexcw-0.4.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4b63cfc169825dc456a6cbb7bda8ff95814297be144351fd175e8d0a66707f79
MD5 0cb2f72e6f112d1f4bb8d5f454490481
BLAKE2b-256 881d58230d11ad8bd803ad46b678d681ac70034281024c9b5d722b3e7e2e2630

See more details on using hashes here.

Provenance

The following attestation bundles were made for codexcw-0.4.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release-pypi.yml on c3-oss/codexcw

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codexcw-0.4.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for codexcw-0.4.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 17445c5390227d74c62b8f34cc943ba921094d71bb0d89a300a7f53af30f3b60
MD5 dd17cc6da80f2a0bddf4f59083e78750
BLAKE2b-256 5284e7b7bcc276790e289e9bb8c9e1d0973f338d026bcaae60a6a2d626471dbb

See more details on using hashes here.

Provenance

The following attestation bundles were made for codexcw-0.4.0-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: release-pypi.yml on c3-oss/codexcw

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codexcw-0.4.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for codexcw-0.4.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d8c62abc894d97cabc3f57e8b45ee5939fbb2d3aafb77d8ff97fe52bbdcec89e
MD5 2c16d8b7b7317ac8c527c226e1f3a235
BLAKE2b-256 35d66ae47bdd5077625474a3d1c49ee7f749a23fb42eb2b83f8100564e8f3746

See more details on using hashes here.

Provenance

The following attestation bundles were made for codexcw-0.4.0-cp39-abi3-macosx_10_12_x86_64.whl:

Publisher: release-pypi.yml on c3-oss/codexcw

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