Skip to main content

The official Python library for the Hanzo API

Project description

Hanzo Python SDK

CI PyPI Python Version License

The official Python SDK for the Hanzo AI platform, providing unified access to 100+ LLM providers through a single OpenAI-compatible API interface.

๐Ÿš€ Features

  • Unified API: Single interface for 100+ LLM providers (OpenAI, Anthropic, Google, Meta, etc.)
  • OpenAI Compatible: Drop-in replacement for OpenAI SDK
  • Enterprise Features: Cost tracking, rate limiting, observability
  • Local AI Support: Run models locally with node infrastructure
  • Model Context Protocol (MCP): Advanced tool use and context management
  • Agent Framework: Build and orchestrate AI agents
  • Memory Management: Persistent memory and RAG capabilities
  • Network Orchestration: Distributed AI compute capabilities

๐Ÿ“ฆ Installation

Basic Installation

pip install hanzoai

Full Installation (All Features)

pip install "hanzoai[all]"

Development Installation

git clone https://github.com/hanzoai/python-sdk.git
cd python-sdk
make setup

๐ŸŽฏ Quick Start

Basic Usage

from hanzoai import Hanzo

# Initialize client
client = Hanzo(api_key="your-api-key")

# Chat completion
response = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)

Using Different Providers

# Use Claude
response = client.chat.completions.create(
    model="claude-3-opus-20240229",
    messages=[{"role": "user", "content": "Hello!"}]
)

# Use local models
response = client.chat.completions.create(
    model="llama2:7b",
    messages=[{"role": "user", "content": "Hello!"}]
)

๐Ÿ—๏ธ Architecture

Package Structure

python-sdk/
โ”œโ”€โ”€ pkg/
โ”‚   โ”œโ”€โ”€ hanzo/          # CLI and orchestration tools
โ”‚   โ”œโ”€โ”€ hanzo-mcp/      # Model Context Protocol implementation
โ”‚   โ”œโ”€โ”€ hanzo-agents/   # Agent framework
โ”‚   โ”œโ”€โ”€ hanzo-network/  # Distributed network capabilities
โ”‚   โ”œโ”€โ”€ hanzo-memory/   # Memory and RAG
โ”‚   โ”œโ”€โ”€ hanzo-aci/      # AI code intelligence
โ”‚   โ”œโ”€โ”€ hanzo-repl/     # Interactive REPL
โ”‚   โ””โ”€โ”€ hanzoai/        # Core SDK

Core Components

1. Hanzo CLI (hanzo)

Command-line interface for AI operations:

# Chat with AI
hanzo chat

# Start local node
hanzo node start

# Manage router
hanzo router start

# Interactive REPL
hanzo repl

2. Model Context Protocol (hanzo-mcp)

Advanced tool use and context management:

from hanzo_mcp import create_mcp_server

server = create_mcp_server()
server.register_tool(my_tool)
server.start()

3. Agent Framework (hanzo-agents)

Build and orchestrate AI agents:

from hanzo_agents import Agent, Swarm

agent = Agent(
    name="researcher",
    model="gpt-4",
    instructions="You are a research assistant"
)

swarm = Swarm([agent])
result = await swarm.run("Research quantum computing")

4. Network Orchestration (hanzo-network)

Distributed AI compute:

from hanzo_network import LocalComputeNode, DistributedNetwork

node = LocalComputeNode(node_id="node-001")
network = DistributedNetwork()
network.register_node(node)

5. Memory Management (hanzo-memory)

Persistent memory and RAG:

from hanzo_memory import MemoryService

memory = MemoryService()
await memory.store("key", "value")
result = await memory.retrieve("key")

๐Ÿ› ๏ธ Development

Setup Development Environment

# Install Python 3.10+
make install-python

# Setup virtual environment
make setup

# Install development dependencies
make dev

Running Tests

# Run all tests
make test

# Run specific package tests
make test-hanzo
make test-mcp
make test-agents

# Run with coverage
make test-coverage

Code Quality

# Format code
make format

# Run linting
make lint

