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.1.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.1-cp39-abi3-win_amd64.whl (853.8 kB view details)

Uploaded CPython 3.9+Windows x86-64

codexcw-0.4.1-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.1-cp39-abi3-musllinux_1_1_aarch64.whl (1.0 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.1+ ARM64

codexcw-0.4.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (873.3 kB view details)

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

codexcw-0.4.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (834.8 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

codexcw-0.4.1-cp39-abi3-macosx_11_0_arm64.whl (790.8 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

codexcw-0.4.1-cp39-abi3-macosx_10_12_x86_64.whl (834.0 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: codexcw-0.4.1.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.1.tar.gz
Algorithm Hash digest
SHA256 9b7e315d0b0df1255fcb8ee4c8df3fa81e1632d578426f407948656d46b45086
MD5 d8c8c960f8ac13a3e726d740e0e62616
BLAKE2b-256 275da69b9e018076c5f0bf3540697780a73ef61c25d531c399ec7762c83821a0

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: codexcw-0.4.1-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 853.8 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.1-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 6be466259e467a3c2a238af6e63dc29e4ef3bddba6c523b13b312412338fed08
MD5 6adbeaa0555006e8e5d9f3028609862f
BLAKE2b-256 2f01a55e87b7d92ab9c0054c86aa21e08789a47ba732b2d56287fe7ff109f141

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codexcw-0.4.1-cp39-abi3-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 467babc84027bda7b1843c3b518d807975a59b73ea5b37d3490e93b708d53667
MD5 f6dedfbe9f52bb9b7268d722019c9030
BLAKE2b-256 d3ed85d666cc9824f0a193891544d20274b6c355beade09b8d5e1d22abf6ec17

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codexcw-0.4.1-cp39-abi3-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 3b5ddcf1574986b02d00dc6371d32ed58da2bc9c62867816d00966e4ea68019d
MD5 e78b429a6262f9ce7395f59fa2391974
BLAKE2b-256 366d1107d1af13da24997a6208475806d933318becc17fb0841f702e0f63701e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codexcw-0.4.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 82dc00427498174ff20292ea9b040b9dce06e57e57d844b98382d71923dc69ae
MD5 447ba9818381fd72c9c183c178b99846
BLAKE2b-256 8c8dc20f99c9b17807ac3d5bb3fe299047c04cdb60e02c9aeade38a9e81af55f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codexcw-0.4.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 fe70c62aeb80d4b4fade56cf019b183b851f36f742b85e2556a5946e9bc1dea5
MD5 9ec3b6904719563dfe71ae3e60f62c64
BLAKE2b-256 e0ea2fcfe8cba64777ccd74c191ad9a783db3e44b2005b16813435983c1198e3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codexcw-0.4.1-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a9285acf9e28d1692112a3c50e0eee44e2b8f521478f79cb30a0503a01d5ecde
MD5 5ee8c1e45016b93e1827ce83d9b90ff8
BLAKE2b-256 6b9cbc3914f90e90b95fe1aee3be800712f6a082d4650dd771c743bb540af88d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for codexcw-0.4.1-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 535da1b61edbf6e3aa5915b596204f1db13da303cdf5d6452cdb2416a669be4e
MD5 68c4942e71e2fcd78d59adabd4a3bff5
BLAKE2b-256 f82b6128596ca8f75f07f8ff8bb5d696be5c690e5829b2b59ca283e5f31d7bfc

See more details on using hashes here.

Provenance

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