Skip to main content

ONEX Service Provider Interface - Protocol definitions

Project description

ONEX Service Provider Interface (omnibase_spi)

License: MIT Python 3.12+ Code style: black Type checked: mypy Pre-commit Protocols Domains

๐Ÿ“ฆ Package Renamed: This package has been renamed from omnibase-spi to omnibase_spi to follow Python naming conventions.

Pure protocol interfaces for the ONEX framework with zero implementation dependencies.

๐Ÿš€ Quick Start

# Install the package
pip install omnibase-spi

# Or with poetry
poetry add omnibase-spi

๐Ÿ“– Documentation

๐ŸŒŸ Overview

This repository contains all protocol definitions that define the contracts for ONEX services. These protocols enable duck typing and dependency injection without requiring concrete implementations.

๐Ÿ—๏ธ Architecture

The ONEX SPI follows a protocol-first design with 165 protocol files across 22 specialized domains:

  • Core System (16 protocols) - Logging, health monitoring, error handling
  • Container Management (21 protocols) - Dependency injection, lifecycle management
  • Workflow Orchestration (14 protocols) - Event-driven FSM coordination
  • MCP Integration (15 protocols) - Multi-subsystem tool coordination
  • Event Bus (13 protocols) - Distributed messaging infrastructure
  • Memory Management (15 protocols) - Workflow state persistence
  • Networking (6 protocols) - HTTP, Kafka, circuit breakers
  • File Handling (8 protocols) - File processing and type detection
  • Validation (11 protocols) - Input validation and compliance
  • Plus 13 more specialized domains

๐Ÿ”ง Key Features

  • Zero Implementation Dependencies - Pure protocol contracts only
  • Runtime Type Safety - Full @runtime_checkable protocol support
  • Dependency Injection - Sophisticated service lifecycle management
  • Event-Driven Architecture - Event sourcing and workflow orchestration
  • Multi-Subsystem Coordination - MCP integration and distributed tooling
  • Enterprise Features - Health monitoring, metrics, circuit breakers, and more

Architecture Principles

  • Zero Dependencies: No implementation dependencies, only typing imports
  • Protocol-First Design: All services defined through Python protocols
  • Domain Organization: Protocols organized by functional domain
  • Forward References: Uses TYPE_CHECKING imports to avoid circular dependencies

Repository Structure

src/omnibase/
โ”œโ”€โ”€ protocols/
โ”‚   โ”œโ”€โ”€ core/                    # Core system protocols
โ”‚   โ”‚   โ”œโ”€โ”€ protocol_canonical_serializer.py
โ”‚   โ”‚   โ”œโ”€โ”€ protocol_schema_loader.py
โ”‚   โ”‚   โ””โ”€โ”€ protocol_workflow_reducer.py
โ”‚   โ”œโ”€โ”€ event_bus/              # Event system protocols
โ”‚   โ”‚   โ”œโ”€โ”€ protocol_event_bus.py
โ”‚   โ”‚   โ”œโ”€โ”€ protocol_event_publisher.py
โ”‚   โ”‚   โ””โ”€โ”€ protocol_event_subscriber.py
โ”‚   โ”œโ”€โ”€ container/              # Dependency injection protocols
โ”‚   โ”‚   โ””โ”€โ”€ protocol_container.py
โ”‚   โ”œโ”€โ”€ discovery/              # Service discovery protocols
โ”‚   โ”‚   โ””โ”€โ”€ protocol_handler_discovery.py
โ”‚   โ””โ”€โ”€ file_handling/          # File processing protocols
โ”‚       โ”œโ”€โ”€ protocol_file_type_handler.py
โ”‚       โ””โ”€โ”€ protocol_file_writer.py

Setup Tasks

1. Initialize Git Repository

cd /Volumes/PRO-G40/Code/omnibase-spi
git init
git add .
git commit -m "Initial commit: ONEX protocol interfaces"

2. Python Packaging with Poetry

The project uses Poetry for dependency management. The pyproject.toml is already configured with:

  • Runtime dependencies: typing-extensions
  • Development dependencies: mypy, black, isort, pre-commit
  • Package configuration for publishing

3. Create Package Structure

# Create __init__.py files for proper package structure
touch src/omnibase/__init__.py
touch src/omnibase/protocols/__init__.py
touch src/omnibase/protocols/core/__init__.py
touch src/omnibase/protocols/event_bus/__init__.py
touch src/omnibase/protocols/container/__init__.py
touch src/omnibase/protocols/discovery/__init__.py
touch src/omnibase/protocols/file_handling/__init__.py

4. Set Up Development Environment with Poetry

# Install dependencies and create virtual environment
poetry install

# Activate virtual environment (optional - poetry run handles this)
poetry shell

# Install pre-commit hooks (includes SPI validation)
poetry run pre-commit install

# Install pre-push hooks for namespace validation
poetry run pre-commit install --hook-type pre-push -c .pre-commit-config-push.yaml

# Test pre-commit hooks
poetry run pre-commit run --all-files