# Type checking
make type-check

Building Packages

# Build all packages
make build

# Build specific package
cd pkg/hanzo && uv build

๐Ÿ“š Documentation

Package Documentation

API Reference

See the API documentation for detailed API reference.

๐Ÿ”ง Configuration

Environment Variables

# API Configuration
HANZO_API_KEY=your-api-key
HANZO_BASE_URL=https://api.hanzo.ai

# Router Configuration
HANZO_ROUTER_URL=http://localhost:4000/v1

# Node Configuration
HANZO_NODE_URL=http://localhost:8000/v1

# Logging
HANZO_LOG_LEVEL=INFO

Configuration File

Create ~/.hanzo/config.yaml:

api:
  key: your-api-key
  base_url: https://api.hanzo.ai

router:
  url: http://localhost:4000/v1
  
node:
  url: http://localhost:8000/v1
  workers: 4
  
logging:
  level: INFO

๐Ÿšข Deployment

Docker

# Build image
docker build -t hanzo-sdk .

# Run container
docker run -p 8000:8000 hanzo-sdk

Docker Compose

# Start all services
docker-compose up

# Start specific service
docker-compose up router

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Workflow

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Make changes and test
  4. Commit changes (git commit -m 'Add amazing feature')
  5. Push to branch (git push origin feature/amazing-feature)
  6. Open Pull Request

Code Standards

  • Follow PEP 8
  • Use type hints
  • Write tests for new features
  • Update documentation
  • Run make lint before committing

๐Ÿ“Š Performance

Benchmarks

Operation Latency Throughput
Chat Completion 50ms 20 req/s
Embedding 10ms 100 req/s
Local Inference 200ms 5 req/s

Optimization Tips

  • Use streaming for long responses
  • Enable caching for repeated queries
  • Use batch operations when possible
  • Configure appropriate timeouts

๐Ÿ”’ Security

  • API keys are encrypted at rest
  • All communications use TLS 1.3+
  • Regular security audits
  • SOC 2 Type II certified

Report security issues to security@hanzo.ai

๐Ÿ“„ License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • OpenAI for the API specification
  • Anthropic for Claude integration
  • The open-source community

๐Ÿ“ž Support

๐Ÿ—บ๏ธ Roadmap

  • Multi-modal support (images, audio, video)
  • Enhanced caching strategies
  • WebSocket streaming
  • Browser SDK
  • Mobile SDKs (iOS, Android)

Built with โค๏ธ by the Hanzo team

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

hanzoai-2.2.1.tar.gz (640.0 kB view details)

Uploaded Source

Built Distribution

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

hanzoai-2.2.1-py3-none-any.whl (451.8 kB view details)

Uploaded Python 3

File details

Details for the file hanzoai-2.2.1.tar.gz.

File metadata

  • Download URL: hanzoai-2.2.1.tar.gz
  • Upload date:
  • Size: 640.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.20 {"installer":{"name":"uv","version":"0.11.20","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for hanzoai-2.2.1.tar.gz
Algorithm Hash digest
SHA256 7890f8b441373f3bd9aab8953161622c1d2a5f69203a629cf9303f4f0294fc15
MD5 f593496be8cc9ef7fc9cd7405ed4d115
BLAKE2b-256 72ea249054f9b17cd924a2a19b2f475ad05a046e77e777a15ad7fc8455dbda20

See more details on using hashes here.

File details

Details for the file hanzoai-2.2.1-py3-none-any.whl.

File metadata

  • Download URL: hanzoai-2.2.1-py3-none-any.whl
  • Upload date:
  • Size: 451.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.20 {"installer":{"name":"uv","version":"0.11.20","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for hanzoai-2.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8a2d1feb7525cdc6810f1dec1b3c09755cb58ab9efb0dc78cac21268ca4e0d22
MD5 e3c6c9f6c1b12a8b0617619d46e03ca7
BLAKE2b-256 c4b0d8ef8e29be4f9b06d48b2b56974ee64e56decb52f0511791e2359a8ee113

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