Skip to main content

Minimal Python API for running the Codex CLI.

Project description

CodexAPI

Use codex from python as easily as calling a function with your codex credits instead of the API.

Requirements

  • Codex CLI installed and authenticated (codex must be on your PATH).
  • Python 3.8+.

Install

pip install codexapi

Quickstart

from codexapi import agent, Agent

# Run one-shot tasks as a function call
print(agent("Say hello"))

# Run a multi-turn conversation as a session
session = Agent(cwd="/path/to/project")
print(session("Summarize this repo."))
print(session("Now list any risks."))

# Save and resume a session later
thread_id = session.thread_id
session2 = Agent(cwd="/path/to/project", trace_id=thread_id)
print(session2("Continue from where we left off."))

API

agent(prompt, cwd=None, *, yolo=False, agent="codex", flags=None) -> str

Runs a single Codex turn and returns only the agent's message. Any reasoning items are filtered out.

  • prompt (str): prompt to send to Codex.
  • cwd (str | PathLike | None): working directory for the Codex session.
  • yolo (bool): pass --yolo to Codex when true.
  • agent (str): agent backend to use (only "codex" is supported).
  • flags (str | None): extra CLI flags to pass to Codex.

Agent(cwd=None, *, yolo=False, agent="codex", trace_id=None, flags=None)

Creates a stateful session wrapper. Calling the instance sends the prompt into the same conversation and returns only the agent's message.

  • __call__(prompt) -> str: send a prompt to Codex and return the message.
  • thread_id -> str | None: expose the underlying session id once created.
  • trace_id (str | None): Codex thread id to resume from the first call.
  • yolo (bool): pass --yolo to Codex when true.
  • agent (str): agent backend to use (only "codex" is supported).
  • flags (str | None): extra CLI flags to pass to Codex.

Behavior notes

  • Uses codex exec --json and parses JSONL events for agent_message items.
  • Automatically passes --skip-git-repo-check so it can run outside a git repo.
  • Passes --yolo when enabled (use with care).
  • Raises RuntimeError if Codex exits non-zero or returns no agent message.

Configuration

Set CODEX_BIN to point at a non-default Codex binary:

export CODEX_BIN=/path/to/codex

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

codexapi-0.1.2.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

codexapi-0.1.2-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: codexapi-0.1.2.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for codexapi-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f01dc340e6b36be09dc4345f69147a8104a56e16b73c7296191dd32de0bfe26f
MD5 37b64b07beab0bde53eb134aea0eb8b0
BLAKE2b-256 8830f82df64c9fb12bea6dc312e807b05758efbd260899b96dd1186979c68427

See more details on using hashes here.

Provenance

The following attestation bundles were made for codexapi-0.1.2.tar.gz:

Publisher: publish.yml on yieldthought/codexapi

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

File details

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

File metadata

  • Download URL: codexapi-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for codexapi-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f649ec32604c5fe6d17bb741b8b8b2ba0c10a396862c7ed7e8d1b3b8deb2a582
MD5 0aac4f7f6fc1a38dd41b935cdd8b3f74
BLAKE2b-256 8132fd5e1cd0ec855cb366b3a81e8f67e7f90fb34e2e2f67e69b4539f3a95a47

See more details on using hashes here.

Provenance

The following attestation bundles were made for codexapi-0.1.2-py3-none-any.whl:

Publisher: publish.yml on yieldthought/codexapi

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