Skip to main content

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

pip install koine-sdk

Quick Start

import asyncio
from koine_sdk import KoineConfig, generate_text

config = KoineConfig(
    base_url="http://localhost:3100",
    auth_key="your-api-key",
    timeout=300.0,
)

async def main():
    result = await generate_text(config, prompt="Hello, how are you?")
    print(result.text)

asyncio.run(main())

Features

  • Text Generationgenerate_text() for simple prompts
  • Streamingstream_text() with async iterators
  • Structured Outputgenerate_object() with Pydantic schema validation
  • Type Safety — Full type hints for all requests and responses
  • Error HandlingKoineError class with error codes

API

Functions

Function Description
generate_text(config, *, prompt, system?, session_id?) Generate text from a prompt
stream_text(config, *, prompt, system?, session_id?) Stream text via Server-Sent Events
generate_object(config, *, prompt, schema, system?, session_id?) Extract structured data using a Pydantic model

Types

Type Description
KoineConfig Client configuration (base_url, auth_key, timeout, model)
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

koine_sdk-2.0.0.tar.gz (41.0 kB view details)

Uploaded Source

Built Distribution

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

koine_sdk-2.0.0-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file koine_sdk-2.0.0.tar.gz.

File metadata

  • Download URL: koine_sdk-2.0.0.tar.gz
  • Upload date:
  • Size: 41.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for koine_sdk-2.0.0.tar.gz
Algorithm Hash digest
SHA256 712422a7d8b13cb3585f09dd036895bddd85d792a8477c612cca1f20e76aab71
MD5 946b4327810863ae920f0aa7f0b9bf01
BLAKE2b-256 c4a6c3470fafb92d5f413ac10927f2897e5c4d1d1c656fc15957adb5a080e83c

See more details on using hashes here.

Provenance

The following attestation bundles were made for koine_sdk-2.0.0.tar.gz:

Publisher: release.yml on pattern-zones-co/koine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file koine_sdk-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: koine_sdk-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for koine_sdk-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 28e73c698fc4cc115d9bbe2cee45f823c0e4297f0dcf8fc80778029aaada73d9
MD5 213e6ece31f090e73d71080e431c0782
BLAKE2b-256 5c957ff6d57eb6ee5b0bc4c5a8f941d5ff3482125a11fc2b6d68fae809c8ab31

See more details on using hashes here.

Provenance

The following attestation bundles were made for koine_sdk-2.0.0-py3-none-any.whl:

Publisher: release.yml on pattern-zones-co/koine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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