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.3.0.tar.gz (71.0 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.3.0-cp39-abi3-win_amd64.whl (846.3 kB view details)

Uploaded CPython 3.9+Windows x86-64

codexcw-0.3.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.3.0-cp39-abi3-musllinux_1_1_aarch64.whl (998.6 kB view details)

Uploaded CPython 3.9+musllinux: musl 1.1+ ARM64

codexcw-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (863.0 kB view details)

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

codexcw-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (822.5 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

codexcw-0.3.0-cp39-abi3-macosx_11_0_arm64.whl (785.3 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

codexcw-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl (820.3 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for codexcw-0.3.0.tar.gz
Algorithm Hash digest
SHA256 c7e051e6a1bd264d1433084ca74367017b847edbf0f8a0e308dd699521e3baac
MD5 69615526f0655f84a42453281709430d
BLAKE2b-256 ce9d5bbb5b640927aa963b120b9479f000ca1f1eff5eb151d70becf8f5585bbc

See more details on using hashes here.

Provenance

The following attestation bundles were made for codexcw-0.3.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.3.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: codexcw-0.3.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 846.3 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.3.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 27405b7aada71985c3916b0ae45f52f125908f442218cb79e9494525f06860bf
MD5 2874687bec3bfe9a6f3f18063f0a95be
BLAKE2b-256 58f80c85a41d9000a5a2c733d2686a13f467e6c5d00855aeb10bb93ea62cb26c

See more details on using hashes here.

Provenance

The following attestation bundles were made for codexcw-0.3.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.3.0-cp39-abi3-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for codexcw-0.3.0-cp39-abi3-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 08dd8bb69ada7c4431f14f65922265afc55f0339a944d28f8efec70ab6f5f2c7
MD5 a0d008086f394b833930c1d93253bd99
BLAKE2b-256 202a292334e6d31945e648585a739ce9a0c9f0f3f739a872404f9105c23c5c18

See more details on using hashes here.

Provenance

The following attestation bundles were made for codexcw-0.3.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.3.0-cp39-abi3-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for codexcw-0.3.0-cp39-abi3-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 545164f992187cd8cf66811d3e87b2ec5c21b0cfc40fce30af50ae8e03dc1982
MD5 f0f632776863bef11e5a0a997d5ba05c
BLAKE2b-256 c88fd0cfb6cee9c3b62936486f0a2b4944d07f0b2c61458cd77066def0ca25a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for codexcw-0.3.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.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for codexcw-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5599a17b6afd928303aaf756c34e2199b7ebbbd93aa9938cec671bf4c5cbf167
MD5 97c4cec2790612613753017d3d3ac0a3
BLAKE2b-256 a47bdb2593f9aca46364b6bc5f7cca2519585286ffecfa35a89b83d00a0c5057

See more details on using hashes here.

Provenance

The following attestation bundles were made for codexcw-0.3.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.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for codexcw-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9c4339d92c4733c65389ea6b9ae1b53b86d4cd329ef36cf18ac47379ac88f6ca
MD5 8000405b36b523af428c9babdf4e183d
BLAKE2b-256 d07d61f56c65e2234699bb9089cbd93cf00acb8a24f3e17bf139bf2c2a147921

See more details on using hashes here.

Provenance

The following attestation bundles were made for codexcw-0.3.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.3.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for codexcw-0.3.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 837f4148f3ace3074aa21431210dfbc9a64ebdfc3e15b7aa345bb031873f8ac8
MD5 e4caefdce316c35136d3a5dd47c4abb2
BLAKE2b-256 51e368246b5d775335e99fc17c5eafa54ab8f5a4ae950ff961b8d8c3577e7a89

See more details on using hashes here.

Provenance

The following attestation bundles were made for codexcw-0.3.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.3.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for codexcw-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 91c82277ee397e347e3cbfb8e760dd7a166bd9600dfd691c1845d132fea341dc
MD5 b387c9ede257b4188c99e1ed871251a7
BLAKE2b-256 597d760627f010a2266f6530a401e98b254b27cc72d712d3a123d3e584288c32

See more details on using hashes here.

Provenance

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