Skip to main content

hexastack-core

hexastack-core

The foundational kernel of Hexastack: dependency injection, abstract ports, domain abstractions, configuration registry, and the modular bootstrap lifecycle.

PyPI: hexastack-core Python 3.13+ Coverage License: Apache 2.0

1. Overview & Capabilities

hexastack-core serves as the zero-dependency (excluding pydantic and rodi) microkernel for all Hexastack packages. It establishes:

  • Dependency Injection Engine: Powered by rodi, managing service lifecycles (singleton, scoped, transient).
  • Feature Flag Port & Providers: Vendor-agnostic feature toggling (FeatureFlagPort, EvaluationContext, ConfigFeatureFlagAdapter, InMemoryFeatureFlagAdapter) with multi-tenant and ambient UserContext targeting.
  • Core Domain Primitives: Generic Result[T, E], generic types, and standard exception hierarchies (HexastackError, ConfigurationError, MissingDependencyError).
  • Core Port Contracts: Standard abstract protocols and ABCs for repositories (Repository[E, ID]), unit of work (UnitOfWork), logging (LoggerPort), presenters (PresenterPort), feature flags (FeatureFlagPort), and bootstrappers (BootstrapperPort).
  • Configuration & Type Registries: Type-safe Pydantic configuration parsing from TOML (ConfigRegistry) and generic type registries (GenericTypeRegistry).
  • Three-Phase Bootstrap Engine: Deterministic orchestration of Phase 1 config registration, Phase 2 container assembly, and Phase 3 reflective scanning.
  • Testing & Quality Toolkit:
    • assert_clean_architecture(...): Hexagonal architecture boundary verification powered by pytest-archon.
    • create_test_runtime(...): Lightweight in-memory DI test harness and doubles (TestRuntime).
    • cqrs_strategy(...): Hypothesis property-based fuzzing strategy generator for Pydantic/dataclass CQRS models.
    • Feature flag testing: @parametrize_flags, flag_scope, @require_feature, and @require_extra.
  • Context Utilities: Async-safe correlation ID and context variable management (get_correlation_id, set_correlation_id, UserContext).

2. Package Anatomy & Key Components

hexastack_core/
├── domain/          # Result[T, E], HexastackError, Entity, ValueObject, EvaluationContext
├── ports/           # Repository, UnitOfWork, BootstrapperPort, LoggerPort, PresenterPort, FeatureFlagPort
├── adapters/        # InMemoryRepository, InMemoryUnitOfWork, InMemoryFeatureFlagAdapter, ConfigFeatureFlagAdapter
├── infra/           # Bootstrap engine, ConfigRegistry, GenericTypeRegistry, decorators
├── testing/         # assert_clean_architecture, create_test_runtime, cqrs_strategy, flag_scope, isolation
└── utils/           # Context variable utilities, reflection helpers

Key Exports

Category Exports
Bootstrap bootstrap, BootstrapContext, BootstrapResult, scan_modules
Config ConfigRegistry, HexastackConfig, HexastackCoreConfig, @config_section
Context get_correlation_id, set_correlation_id, correlation_scope, UserContext
Domain Result, Ok, Err, HexastackError, ConfigurationError, MissingDependencyError, EntityNotFoundError
Feature Flags EvaluationContext, FlagEvaluationDetails, InMemoryFeatureFlagAdapter, ConfigFeatureFlagAdapter
Ports BootstrapperPort, Repository, AsyncRepository, UnitOfWork, AsyncUnitOfWork, LoggerPort, PresenterPort, FeatureFlagPort
Registries GenericTypeRegistry, ExceptionRegistry
Testing assert_clean_architecture, create_test_runtime, TestRuntime, cqrs_strategy, faker_strategy, flag_scope, generate_synthetic_payload, isolate_registries, parametrize_flags, @require_extra, @require_feature, seeded_faker

3. Monorepo & Sibling Relationships

