Skip to main content

A minimal Python library scaffold for codex-python

Project description

codex-python

A minimal Python library scaffold using uv with Python 3.13+.

Quickstart

  • Requires Python 3.13+.
  • Package import name: codex.
  • Distribution name (PyPI): codex-python.

Repo

Usage

Basic non-interactive execution via Codex CLI:

from codex import run_exec

out = run_exec("explain this repo")
print(out)

Options:

  • Choose model: run_exec("...", model="gpt-4.1")
  • Full auto: run_exec("scaffold a cli", full_auto=True)
  • Run in another dir: run_exec("...", cd="/path/to/project")

Streaming JSON events (no PyO3 required):

from codex.protocol.runtime import stream_exec_events

for event in stream_exec_events("explain this repo", full_auto=True):
    # event is a dict with shape {"id": str, "msg": {...}}
    print(event)

The event payload matches the Pydantic models in codex.protocol.types (e.g., EventMsg).

Using a client with defaults:

from codex import CodexClient

client = CodexClient(model="gpt-4.1", full_auto=True)
print(client.run("explain this repo"))

Install uv

  • macOS (Homebrew): brew install uv
  • Or via install script:
    • Unix/macOS: curl -LsSf https://astral.sh/uv/install.sh | sh
    • Windows (PowerShell): iwr https://astral.sh/uv/install.ps1 -UseBasicParsing | iex

See: https://docs.astral.sh/uv/

Create a virtual env (optional)

uv python install 3.13
uv venv --python 3.13
. .venv/bin/activate  # or .venv\Scripts\activate on Windows

Build

uv build

Artifacts appear in dist/ (.whl and .tar.gz).

Publish to PyPI

  • Manual:
export PYPI_API_TOKEN="pypi-XXXX"  # create at https://pypi.org/manage/account/token/
uv publish --token "$PYPI_API_TOKEN"
  • GitHub Actions (Trusted Publishing): enable PyPI Trusted Publishing for gersmann/codex-python and push a tag like v0.1.0. No token is needed. The workflow at .github/workflows/publish.yml requests an OIDC token and runs uv publish --trusted-publishing=always on v* tags.

Dev tooling

  • Lint: make lint (ruff + mypy)
  • Tests: make test (pytest)
  • Format: make fmt (ruff formatter)
  • Pre-commit: uvx pre-commit install && uvx pre-commit run --all-files

Protocol bindings (from codex-rs)

  • Prereq: Rust toolchain (cargo) installed.
  • Generate Python types from the upstream protocol with:
make gen-protocol

This will:

  • run codex-proj/codex-rs/protocol-ts to emit TypeScript types under .generated/ts/
  • convert them to Python TypedDict/Literal aliases at codex/protocol/types.py

Project Layout

.
├── codex/              # package root (import name: codex)
│   └── __init__.py     # version lives here
├── pyproject.toml      # PEP 621 metadata, hatchling build backend
├── README.md
└── .gitignore

Versioning

Version is managed via codex/__init__.py and exposed as __version__. The build uses Hatch’s version source.

Python Compatibility

  • Requires Python >=3.13.

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_python-0.1.2.tar.gz (29.6 kB view details)

Uploaded Source

Built Distribution

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

codex_python-0.1.2-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file codex_python-0.1.2.tar.gz.

File metadata

  • Download URL: codex_python-0.1.2.tar.gz
  • Upload date:
  • Size: 29.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.16

File hashes

Hashes for codex_python-0.1.2.tar.gz
Algorithm Hash digest
SHA256 fee860e4e8751d2bfc4c8360d40bfbae71c2a27b64548b8f683a3af6c83c9b1d
MD5 de7bc8065486e50aa4691fbd6b7f82c2
BLAKE2b-256 333010b05bb2ece7e842e61602e88fcb2c7312a8eb69f05bcdfc8677df4f1a7a

See more details on using hashes here.

File details

Details for the file codex_python-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for codex_python-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f56729c985b0cd523b2ea6883071d84c2128bab449d1de28a415e3c0b4e087b7
MD5 8391ed7e7ff2fea8c94bb29460889dcf
BLAKE2b-256 339d2387e78a608784e9a9b31157d6830b590734235988e81c646141dbfab6f8

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