Metadata-Version: 2.4
Name: claude2api-client
Version: 0.1.0
Summary: Python client for claude2Api bridge service
Author: claude2api contributors
License-Expression: MIT
Project-URL: Homepage, https://github.com/anthropics/claude2api
Project-URL: Repository, https://github.com/anthropics/claude2api
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.28.0
Requires-Dist: sseclient-py>=1.8.0
Dynamic: license-file

# claude2api-client

Python client for the [claude2Api](https://github.com/anthropics/claude2api) bridge service — call Claude Code's full capabilities (file I/O, Bash, multi-turn conversations) over HTTP from any Python project.

## Prerequisites

A running **claude2Api** Node.js bridge service. See the [main repo](https://github.com/anthropics/claude2api) for setup instructions.

## Installation

```bash
pip install claude2api-client
```

## Quick Start

```python
from claude2api_client import Claude2Api

api = Claude2Api("http://localhost:3456")

# Single turn
r = api.chat("Explain Python GIL in one sentence")
print(r.result)

# Multi-turn conversation
r2 = api.chat("How about JavaScript?", session_id=r.session_id)
print(r2.result)
```

## Streaming

```python
def on_stream(data):
    if isinstance(data.get("content"), list):
        for block in data["content"]:
            if isinstance(block, dict) and block.get("type") == "text":
                print(block["text"], end="", flush=True)

r = api.chat("Write a haiku", on_stream=on_stream)
```

## API Reference

### `Claude2Api(base_url, timeout)`

| Param | Default | Description |
|-------|---------|-------------|
| `base_url` | `http://localhost:3456` | Bridge service URL |
| `timeout` | `300` | Request timeout in seconds |

### `chat(prompt, **kwargs) -> ChatResult`

| Param | Type | Description |
|-------|------|-------------|
| `prompt` | `str` | Message to send (required) |
| `session_id` | `str` | Resume an existing session |
| `cwd` | `str` | Working directory for file operations |
| `model` | `str` | Model ID, e.g. `"claude-sonnet-4-6"` |
| `allowed_tools` | `list` | e.g. `["Read", "Edit", "Bash"]` |
| `max_turns` | `int` | Max agent turns |
| `system_prompt` | `str` | Custom system prompt |
| `on_stream` | `callable` | Callback for intermediate SSE events |

### `ChatResult`

| Field | Type | Description |
|-------|------|-------------|
| `session_id` | `str \| None` | Session identifier |
| `result` | `str \| None` | Final response text |
| `cost` | `float \| None` | Token cost |
| `duration` | `float \| None` | Execution time |
| `is_error` | `bool` | Whether an error occurred |
| `error` | `str \| None` | Error message |

### Utility methods

- `health() -> dict` — Health check
- `sessions() -> list` — List active sessions
- `abort(session_id) -> dict` — Abort a running session

## Publishing to PyPI

```bash
# Build
cd python
python -m build

# Upload to PyPI
twine upload dist/*
# username: __token__
# password: your PyPI API token (https://pypi.org/manage/account/token/)

# Or test on TestPyPI first
twine upload --repository testpypi dist/*
pip install --index-url https://test.pypi.org/simple/ claude2api
```

To skip entering credentials every time, create `~/.pypirc`:

```ini
[distutils]
index-servers =
    pypi
    testpypi

[pypi]
username = __token__
password = pypi-xxxxxxxxxxxxxxxx

[testpypi]
repository = https://test.pypi.org/legacy/
username = __token__
password = pypi-xxxxxxxxxxxxxxxx
```

To release a new version, update `version` in both `pyproject.toml` and `claude2api_client/__init__.py`, then rebuild and upload.

## License

MIT
