Huitzo SDK for building Intelligence Packs
Project description
Huitzo SDK
The Huitzo SDK is a Python framework for building Intelligence Packsโreusable, scalable command modules that integrate with the Huitzo platform.
Features
- ๐ฏ Simple Command Decorator: Define commands with
@commandor class-basedHuitzoCommand - ๐ Built-in Integrations: Pre-configured clients for LLM, Email, HTTP, Telegram, and File operations
- ๐พ Flexible Storage: Pluggable storage backends with namespace isolation
- ๐ Async First: Full async/await support with automatic sync function handling
- โ Type Safe: Built on Pydantic for runtime validation and type hints
- ๐ก๏ธ Error Handling: Comprehensive error hierarchy for robust error management
Installation
pip install huitzo-sdk
Quick Start
Function-based Command
from pydantic import BaseModel
from huitzo_sdk import command, Context, Result
class GreetingArgs(BaseModel):
name: str
language: str = "en"
@command(
name="greet",
namespace="examples",
version="1.0.0",
description="Greet a user in their language"
)
async def greet_user(args: GreetingArgs, ctx: Context) -> Result:
greetings = {"en": "Hello", "es": "Hola", "fr": "Bonjour"}
greeting = greetings.get(args.language, "Hello")
return {
"message": f"{greeting}, {args.name}!",
"user_id": str(ctx.user_id)
}
Class-based Command
from huitzo_sdk import HuitzoCommand, Context, Result
class WeatherCommand(HuitzoCommand):
name = "get_weather"
namespace = "weather"
version = "1.0.0"
async def execute(self, args: dict, ctx: Context) -> Result:
# Use built-in HTTP client
response = await ctx.http.get(
f"https://api.weather.com/v1/forecast?city={args['city']}"
)
return response.json()
Core Concepts
Commands
Commands are the building blocks of Intelligence Packs. Use the @command decorator for simple functions or extend HuitzoCommand for more control with lifecycle hooks.
Decorator parameters:
name: Command identifiernamespace: Organizational groupingversion: Semantic versiontimeout: Max execution time (default: 60s)retries: Number of retry attempts (default: 3)
Context
The Context object provides access to:
- Identity:
user_id,tenant_id,session_id,correlation_id - Metadata:
command_name,namespace,command_version - Integrations:
llm,email,http,telegram,files
async def my_command(args: dict, ctx: Context) -> Result:
# Access user identity
user_id = ctx.user_id
# Use integrations
completion = await ctx.llm.complete(
prompt="Explain quantum computing",
model="gpt-4"
)
# Send results via email
await ctx.email.send(
to="user@example.com",
subject="Your Results",
body=completion
)
return {"status": "sent"}
Integrations
Built-in clients for common operations:
- LLMClient: Language model completions and chat
- EmailClient: Send emails with templates
- HTTPClient: HTTP requests with security controls
- TelegramClient: Send messages and interact with Telegram
- FileClient: File operations and storage
Storage
Persistent storage with namespace isolation:
from huitzo_sdk.storage import InMemoryBackend, StorageNamespace
# Create storage backend
backend = InMemoryBackend()
storage = StorageNamespace(backend=backend, namespace="my-app")
# Store and retrieve data
await storage.set("user:123", {"name": "Alice", "score": 100})
user_data = await storage.get("user:123")
Error Handling
The SDK provides a comprehensive error hierarchy:
from huitzo_sdk import (
HuitzoError,
ValidationError,
TimeoutError,
IntegrationError,
LLMError,
HTTPError,
StorageError
)
try:
result = await ctx.llm.complete(prompt="Hello")
except LLMError as e:
# Handle LLM-specific errors
print(f"LLM failed: {e}")
except TimeoutError as e:
# Handle timeout errors
print(f"Request timed out: {e}")
except HuitzoError as e:
# Catch-all for other SDK errors
print(f"Huitzo error: {e}")
Development
Prerequisites
- Python 3.11 or higher
- uv (recommended) or pip
Setup
# Clone the repository
git clone https://github.com/Huitzo-Inc/sdk.git
cd sdk
# Install dependencies
uv sync --dev
# Or with pip
pip install -e ".[dev]"
Running Tests
# Run all tests
pytest
# Run with coverage
pytest --cov=huitzo_sdk --cov-report=term-missing
# Run specific test file
pytest tests/test_command.py
Code Quality
# Type checking
mypy src/huitzo_sdk
# Linting and formatting
ruff check src tests
ruff format src tests
Project Structure
huitzo-sdk/
โโโ src/
โ โโโ huitzo_sdk/
โ โโโ __init__.py # Public API exports
โ โโโ command.py # @command decorator and HuitzoCommand
โ โโโ context.py # Context object
โ โโโ types.py # Core type definitions
โ โโโ errors.py # Error hierarchy
โ โโโ integrations/ # Integration clients
โ โ โโโ llm.py
โ โ โโโ email.py
โ โ โโโ http.py
โ โ โโโ telegram.py
โ โ โโโ files.py
โ โโโ storage/ # Storage backends
โ โโโ protocol.py
โ โโโ memory.py
โ โโโ namespace.py
โโโ tests/ # Test suite
โโโ pyproject.toml # Project configuration
โโโ README.md # This file
Contributing
We welcome contributions! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes with tests
- Ensure all tests pass (
pytest) - Run linters (
ruff check src tests) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
See the LICENSE file for details.
Support
- ๐ง Email: support@huitzo.com
- ๐ฌ Community: Discord
- ๐ Documentation: docs.huitzo.com
- ๐ Issues: GitHub Issues
Built with โค๏ธ by the Huitzo team
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 huitzo_sdk-0.0.10.tar.gz.
File metadata
- Download URL: huitzo_sdk-0.0.10.tar.gz
- Upload date:
- Size: 120.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0819ed227e1f3ed4318d8033872ae95739c73503d92109d262b2788edc816767
|
|
| MD5 |
3f3c0b96ad9dc17a5cb7df99e9dab961
|
|
| BLAKE2b-256 |
ad70747915f28de152168997ad8431aaaed6a01bef7640de44d9f60b4ab31a1f
|
File details
Details for the file huitzo_sdk-0.0.10-py3-none-any.whl.
File metadata
- Download URL: huitzo_sdk-0.0.10-py3-none-any.whl
- Upload date:
- Size: 61.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5474dc51d829b225e8049044e7ab2ee8cb6f56ad890157257b620b67cc1381f4
|
|
| MD5 |
afe1a968af6302e28c13a9183db65829
|
|
| BLAKE2b-256 |
99f56968355a81296b1e7a6b610432e28c144809d2378ad0668640bc57379997
|