Skip to main content

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 @command or class-based HuitzoCommand
  • ๐Ÿ”Œ 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 identifier
  • namespace: Organizational grouping
  • version: Semantic version
  • timeout: 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:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes with tests
  4. Ensure all tests pass (pytest)
  5. Run linters (ruff check src tests)
  6. Commit your changes (git commit -m 'Add amazing feature')
  7. Push to the branch (git push origin feature/amazing-feature)
  8. Open a Pull Request

License

See the LICENSE file for details.

Support


Built with โค๏ธ by the Huitzo 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

huitzo_sdk-0.0.8.tar.gz (94.3 kB view details)

Uploaded Source

Built Distribution

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

huitzo_sdk-0.0.8-py3-none-any.whl (43.8 kB view details)

Uploaded Python 3

File details

Details for the file huitzo_sdk-0.0.8.tar.gz.

File metadata

  • Download URL: huitzo_sdk-0.0.8.tar.gz
  • Upload date:
  • Size: 94.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for huitzo_sdk-0.0.8.tar.gz
Algorithm Hash digest
SHA256 ae3c272b2638ac8cfcd9f98aad031544f4ba3064fa184846c21677d0bfe271f7
MD5 7a04acad92a63d58b88c640b23e32cae
BLAKE2b-256 97979bea6ad0df3cd52d79a9d4212c30f3872d19f23f1d2508f9cc1b8f0316f8

See more details on using hashes here.

File details

Details for the file huitzo_sdk-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: huitzo_sdk-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 43.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for huitzo_sdk-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 a59ee7c1193c6f7d5a9b1b9d2cce92ef9ccd72c035d517eea38a1a2b2216d2db
MD5 13bcce9a8945649d4806d88ba018eb17
BLAKE2b-256 d11fc4e343e17811dba21b65df1412d1a3affee46fdd288b471975cb66ea5759

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