5. Configure Type Checking

Create .mypy.ini:

[mypy]
python_version = 3.11
strict = True
warn_return_any = True
warn_unused_configs = True
disallow_untyped_defs = True

6. Configure Code Formatting

Create .pre-commit-config.yaml:

repos:
  - repo: https://github.com/psf/black
    rev: 23.3.0
    hooks:
      - id: black
  - repo: https://github.com/pycqa/isort
    rev: 5.12.0
    hooks:
      - id: isort
  - repo: https://github.com/pre-commit/mirrors-mypy
    rev: v1.0.0
    hooks:
      - id: mypy

Namespace Isolation & Validation

Critical: Complete Namespace Isolation

This SPI package maintains complete namespace isolation to prevent circular dependencies when installed by omnibase-core. All imports must use omnibase_spi.protocols.* paths only.

Validation Tools

1. Comprehensive SPI Protocol Validation

The repository includes a comprehensive validation framework with configurable rules:

# Run comprehensive validation with default configuration
python scripts/validation/comprehensive_spi_validator.py src/

# Run with custom configuration file
python scripts/validation/comprehensive_spi_validator.py src/ --config validation_config.yaml

# Apply automatic fixes for supported violations
python scripts/validation/comprehensive_spi_validator.py src/ --fix

# Generate JSON report for CI/CD integration
python scripts/validation/comprehensive_spi_validator.py src/ --json-report

# Pre-commit integration mode (faster)
python scripts/validation/comprehensive_spi_validator.py --pre-commit

Validation Rules (16 comprehensive rules):

  • SPI001: No Protocol __init__ methods
  • SPI002: Protocol naming conventions
  • SPI003: @runtime_checkable decorator enforcement
  • SPI004: Protocol method bodies (ellipsis only)
  • SPI005: Async I/O operations
  • SPI006: Proper Callable types
  • SPI007: No concrete classes in SPI
  • SPI008: No standalone functions
  • SPI009: ContextValue usage patterns
  • SPI010: Duplicate protocol detection
  • SPI011: Protocol name conflicts
  • SPI012: Namespace isolation
  • SPI013: Forward reference typing
  • SPI014: Protocol documentation
  • SPI015: Method type annotations
  • SPI016: SPI implementation purity

Configuration File (validation_config.yaml):

  • Customize rule severity levels (error/warning/info)
  • Enable/disable specific rules
  • Environment-specific overrides (pre_commit, ci_cd, development, production)
  • Performance optimization settings
  • Output format configuration

2. Pre-Push Hook Validation

# Manual validation
./scripts/validate-namespace-isolation.sh

# Validates:
# โœ… No external omnibase imports (only omnibase_spi.protocols.* allowed)  
# โœ… Protocol naming conventions (must start with "Protocol")
# โœ… Strong typing (no Any usage)
# โœ… Namespace isolation tests pass

2. CI/CD Validation

  • GitHub Actions: Automatic validation on all pushes and PRs
  • Multi-Python: Tests on Python 3.11, 3.12, 3.13
  • Isolation Testing: Verifies package can be installed without external dependencies
  • Cross-compatibility: Validates with strict mypy settings

3. Development Checks

# Quick namespace check
grep -r "from omnibase\." src/ | grep -v "from omnibase_spi.protocols"
# Should return no results

# Run namespace isolation tests
poetry run pytest tests/test_protocol_imports.py -v

# Full validation suite
poetry run pytest && poetry build

Namespace Rules

  1. โœ… ALLOWED: from omnibase_spi.protocols.types import ...
  2. โœ… ALLOWED: from omnibase_spi.protocols.core import ...
  3. โŒ FORBIDDEN: from omnibase_spi.model import ...
  4. โŒ FORBIDDEN: from omnibase_spi.core import ...
  5. โŒ FORBIDDEN: Any imports from external omnibase modules

Protocol Design Guidelines

1. Protocol Definition Pattern

from typing import TYPE_CHECKING, Protocol

if TYPE_CHECKING:
    from some.model import SomeModel

class ProtocolExample(Protocol):
    """Protocol description with clear contract definition."""

    def method_name(self, param: str) -> "SomeModel":
        """Method documentation with clear expectations."""
        ...

2. Zero Implementation Rule

  • Never import concrete implementations
  • Use TYPE_CHECKING imports for model types
  • All methods must be abstract (... body)

3. Forward Reference Pattern

# Good: Forward reference with TYPE_CHECKING
if TYPE_CHECKING:
    from omnibase_spi.model.core.model_node_metadata import NodeMetadataBlock

def process(self, block: "NodeMetadataBlock") -> str: ...

# Bad: Direct import creates dependency
from omnibase_spi.model.core.model_node_metadata import NodeMetadataBlock

Integration with omnibase-core

This repository provides the protocol contracts that omnibase-core implements:

# In omnibase-core implementations
from omnibase_spi.protocols.event_bus.protocol_event_bus import ProtocolEventBus

class EventBusImplementation(ProtocolEventBus):
    """Concrete implementation of the protocol."""
    pass

