Python SDK for Koine gateway
Project description
koine-sdk
Python SDK for Koine — the HTTP gateway for Claude Code CLI.
Running the Gateway
docker run -d -p 3100:3100 \
-e CLAUDE_CODE_GATEWAY_API_KEY=your-key \
-e CLAUDE_CODE_OAUTH_TOKEN=your-token \
ghcr.io/pattern-zones-co/koine:latest
See Docker Deployment for version pinning and production setup.
Installation
uv pip install koine-sdk
# or: pip install koine-sdk
Quick Start
import asyncio
from koine_sdk import KoineConfig, create_koine
config = KoineConfig(
base_url="http://localhost:3100",
auth_key="your-api-key",
timeout=300.0,
)
async def main():
koine = create_koine(config)
result = await koine.generate_text(prompt="Hello, how are you?")
print(result.text)
asyncio.run(main())
Features
- Text Generation —
koine.generate_text()for simple prompts - Streaming —
koine.stream_text()with async iterators - Structured Output —
koine.generate_object()with Pydantic schema validation - Type Safety — Full type hints for all requests and responses
- Error Handling —
KoineErrorclass with error codes
API
Client Factory
koine = create_koine(config)
Creates a client instance with the given configuration. The config is validated once at creation time.
Methods
| Method | Description |
|---|---|
koine.generate_text(*, prompt, system?, session_id?) |
Generate text from a prompt |
koine.stream_text(*, prompt, system?, session_id?) |
Stream text via Server-Sent Events |
koine.generate_object(*, prompt, schema, system?, session_id?) |
Extract structured data using a Pydantic model |
Types
| Type | Description |
|---|---|
KoineConfig |
Client configuration (base_url, auth_key, timeout, model) |
KoineClient |
Client interface returned by create_koine() |
GenerateTextResult |
Text generation response with usage stats |
GenerateObjectResult[T] |
Object extraction response (generic over schema) |
StreamTextResult |
Streaming result with async iterators and futures |
KoineUsage |
Token usage information |
KoineError |
Error class with code and raw_text |
Documentation
See the SDK Guide for:
- Configuration options
- Streaming examples
- Structured output with Pydantic
- Error handling
- Multi-turn conversations
Examples
Runnable examples are available in the examples/ directory. Run from the SDK directory:
cd packages/sdks/python
uv pip install -e ".[dev]"
uv run python examples/hello.py # Basic text generation
uv run python examples/extract_recipe.py # Structured output with Pydantic
uv run python examples/stream.py # Real-time streaming
uv run python examples/conversation.py # Multi-turn sessions
License
Dual-licensed under AGPL-3.0 or commercial license.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file koine_sdk-2.0.3.tar.gz.
File metadata
- Download URL: koine_sdk-2.0.3.tar.gz
- Upload date:
- Size: 41.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69e1854243dbdcfafffeafe3e73ca4f23591bde4aef964544f29c606e1fe9ea8
|
|
| MD5 |
0e3593f98ca7258a46f4846da0dff6c8
|
|
| BLAKE2b-256 |
343641cf80cda9d1b68000e8782bcf0d9a0ae2b0dee5665732be38083d3d3e8c
|
Provenance
The following attestation bundles were made for koine_sdk-2.0.3.tar.gz:
Publisher:
release.yml on pattern-zones-co/koine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
koine_sdk-2.0.3.tar.gz -
Subject digest:
69e1854243dbdcfafffeafe3e73ca4f23591bde4aef964544f29c606e1fe9ea8 - Sigstore transparency entry: 779724682
- Sigstore integration time:
-
Permalink:
pattern-zones-co/koine@424d45185a9cbf56b06732a0542f205ba2d1492d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pattern-zones-co
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@424d45185a9cbf56b06732a0542f205ba2d1492d -
Trigger Event:
push
-
Statement type:
File details
Details for the file koine_sdk-2.0.3-py3-none-any.whl.
File metadata
- Download URL: koine_sdk-2.0.3-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
24633c7909c923c5a74b05332fb9fea8828d91c76292c2f18a5e37cdd45ec74b
|
|
| MD5 |
ba853b09db2d2d1d703dc2c69a143653
|
|
| BLAKE2b-256 |
0895dc7c4b010a2a4e4183e664f08bc5fdc38f423dfe11a7d1471475ccc18151
|
Provenance
The following attestation bundles were made for koine_sdk-2.0.3-py3-none-any.whl:
Publisher:
release.yml on pattern-zones-co/koine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
koine_sdk-2.0.3-py3-none-any.whl -
Subject digest:
24633c7909c923c5a74b05332fb9fea8828d91c76292c2f18a5e37cdd45ec74b - Sigstore transparency entry: 779724683
- Sigstore integration time:
-
Permalink:
pattern-zones-co/koine@424d45185a9cbf56b06732a0542f205ba2d1492d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pattern-zones-co
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@424d45185a9cbf56b06732a0542f205ba2d1492d -
Trigger Event:
push
-
Statement type: