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 the @command decorator
  • ๐Ÿ”Œ 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

Defining a 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)
    }

Using Built-in Integrations

from pydantic import BaseModel
from huitzo_sdk import command, Context, Result

class WeatherArgs(BaseModel):
    city: str

@command(
    name="get_weather",
    namespace="weather",
    version="1.0.0",
)
async def get_weather(args: WeatherArgs, 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 to register a sync or async function as a command.

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
โ”‚       โ”œโ”€โ”€ 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-1.0.0.tar.gz (199.8 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-1.0.0-py3-none-any.whl (109.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for huitzo_sdk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b13a80b5c8190a8d8c8cbbd73d2bac489cd701eb6197f03db1b39726dc324b61
MD5 46c45f3b8b89c9d6e5bc26db2856210c
BLAKE2b-256 274fd78a8fdddee9b4f8a06ab2e360bb7a12b4c1a3f95dbe4471de78308d51dc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: huitzo_sdk-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 109.3 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-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 88b6305a583e903036f65c70a0e2913c6d143a04770c48ca3bb3c1d599971e9f
MD5 a564f8007c7b5cb9af6622baeecb7f4e
BLAKE2b-256 b79dd78be0529852582b3eb8b8a610c3cb612c3b9d229b35aa6c9df23d59f85d

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