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.7.tar.gz (93.1 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.7-py3-none-any.whl (43.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: huitzo_sdk-0.0.7.tar.gz
  • Upload date:
  • Size: 93.1 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.7.tar.gz
Algorithm Hash digest
SHA256 bc79604da034cdb9e622a3c853f41a4d9183acc44416f93e25b4352715cb9d3b
MD5 704167fb20a10f6a720a230641f8e7f7
BLAKE2b-256 0d01cceb6b4090513525fe8509897618f970df48007087269547ce65dd9b4b60

See more details on using hashes here.

File details

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

File metadata

  • Download URL: huitzo_sdk-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 43.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-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 670f09316ae47a8dd37ac91a2f403b3a5d6a55e08d03b0343c04299ad05bad2f
MD5 bade583e4150ba83beef7795fe9a8692
BLAKE2b-256 a2aa8111d35d8578485b7d537500820466ec27adcdd7dcf76c44f52750f3e965

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