Skip to main content

A framework for building Hoshii-compliant code components

Project description

hoshii-cdk

A Python framework for building Hoshii-compliant code components with declarative action definitions.

Installation

pip install hoshii-cdk

Quick Start

Define a component with typed actions:

from hoshii_cdk import Component, action
from your_proto_package import ListItemsRequest, ListItemsResponse

class ItemsComponent(Component):
    name = "Items"
    description = "Item/product operations"
    
    @action(
        name="List Items",
        description="List items with optional filtering and pagination",
        request_schema=ListItemsRequest,
        response_schema=ListItemsResponse,
    )
    def list_items(self, request: dict) -> dict:
        # Your implementation here
        ...

Register and use the component:

from hoshii_cdk import Registry
from your_components import ItemsComponent

registry = Registry()
registry.register(ItemsComponent)

# Get manifest for workflow platform introspection
manifest = registry.get_manifest()

# Invoke an action
result = registry.invoke("Items", "list_items", {"active_only": True})

Features

  • Declarative Actions: Define actions with @action decorator including name, description, and schemas
  • Protobuf Schema Support: Automatically converts protobuf message types to JSON Schema
  • Registry System: Discover, register, and invoke component actions
  • Workflow Platform Integration: Get action manifests with full schema information for UI generation
  • Manifest Generation: Export component metadata to JSON files for build-time discovery
  • Runtime Execution: Load manifests and execute actions in sandboxed environments (e.g., e2b)
  • CLI Tools: Command-line utilities for generating and validating manifests

API Reference

Component

Base class for defining components:

class MyComponent(Component):
    name = "My Component"
    description = "Description of what this component does"

@action

Decorator for defining actions:

@action(
    name="Action Name",
    description="What this action does",
    request_schema=RequestProtoMessage,
    response_schema=ResponseProtoMessage,
    tags=["optional", "tags"],
)
def my_action(self, request: dict) -> dict:
    ...

Registry

Central registry for managing components:

registry = Registry()

# Register a component
registry.register(MyComponent)

# Auto-discover components in a module
registry.discover("my_package.components")

# Get manifest with all actions and schemas
manifest = registry.get_manifest()

# Invoke an action
result = registry.invoke("ComponentName", "action_name", request_dict)

Manifest Workflow

The CDK supports a two-phase workflow for integration with workflow platforms:

Build-Time: Generate Manifest

Generate a JSON manifest containing all component and action metadata:

from hoshii_cdk import Registry, generate_manifest

# Discover and register components
registry = Registry()
registry.discover("my_component.components")

# Generate manifest.json
generate_manifest(registry, "manifest.json")

Or use the CLI:

python -m hoshii_cdk.cli generate \
  --module my_component.components \
  --output manifest.json

The generated manifest contains:

  • Component names and descriptions
  • Action names, descriptions, and tags
  • Full JSON Schema for request/response types
  • All metadata needed for UI generation

Runtime: Execute from Manifest

In a sandboxed environment (e.g., e2b), load the manifest and execute actions:

from hoshii_cdk import ComponentRunner

# Initialize runner with manifest and component module
runner = ComponentRunner("manifest.json", "my_component.components")

# Import components
runner.import_components()

# List available components and actions
components = runner.list_components()  # ["Items", "BusinessPartners"]
actions = runner.list_actions("Items")  # ["list_items", "get_item"]

# Get schema for an action
schema = runner.get_action_schema("Items", "list_items")
# Returns: {"request_schema": {...}, "response_schema": {...}}

# Invoke an action
result = runner.invoke("Items", "list_items", {"active_only": True})

CLI Tools

Validate a manifest:

python -m hoshii_cdk.cli validate manifest.json -vv

Development

Setup

  1. Clone the repository:
git clone https://github.com/hoshii-ai/hoshii-cdk-python
cd hoshii-cdk-python
  1. Create and activate a virtual environment:
python3 -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  1. Install the package in development mode with dev dependencies:
pip install -e ".[dev]"

Running Tests

Run all tests:

pytest

Run with coverage:

pytest --cov=hoshii_cdk --cov-report=html

Run specific test file:

pytest tests/test_component.py -v

Building the Package

  1. Install build tools:
pip install build twine
  1. Build the package:
python -m build

This creates distribution files in the dist/ directory:

  • hoshii_cdk-1.0.0-py3-none-any.whl (wheel)
  • hoshii-cdk-1.0.0.tar.gz (source distribution)

Publishing to PyPI

The package includes a publish script for easy deployment:

Quick Publish

# Publish to PyPI
./scripts/publish.sh

# Publish to TestPyPI (recommended first)
./scripts/publish.sh --test

# Build only (no upload)
./scripts/publish.sh --dry-run

Manual Publishing

If you prefer to publish manually:

Test PyPI (Recommended First)
  1. Create an account on Test PyPI

  2. Upload to Test PyPI:

python -m build
python -m twine upload --repository testpypi dist/*
  1. Test installation from Test PyPI:
pip install --index-url https://test.pypi.org/simple/ hoshii-cdk
Production PyPI
  1. Create an account on PyPI

  2. Create an API token:

    • Go to Account Settings → API tokens
    • Create a token for the project or account
  3. Configure credentials (optional):

# Create ~/.pypirc
cat > ~/.pypirc << EOF
[pypi]
username = __token__
password = pypi-YOUR-API-TOKEN
EOF
chmod 600 ~/.pypirc
  1. Upload to PyPI:
python -m build
python -m twine upload dist/*

Or with token directly:

python -m twine upload -u __token__ -p pypi-YOUR-API-TOKEN dist/*
  1. Verify installation:
pip install hoshii-cdk

Version Bumping

Update the version in pyproject.toml and src/hoshii_cdk/__init__.py before publishing:

# pyproject.toml
[project]
version = "1.0.1"
# src/hoshii_cdk/__init__.py
__version__ = "1.0.1"

License

MIT

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

hoshii_cdk-1.0.8.tar.gz (28.5 kB view details)

Uploaded Source

Built Distribution

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

hoshii_cdk-1.0.8-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file hoshii_cdk-1.0.8.tar.gz.

File metadata

  • Download URL: hoshii_cdk-1.0.8.tar.gz
  • Upload date:
  • Size: 28.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for hoshii_cdk-1.0.8.tar.gz
Algorithm Hash digest
SHA256 f64802548726932256f063475d90215492d26dd0bba8c9daf8be2e5d60aa2612
MD5 c917f36a69a8fea3cc1f8d42f7301b8a
BLAKE2b-256 e6efae08041cbd185c1e20158be5c57ba174e10af045ec7edf85d0f5fd4f8dfc

See more details on using hashes here.

File details

Details for the file hoshii_cdk-1.0.8-py3-none-any.whl.

File metadata

  • Download URL: hoshii_cdk-1.0.8-py3-none-any.whl
  • Upload date:
  • Size: 19.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for hoshii_cdk-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 663d49e7b51fd4a97d65acc839acd6a3984ef267b2316b98a7805a1cdd3a40f8
MD5 2c9245ee01a79fede7c9d2adc15bd0c3
BLAKE2b-256 c68c5c08823d6ba2c3d6962b57a73a8d7307b4ad8b7aa888643ee9e5b7dae2e5

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