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.2.0.tar.gz (5.2 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.2.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: claude2api_client-0.2.0.tar.gz
  • Upload date:
  • Size: 5.2 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.2.0.tar.gz
Algorithm Hash digest
SHA256 5d424415ad31d76a2f3470a3b27a09664c054c4e644df09374fadebfe0d0964b
MD5 3ccc74c3cbb3a482c2b554365c9d2f28
BLAKE2b-256 593f84a012a8ec3737d7011abd55e19ce3f0ed6b06f4dba25e094dee6e547435

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for claude2api_client-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 590839212c90b107b7559436999f5ef4f8b49c12aa99146cbb109801e30bae29
MD5 c5e8a0021e9157c4fc7cf0551b199770
BLAKE2b-256 35cd082722636911905498672e74af84ccdf49d7316a61801dbf45436f1de2b4

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