graph TD
    subgraph SiblingPackages ["Dependent Sibling Packages"]
        CQRS["hexastack-cqrs"]
        LOG["hexastack-logging"]
        DB["hexastack-db"]
        FASTAPI["hexastack-fastapi"]
        GRAPHQL["hexastack-graphql"]
        MCP["hexastack-mcp"]
        GRPC["hexastack-grpc"]
        CLI["hexastack-cli"]
        UMBRELLA["hexastack"]
    end

    subgraph CoreKernel ["hexastack-core"]
        DI["rodi.Container"]
        BOOT["Bootstrap Engine"]
        PORTS["Abstract Ports (UoW, Repo, Logger)"]
        CONF["ConfigRegistry"]
    end

    CQRS -->|implements BootstrapperPort, uses rodi| CoreKernel
    LOG -->|implements LoggerPort & BootstrapperPort| CoreKernel
    DB -->|implements Repository & UnitOfWork ports| CoreKernel
    FASTAPI -->|implements BootstrapperPort, consumes DI| CoreKernel
    GRAPHQL -->|implements BootstrapperPort, consumes DI| CoreKernel
    MCP -->|implements BootstrapperPort, consumes DI| CoreKernel
    GRPC -->|implements BootstrapperPort, consumes DI| CoreKernel
    CLI -->|implements BootstrapperPort, consumes DI| CoreKernel
    UMBRELLA -->|orchestrates bootstrap| CoreKernel

Explicit Dependencies (Direct)

  • pydantic>=2.13.4: Schema validation and config parsing.
  • rodi>=2.1.0: Fast, lightweight dependency injection container.

Implied / Behavioral Relationships (DI-Mediated)

  • Provides Ports: Defines UnitOfWorkPort and Repository implemented by hexastack-db.
  • Provides Telemetry Contract: Defines LoggerPort implemented by hexastack-logging.
  • Provides Bootstrap Framework: All siblings expose extension entry points implementing BootstrapperPort.

4. Installation

# Standalone installation
pip install hexastack-core

# Via umbrella package
pip install hexastack

5. Configuration Reference

Configuration schemas are registered under [hexastack]:

[hexastack]
app_name = "my-application"
environment = "production" # "development", "staging", "production", "test"
debug = false

6. Quickstart Example

from hexastack_core.infra.bootstrap import bootstrap
from hexastack_core.ports.bootstrap import BootstrapperPort, BootstrapContext
from hexastack_core.domain.result import Ok, Err, Result


# 1. Implement a custom extension
class ServiceBootstrapper(BootstrapperPort):
    name = "custom_service"
    order = 10

    def configure(self, context: BootstrapContext) -> None:
        context.container.add_instance("Service Configured", declared_class=str)


# 2. Run deterministic bootstrap
result = bootstrap(bootstrappers=[ServiceBootstrapper()], auto_discover=False)
value = result.container.get(str)
print(value)  # "Service Configured"

Metadata

Release files for hexastack-core 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hexastack-core 0.1.0
File Size Uploaded
hexastack_core-0.1.0.tar.gz 32.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hexastack-core 0.1.0
File Interpreter ABI Platform
hexastack_core-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 87.9 kB

Release files / hexastack_core-0.1.0.tar.gz

Download URL hexastack_core-0.1.0.tar.gz
Size 32.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5c29c86624af24cae9d465fbd552fc365ba7714525120bfd19c7f941dfdf4586
BLAKE2b-256 checksum
How to use checksums
0a1c9997316a81046ec87ebb85fb4ca5384e59a10af5e2fa15867c593573e600
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / hexastack_core-0.1.0-py3-none-any.whl

Download URL hexastack_core-0.1.0-py3-none-any.whl
Size 55.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d750a7ca782a7209389216f921001ef961b8fe145b23ca755a3576f833290355
BLAKE2b-256 checksum
How to use checksums
686f73c65fc143a7e8011572b2167c7d6a997b04068cbf30f20bea9b925ab9d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.5

2 release files

0.3.0

2 release files

0.2.0

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page