claude2api-client
Python client for the 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 for setup instructions.
Installation
pip install claude2api-client
Quick Start
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
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 checksessions() -> list— List active sessionsabort(session_id) -> dict— Abort a running session
Publishing to PyPI
# 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:
[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
Metadata
Release files for claude2api-client 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| claude2api_client-0.2.0.tar.gz | 5.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| claude2api_client-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.8 kB
Release files / claude2api_client-0.2.0.tar.gz
| Download URL | claude2api_client-0.2.0.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5d424415ad31d76a2f3470a3b27a09664c054c4e644df09374fadebfe0d0964b
|
|
BLAKE2b-256 checksum How to use checksums |
593f84a012a8ec3737d7011abd55e19ce3f0ed6b06f4dba25e094dee6e547435
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Release files / claude2api_client-0.2.0-py3-none-any.whl
| Download URL | claude2api_client-0.2.0-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
590839212c90b107b7559436999f5ef4f8b49c12aa99146cbb109801e30bae29
|
|
BLAKE2b-256 checksum How to use checksums |
35cd082722636911905498672e74af84ccdf49d7316a61801dbf45436f1de2b4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|