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 Part of Hexastack Governed by Hexaqual License: Apache 2.0

Part of the Hexastack Framework · Governed by Hexaqual.


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).
  • Distributed & Persistent Cache Adapters: CachePort and AsyncCachePort with in-memory (InMemoryCache, AsyncInMemoryCache), distributed Redis/Valkey (RedisCacheAdapter, AsyncRedisCacheAdapter), and persistent L2 filesystem storage (DiskCacheAdapter, AsyncDiskCacheAdapter).
  • High-Availability Primitives & Locks: LockPort and AsyncLockPort (reentrant in-memory, OS FileLockAdapter, and distributed RedisLockAdapter) and LeaderElectionPort / AsyncLeaderElectionPort (single-process and distributed Redis lease coordination).
  • Unified Object & File Storage: StoragePort and AsyncStoragePort with in-memory (InMemoryStorage, AsyncInMemoryStorage), local filesystem (LocalStorageAdapter, AsyncLocalStorageAdapter), and unified multi-cloud storage via fsspec (FsspecStorageAdapter, AsyncFsspecStorageAdapter for S3, GCS, Azure Blob Storage).
  • Core Domain Primitives: Generic Result[T, E], generic types, and standard exception hierarchies (HexastackError, ConfigurationError, MissingDependencyError, LockError, LeaderElectionError, StorageError, StorageNotFoundError).
  • Core Port Contracts: Standard abstract protocols and ABCs for repositories (Repository[E, ID]), unit of work (UnitOfWork), caching (CachePort), object storage (StoragePort), distributed locks (LockPort), leader election (LeaderElectionPort), 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, HexastackConfig, HexastackCoreConfig
├── ports/           # Repository, UnitOfWork, BootstrapperPort, LoggerPort, CachePort, StoragePort, LockPort, LeaderElectionPort
├── adapters/        # InMemory, Redis, DiskCache, FileLock, Storage (InMemory, Local, Fsspec) implementations
├── 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
Cache CachePort, AsyncCachePort, InMemoryCache, AsyncInMemoryCache, RedisCacheAdapter, AsyncRedisCacheAdapter, DiskCacheAdapter, AsyncDiskCacheAdapter
Config ConfigRegistry, HexastackConfig, HexastackCoreConfig, @config_section
Context get_correlation_id, set_correlation_id, correlation_scope, UserContext
Domain Result, Ok, Err, HexastackError, ConfigurationError, MissingDependencyError, EntityNotFoundError, LockError, LeaderElectionError, StorageError, StorageNotFoundError
Feature Flags EvaluationContext, FlagEvaluationDetails, InMemoryFeatureFlagAdapter, ConfigFeatureFlagAdapter
High Availability & Locks LockPort, AsyncLockPort, InMemoryLock, AsyncInMemoryLock, FileLockAdapter, AsyncFileLockAdapter, RedisLockAdapter, AsyncRedisLockAdapter, LeaderElectionPort, AsyncLeaderElectionPort, SingleProcessLeaderElection, AsyncSingleProcessLeaderElection, RedisLeaderElectionAdapter, AsyncRedisLeaderElectionAdapter
Ports BootstrapperPort, CachePort, AsyncCachePort, StoragePort, AsyncStoragePort, LockPort, AsyncLockPort, LeaderElectionPort, AsyncLeaderElectionPort, Repository, AsyncRepository, UnitOfWork, AsyncUnitOfWork, LoggerPort, PresenterPort, FeatureFlagPort
Registries GenericTypeRegistry, ExceptionRegistry
Storage StoragePort, AsyncStoragePort, InMemoryStorage, AsyncInMemoryStorage, LocalStorageAdapter, AsyncLocalStorageAdapter, FsspecStorageAdapter, AsyncFsspecStorageAdapter
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.11.2

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.11.2
File Size Uploaded Provenance Actions
hexastack_core-0.11.2.tar.gz 81.3 kB Without provenance Details for hexastack_core-0.11.2.tar.gz

Built distribution (wheel)

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

Total release size: 204.7 kB

Release files / hexastack_core-0.11.2.tar.gz

Download URL hexastack_core-0.11.2.tar.gz
Size 81.3 kB
Tags Source
SHA-256 checksum
How to use checksums
4065a83c08fd9e54243bfc50620e56b43f41872e25ca9aa6056522114487bc00
BLAKE2b-256 checksum
How to use checksums
50727e8461bcf9b8b9c4f38ddc34a11732c6b6d4d28069ccb2f4a1ba2ea6e33f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL hexastack_core-0.11.2-py3-none-any.whl
Size 123.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
15a4d32f577f658da8da4cf280529b9377927e26570626142ddfb32d24a8e84d
BLAKE2b-256 checksum
How to use checksums
7f32557389bf6987996b8a81121a0c1c7052f2be03c81900f89ad8cd919c3c5e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for hexastack-core 0.11.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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