Skip to main content

Python client for claude2Api bridge service

Project description

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 check
  • sessions() -> list — List active sessions
  • abort(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

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

claude2api_client-0.1.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

claude2api_client-0.1.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: claude2api_client-0.1.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for claude2api_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bda7b324cd4d2ac059a7a3e8bb405b186f12254d14a52b0f32f50de440fd687f
MD5 2bc1c5915a715e80688fc9650c537f67
BLAKE2b-256 c6188e4446fecc8436a4d80d3516eb2711504c65210a521c2fbc1302ee8a2d94

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for claude2api_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 76daceab89e589992e2727a2737dd90992f474e74d42f328ec27458db00b00fe
MD5 4c241c2e31057227828eef91339210ae
BLAKE2b-256 797257a566651a1b390fd65fe7ebc79e2f98c6d7dc7c8b2893faa9eb3c25d7b0

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