Skip to main content

Python SDK for the Shard distributed inference network

Project description

Shard Python SDK

Python client for the Shard distributed inference network.

Installation

pip install shard-inference

Or install from source:

cd sdk/python
pip install -e .

Quick Start

from shard import Shard

# Connect to local daemon (default: http://localhost:9091)
client = Shard()

# Non-streaming request
response = client.chat.completions.create(
    model="shard-hybrid",
    messages=[{"role": "user", "content": "Explain quantum computing simply."}]
)
print(response.choices[0].message.content)

# Streaming request
stream = client.chat.completions.create(
    model="shard-hybrid",
    messages=[{"role": "user", "content": "Count to 5"}],
    stream=True
)
for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

client.close()

OpenAI-Compatible Drop-In

The SDK is designed to be a drop-in replacement for the OpenAI client:

# Instead of:
from openai import OpenAI
client = OpenAI(base_url="http://localhost:9091/v1", api_key="...")

# You can use:
from shard import Shard
client = Shard()  # Defaults to http://localhost:9091

All standard OpenAI parameters are supported:

  • messages - Chat messages
  • model - Model identifier
  • temperature - Sampling temperature (0.0-2.0)
  • max_tokens - Maximum tokens to generate
  • top_p - Nucleus sampling parameter
  • stream - Enable streaming responses

Async Usage

import asyncio
from shard import AsyncShard

async def main():
    async with AsyncShard() as client:
        response = await client.chat.completions.create(
            model="shard-hybrid",
            messages=[{"role": "user", "content": "Hello!"}]
        )
        print(response.choices[0].message.content)

asyncio.run(main())

API Key & Authentication

# With API key
client = Shard(api_key="sk-your-key-here")

# Connect to remote server
client = Shard(base_url="https://your-shard-server.com", api_key="sk-...")

Private Mesh Routing

For sensitive requests that should bypass public bootstrap peers:

response = client.chat.completions.create(
    model="shard-hybrid",
    messages=[...],
    sensitive=True  # Routes via X-Shard-Route: private
)

Configuration

client = Shard(
    api_key="sk-...",           # API key (optional)
    base_url="http://localhost:9091",  # Daemon URL
    timeout=30.0,               # Request timeout (seconds)
    max_retries=3,              # Retry attempts on failure
)

Exceptions

The SDK provides typed exceptions:

  • ShardError - Base exception
  • ShardAPIError - API errors (4xx/5xx responses)
  • ShardAuthError - Authentication failures (401)
  • ShardTimeoutError - Request timeouts
  • ShardConnectionError - Connection failures
from shard import Shard, ShardAPIError

try:
    client = Shard()
    response = client.chat.completions.create(messages=[...])
except ShardAPIError as e:
    print(f"API Error: {e.status_code} - {e.response_body}")
except ShardTimeoutError:
    print("Request timed out")

Requirements

  • Python 3.9+
  • httpx >= 0.25.0
  • pydantic >= 2.0

For async support:

  • aiohttp >= 3.9.0

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

shard_inference-0.1.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

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

shard_inference-0.1.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for shard_inference-0.1.0.tar.gz
Algorithm Hash digest
SHA256 58203da9a27baf17882eb65b03b2a08644bcf541e0f11695f3ceaea1dfcd1440
MD5 4db96c79ef3d6164d2097b8880d3757d
BLAKE2b-256 e8308ca1fd465ac49b136c014e94f056c2fb2b9f0862374671bb5a5472e7c8f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for shard_inference-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8e998f78fbc0d34cc209fc5cda39aabd42a1474b7244a0dbd8b5e5d7992f6f4c
MD5 bbba5ad2439017fa132095a31fd344f7
BLAKE2b-256 163bf51e43d8fec21b4e088e80c369e362281a544a9122acdfec75ff6e144262

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