Pre-commit Validation Hooks

The repository includes comprehensive pre-commit hooks adapted from omnibase_core for SPI-specific validation:

Core SPI Validation

  • Protocol Architecture Validation: Ensures protocols follow SPI patterns
  • Protocol Duplicate Detection: Prevents duplicate protocol definitions
  • Namespace Isolation: Validates strict SPI namespace boundaries
  • SPI Purity: Ensures only protocol definitions (no implementations)

Enhanced Validation (New)

  • Typing Pattern Validation: Modern typing syntax enforcement (T | None vs Optional[T])
  • Naming Convention Validation: SPI-specific naming patterns
  • Async-by-Default Validation: Ensures I/O operations use async patterns
  • Callable vs Object Validation: Prevents object type where Callable is appropriate

Running Validation

# Run all pre-commit hooks
poetry run pre-commit run --all-files

# Run specific validation
poetry run pre-commit run validate-spi-protocols --all-files
poetry run pre-commit run validate-spi-typing-patterns --all-files
poetry run pre-commit run validate-spi-naming-conventions --all-files

# Run individual validators directly
poetry run python scripts/validation/validate_spi_protocols.py src/
poetry run python scripts/validation/validate_spi_typing_patterns.py src/
poetry run python scripts/validation/validate_spi_naming.py src/

Development Workflow

Testing Protocols

Protocols should be validated through:

  1. Type checking: poetry run mypy src/
  2. Code formatting: poetry run black src/
  3. Import sorting: poetry run isort src/
  4. Import testing: Ensure no circular dependencies
  5. Contract validation: Verify protocol completeness

Using the Package

Install from source:

# Install from local source
pip install /path/to/omnibase-spi

# Or install in development mode
pip install -e /path/to/omnibase-spi

Import protocols in other packages:

from omnibase_spi.protocols.core.protocol_canonical_serializer import ProtocolCanonicalSerializer
from omnibase_spi.protocols.event_bus.protocol_event_bus import ProtocolEventBus

Next Steps

  1. Complete packaging setup (pyproject.toml, init.py files)
  2. Initialize git repository and commit initial state
  3. Set up CI/CD pipeline for type checking and validation
  4. Create protocol documentation with usage examples
  5. Establish release process for protocol versioning

Dependencies

This repository has zero runtime dependencies by design. The only dependencies are:

  • typing-extensions for modern typing features
  • Development tools (mypy, black, isort) for code quality

Protocol Categories

  • Core Protocols: System-level contracts (serialization, schema loading, workflow)
  • Event Bus Protocols: Event-driven architecture contracts
  • Container Protocols: Dependency injection contracts
  • Discovery Protocols: Service and handler discovery contracts
  • File Handling Protocols: File processing and writing contracts

This repository serves as the foundation for the entire ONEX ecosystem's type safety and architectural contracts.

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guide for development guidelines and validation requirements.

Development Setup

# Clone the repository
git clone https://github.com/OmniNode-ai/omnibase_spi.git
cd omnibase_spi

# Install dependencies
poetry install

# Run validation
poetry run pre-commit run --all-files

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

The MIT License is a permissive open source license that allows you to:

  • โœ… Use the software for any purpose
  • โœ… Modify and distribute the software
  • โœ… Include the software in proprietary applications
  • โœ… Distribute copies of the software

๐ŸŒŸ Open Source

This project is completely open source and community-driven. We believe in:

  • Transparency - All development happens in the open
  • Community - Contributions from developers worldwide
  • Quality - Rigorous testing and validation standards
  • Innovation - Cutting-edge protocol design patterns

๐Ÿ“ž Support


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

omnibase_spi-0.2.0.tar.gz (220.6 kB view details)

Uploaded Source

Built Distribution

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

omnibase_spi-0.2.0-py3-none-any.whl (342.8 kB view details)

Uploaded Python 3

File details

Details for the file omnibase_spi-0.2.0.tar.gz.

File metadata

  • Download URL: omnibase_spi-0.2.0.tar.gz
  • Upload date:
  • Size: 220.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.11 Darwin/24.6.0

File hashes

Hashes for omnibase_spi-0.2.0.tar.gz
Algorithm Hash digest
SHA256 231e743d8925524d2379dcf8c28b55dd1bdd6b502d36992b847574a6e4ced81f
MD5 0b3116ac3e9acfc2c4aa6e9ebdf41eec
BLAKE2b-256 bff649872cebd5176f4ce27949f7a3d75c2c31a65fc2cdfa179af8e05d2a39da

See more details on using hashes here.

File details

Details for the file omnibase_spi-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: omnibase_spi-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 342.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.11 Darwin/24.6.0

File hashes

Hashes for omnibase_spi-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 68bd256bdd948851198d8f6d5172f4b8d516138c5111b787b095a502007a5271
MD5 092c92612268d2157f0ad09fb6ea8b0a
BLAKE2b-256 9b52825136e80a93a24347fb607213dd480e83ba584aa77fc40a8b0535b95335

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