codex-client


Namecodex-client JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryClaude Code SDK-style wrapper around the Codex CLI for programmatic automation.
upload_time2025-10-12 01:09:43
maintainerCodex Assistant
docs_urlNone
authorCodex Assistant
requires_python>=3.11
licenseMIT
keywords codex openai mcp sdk automation cli
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Codex Client

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

## Installation

```bash
pip install codex-client
```

Requires `codex` executable on your PATH.

## Authentication (CLI)

```bash
# 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

```python
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

```python
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)

```python
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

```bash
cd src/examples
uv sync
uv run weather/main.py
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "codex-client",
    "maintainer": "Codex Assistant",
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": "Cheowan Park <cheolwan.park552@gmail.com>",
    "keywords": "codex, openai, mcp, sdk, automation, cli",
    "author": "Codex Assistant",
    "author_email": "Cheowan Park <cheolwan.park552@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/f5/be/cd9f9e26d1b541e5c335e19e93abf83952a687bc5c78b15219ce90993834/codex_client-0.1.0.tar.gz",
    "platform": null,
    "description": "# Codex Client\n\nLightweight Python wrapper for the Codex CLI. Stream chats, handle reasoning/tool events, and build custom MCP tools.\n\n## Installation\n\n```bash\npip install codex-client\n```\n\nRequires `codex` executable on your PATH.\n\n## Authentication (CLI)\n\n```bash\n# Login via browser\ncodex-client login\n\n# Export credentials (copy to another machine)\ncodex-client read\n\n# Import credentials\ncodex-client set \"<payload>\"\n\n# Clear credentials\ncodex-client logout\n```\n\n## Basic Usage\n\n```python\nimport asyncio\nfrom codex_client import (\n    AssistantMessageStream,\n    Client,\n    CodexChatConfig,\n    CodexProfile,\n    ReasoningEffort,\n    SandboxMode,\n)\n\nasync def main():\n    config = CodexChatConfig(\n        profile=CodexProfile(\n            model=\"gpt-5\",\n            reasoning_effort=ReasoningEffort.MINIMAL,\n            sandbox=SandboxMode.WORKSPACE_WRITE,\n        )\n    )\n\n    async with Client() as client:\n        chat = await client.create_chat(\"Write a Python fibonacci function\", config=config)\n\n        # Stream responses\n        async for event in chat:\n            if isinstance(event, AssistantMessageStream):\n                async for chunk in event.stream():\n                    print(chunk, end=\"\", flush=True)\n\n        # Get final response\n        final = await chat.get()\n        print(f\"\\n\\nFinal: {final}\")\n\n        # Continue conversation\n        await chat.resume(\"Now make it recursive\")\n\nasyncio.run(main())\n```\n\n## Custom Tools\n\n```python\nfrom codex_client import BaseTool, tool\n\nclass CalculatorTool(BaseTool):\n    @tool()\n    async def add(self, a: float, b: float) -> dict:\n        \"\"\"Add two numbers.\"\"\"\n        return {\"result\": a + b}\n\n    @tool()\n    async def multiply(self, a: float, b: float) -> dict:\n        \"\"\"Multiply two numbers.\"\"\"\n        return {\"result\": a * b}\n\n# Use the tool\nasync def main():\n    with CalculatorTool() as calc:\n        config = CodexChatConfig(\n            profile=CodexProfile(model=\"gpt-5\"),\n            mcp_servers=[calc.config()]\n        )\n\n        async with Client() as client:\n            chat = await client.create_chat(\"What is 15 + 27?\", config=config)\n            async for event in chat:\n                if isinstance(event, AssistantMessageStream):\n                    async for chunk in event.stream():\n                        print(chunk, end=\"\", flush=True)\n\nasyncio.run(main())\n```\n\n## Authentication (Code)\n\n```python\nfrom codex_client.auth import CodexAuth\n\nauth = CodexAuth()\n\n# Trigger login flow (opens browser)\nsession = auth.login()\nprint(f\"Visit: {session.url}\")\nsuccess = session.wait()  # Blocks until user completes login\n\n# Or import existing credentials\nauth.set(\"<payload-from-codex-client-read>\")\n\n# Verify credentials\ntoken = auth.read()\n```\n\n## Examples\n\nSee `src/examples/` for complete demos:\n\n- **Interactive Chat** - Multi-turn conversations with streaming\n- **MCP Transport** - HTTP and stdio MCP server connectivity\n- **Weather Assistant** - Custom tool with state management\n\n```bash\ncd src/examples\nuv sync\nuv run weather/main.py\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Claude Code SDK-style wrapper around the Codex CLI for programmatic automation.",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://github.com/cheolwanpark/codex-client",
        "Issues": "https://github.com/cheolwanpark/codex-client/issues",
        "Repository": "https://github.com/cheolwanpark/codex-client"
    },
    "split_keywords": [
        "codex",
        " openai",
        " mcp",
        " sdk",
        " automation",
        " cli"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "985bef5c1fb64eb0388ff3554749dd4a6ce437e675e56c32af8356c6541144cb",
                "md5": "21e36e55a96a7e997389bb2ad1d17cb1",
                "sha256": "30da90ac93ae96a5ea6f64f033b8c58f4a8a3ab471c341d0ea062a7b873abbcd"
            },
            "downloads": -1,
            "filename": "codex_client-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "21e36e55a96a7e997389bb2ad1d17cb1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 47199,
            "upload_time": "2025-10-12T01:09:42",
            "upload_time_iso_8601": "2025-10-12T01:09:42.169384Z",
            "url": "https://files.pythonhosted.org/packages/98/5b/ef5c1fb64eb0388ff3554749dd4a6ce437e675e56c32af8356c6541144cb/codex_client-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "f5becd9f9e26d1b541e5c335e19e93abf83952a687bc5c78b15219ce90993834",
                "md5": "e261e0d8093f6427dfbb49e682699350",
                "sha256": "e510f54725db9f0f0e74e13d5a8bcb5fadc50ba815cc11376fd18322ce8713ee"
            },
            "downloads": -1,
            "filename": "codex_client-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "e261e0d8093f6427dfbb49e682699350",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 38172,
            "upload_time": "2025-10-12T01:09:43",
            "upload_time_iso_8601": "2025-10-12T01:09:43.492124Z",
            "url": "https://files.pythonhosted.org/packages/f5/be/cd9f9e26d1b541e5c335e19e93abf83952a687bc5c78b15219ce90993834/codex_client-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-12 01:09:43",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "cheolwanpark",
    "github_project": "codex-client",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "codex-client"
}
        
Elapsed time: 2.57549s