Python API wrapper for the Daisi SDK
Project description
Daisi SDK - Python gRPC Wrapper
A modern Python wrapper for the Daisi SDK, providing a clean and Pythonic interface to interact with the Daisi distributed AI network via gRPC.
Features
- gRPC-based: Full gRPC implementation matching the .NET SDK
- Type-safe: Full type hints for IDE autocomplete and type checking
- Streaming support: Native support for streaming inference responses
- Session management: Complete session lifecycle management
- Comprehensive: All Daisi services (Auth, Sessions, Inference, Models, Hosts, Peers, Settings, Commands)
- Production-ready: Follows PEP standards and best practices
Installation
pip install daisi-sdk
Development Installation
git clone https://github.com/daisinet/daisi-sdk-python.git
cd daisi-sdk-python
pip install -e ".[dev]"
Quick Start
from daisi import DaisiClient
# Initialize client with API key
client = DaisiClient(client_key="your-client-key")
# Create a session
session_id, host = client.session.create(model_name="llama-3")
# Create an inference
inference_id = client.inference.create(
session_id=session_id,
initialization_prompt="You are a helpful assistant."
)
# Send inference request with streaming response
for response in client.inference.send("Hello, how are you?"):
if response.Type == InferenceResponseTypes.InferenceText:
print(response.Content, end="", flush=True)
# Get statistics
stats = client.inference.stats()
print(f"\nTokens used: {stats.SessionTokenCount}")
# Clean up
client.inference.close_inference()
client.session.close()
client.close()
Configuration
Set your configuration via environment variables:
export DAISI_CLIENT_KEY="your-client-key"
export DAISI_ORC_ADDRESS="orc.daisi.net"
export DAISI_ORC_PORT="443"
Or configure in code:
from daisi import DaisiClient, DaisiConfig
config = DaisiConfig(
client_key="your-client-key",
orc_address="orc.daisi.net",
orc_port=443,
use_ssl=True
)
client = DaisiClient(
client_key=config.client_key,
orc_address=config.orc_address,
orc_port=config.orc_port
)
Available Clients
The SDK provides specialized clients for each service:
client.auth: Authentication operations (create/validate keys, auth codes)client.session: Session management (create, claim, close, connect)client.inference: Inference operations (create, send streaming, stats, close)client.models: Model discovery and requirementsclient.hosts: Host registration and managementclient.peers: Peer operationsclient.settings: Settings managementclient.host_commands: Host command streamingclient.app_commands: App command streaming
Usage Examples
Authentication
from daisi import DaisiClient
client = DaisiClient(client_key="initial-key")
# Send auth code
client.auth.send_auth_code("user@example.com")
# Validate auth code and get new client key
client_key, user_name, account_name, account_id = client.auth.validate_auth_code(
secret_key="secret",
email_or_phone="user@example.com",
auth_code="123456",
app_id="my-app"
)
Session Management
# Create session with preferences
session_id, host = client.session.create(
model_name="llama-3",
direct_connect_required=False,
preferred_region="us-west",
private_network_only=False
)
# Connect to session
sid, has_capacity, already_connected = client.session.connect(session_id)
Inference with Tool Groups
from protos.v1.models.InferenceModels_pb2 import (
ThinkChainOfThought,
InferenceCodingTools,
InferenceFileTools
)
# Create inference with tools
session_id, inference_id = client.inference.create(
session_id=session_id,
think_level=ThinkChainOfThought,
tool_groups=[InferenceCodingTools, InferenceFileTools]
)
# Send with custom parameters
for response in client.inference.send(
text="Write a Python function to calculate fibonacci",
temperature=0.7,
top_p=0.9,
max_tokens=2000
):
print(response.Content, end="")
Models
# Get required models
models_response = client.models.get_required_models()
Hosts
# Get available hosts
hosts = client.hosts.get_hosts()
for host in hosts:
print(f"{host.Name}: {host.Status} - {host.Region}")
Development
Generating Protobuf Code
If you modify the .proto files:
python generate_protos.py
Testing
# Run all tests
pytest
# Run with coverage
pytest --cov=src/daisi
# Run specific test file
pytest tests/test_client.py
Code Quality
# Format code
black src/ tests/
# Sort imports
isort src/ tests/
# Lint
flake8 src/ tests/
# Type checking
mypy src/
# Run all checks
make lint
Project Structure
daisi-sdk-python/
├── src/daisi/ # Main package
│ ├── __init__.py
│ ├── client.py # Main unified client
│ ├── config.py # Configuration
│ ├── base_client.py # Base gRPC client
│ ├── exceptions.py # Custom exceptions
│ └── clients/ # Service-specific clients
│ ├── auth.py
│ ├── session.py
│ ├── inference.py
│ ├── models.py
│ ├── hosts.py
│ ├── peers.py
│ ├── settings.py
│ └── commands.py
├── protos/v1/ # Protobuf definitions
│ ├── *.proto # Service definitions
│ └── models/ # Model definitions
├── src/protos/ # Generated Python code
├── tests/ # Test suite
├── pyproject.toml # Project configuration
├── generate_protos.py # Proto generation script
└── README.md
Architecture
The SDK is built on gRPC and Protocol Buffers, matching the .NET SDK architecture:
- gRPC: Efficient binary protocol with streaming support
- Protocol Buffers: Strongly-typed message definitions
- Session-based: Orchestrator (Orc) manages session lifecycle
- Streaming: Real-time token-by-token inference responses
- Direct Connect: Optional peer-to-peer mode
Contributing
Contributions are welcome! Ensure:
- Code follows PEP 8 with Black formatting
- All tests pass and coverage is maintained
- Type hints are included
- Documentation is updated
License
MIT License - see LICENSE file for details
Links
Project details
Release history Release notifications | RSS feed
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 daisi_sdk-0.1.0.tar.gz.
File metadata
- Download URL: daisi_sdk-0.1.0.tar.gz
- Upload date:
- Size: 70.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7cb3a09396a7769fa0b3c0d08aa563e6f2bc8f5232fdec3fba41e0338bcd3cd5
|
|
| MD5 |
c51a6546776a1b49ff013117686ab75e
|
|
| BLAKE2b-256 |
d365fb23c0ce3599db4a22ed706f0d2f8c01d3267e41d67dc32691034e80413a
|
File details
Details for the file daisi_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: daisi_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 125.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a3e0cb8254cf2048155780190020849ccb7d8d05ab39cdb1bc2f854ba5dbd698
|
|
| MD5 |
2e79fa090173c63e0a9d84024f15512b
|
|
| BLAKE2b-256 |
206af413aeae09cdca9139f8dfe9644109802d7004e0530a9697f5db02efe669
|