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.5.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.5.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: shard_inference-0.5.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.5.0.tar.gz
Algorithm Hash digest
SHA256 b340c61603493043a3789d2fcc9cd34fa61cbe58c2453559542fa83da54b5365
MD5 4db43dd1e27be23d88407a9596e412f6
BLAKE2b-256 c1b9023fd797f3bd01ad8f59d4f0569c8134f5cc101c53842db647c5d425a571

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for shard_inference-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d36cc6096b18decdb228b2925cc88955bce242ef24756daf7a390047886da7ca
MD5 0b6df16f6f28583d7d1d8a44ff75abf9
BLAKE2b-256 758cbea47dc6fe9944eb5f22dacfab5a830e5150f4ca201335ef9379f31505cc

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