Skip to main content

Claude Code SDK-style wrapper around the Codex CLI for programmatic automation.

Project description

Codex Client

Lightweight Python wrapper for the Codex CLI. Stream chats, handle reasoning/tool events, and build custom MCP tools.

Installation

pip install codex-client

Requires codex executable on your PATH.

Authentication (CLI)

# Login via browser
codex-client login

# Export credentials (copy to another machine)
codex-client read

# Import credentials
codex-client set "<payload>"

# Clear credentials
codex-client logout

Basic Usage

import asyncio
from codex_client import (
    AssistantMessageStream,
    Client,
    CodexChatConfig,
    CodexProfile,
    ReasoningEffort,
    SandboxMode,
)

async def main():
    config = CodexChatConfig(
        profile=CodexProfile(
            model="gpt-5",
            reasoning_effort=ReasoningEffort.MINIMAL,
            sandbox=SandboxMode.WORKSPACE_WRITE,
        )
    )

    async with Client() as client:
        chat = await client.create_chat("Write a Python fibonacci function", config=config)

        # Stream responses
        async for event in chat:
            if isinstance(event, AssistantMessageStream):
                async for chunk in event.stream():
                    print(chunk, end="", flush=True)

        # Get final response
        final = await chat.get()
        print(f"\n\nFinal: {final}")

        # Continue conversation
        await chat.resume("Now make it recursive")

asyncio.run(main())

Custom Tools

from codex_client import BaseTool, tool

class CalculatorTool(BaseTool):
    @tool()
    async def add(self, a: float, b: float) -> dict:
        """Add two numbers."""
        return {"result": a + b}

    @tool()
    async def multiply(self, a: float, b: float) -> dict:
        """Multiply two numbers."""
        return {"result": a * b}

# Use the tool
async def main():
    with CalculatorTool() as calc:
        config = CodexChatConfig(
            profile=CodexProfile(model="gpt-5"),
            mcp_servers=[calc.config()]
        )

        async with Client() as client:
            chat = await client.create_chat("What is 15 + 27?", config=config)
            async for event in chat:
                if isinstance(event, AssistantMessageStream):
                    async for chunk in event.stream():
                        print(chunk, end="", flush=True)

asyncio.run(main())

Authentication (Code)

from codex_client.auth import CodexAuth

auth = CodexAuth()

# Trigger login flow (opens browser)
session = auth.login()
print(f"Visit: {session.url}")
success = session.wait()  # Blocks until user completes login

# Or import existing credentials
auth.set("<payload-from-codex-client-read>")

# Verify credentials
token = auth.read()

Examples

See src/examples/ for complete demos:

  • Interactive Chat - Multi-turn conversations with streaming
  • MCP Transport - HTTP and stdio MCP server connectivity
  • Weather Assistant - Custom tool with state management
cd src/examples
uv sync
uv run weather/main.py

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_client-0.1.0.tar.gz (38.2 kB view details)

Uploaded Source

Built Distribution

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

codex_client-0.1.0-py3-none-any.whl (47.2 kB view details)

Uploaded Python 3

File details

Details for the file codex_client-0.1.0.tar.gz.

File metadata

  • Download URL: codex_client-0.1.0.tar.gz
  • Upload date:
  • Size: 38.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for codex_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e510f54725db9f0f0e74e13d5a8bcb5fadc50ba815cc11376fd18322ce8713ee
MD5 e261e0d8093f6427dfbb49e682699350
BLAKE2b-256 f5becd9f9e26d1b541e5c335e19e93abf83952a687bc5c78b15219ce90993834

See more details on using hashes here.

File details

Details for the file codex_client-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: codex_client-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 47.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for codex_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 30da90ac93ae96a5ea6f64f033b8c58f4a8a3ab471c341d0ea062a7b873abbcd
MD5 21e36e55a96a7e997389bb2ad1d17cb1
BLAKE2b-256 985bef5c1fb64eb0388ff3554749dd4a6ce437e675e56c32af8356c6541144cb

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