Skip to main content

Enterprise Foundation Framework - Modern Python 3.13 + Clean Architecture

Project description

FLEXT-Core

FLEXT-Core is the foundational library for the FLEXT ecosystem, providing a robust set of architectural primitives, patterns, and utilities for building enterprise-grade Python applications. It enforces Railway-Oriented Programming (ROP), Dependency Injection (DI), and Command Query Responsibility Segregation (CQRS) to ensure type safety, scalability, and maintainability.

Reviewed: 2026-02-17 | Version: 0.10.0-dev

Part of the FLEXT ecosystem.

🚀 Key Features

  • Railway-Oriented Programming: handling errors as values using FlextResult[T, E], eliminating unexpected exceptions in business logic.
  • Dependency Injection: A lightweight, type-safe DI container (FlextContainer) with scoped services and bridge integration.
  • CQRS Dispatcher: A strictly typed FlextDispatcher for routing commands, queries, and events to their respective handlers.
  • Domain-Driven Design: Base classes (FlextModels, FlextService) and mixins for rich domain modeling.
  • Protocol-Based Architecture: Extensive use of Python Protocol for loose coupling and improved testability.
  • Infrastructure Helpers: Built-in support for structured logging, configuration management, and context propagation.

📦 Installation

Install flext-core using pip:

pip install flext-core

Or with Poetry:

poetry add flext-core

🛠️ Usage

Railway-Oriented Results

Replace exception handling with FlextResult for predictable control flow.

from flext_core import FlextResult as r

def divide(a: int, b: int) -> r[float]:
    if b == 0:
        return r[float].fail("Division by zero")
    return r[float].ok(a / b)

result = divide(10, 2)
if result.is_success:
    print(f"Result: {result.unwrap()}")
else:
    print(f"Error: {result.error}")

Dependency Injection

Manage your application's dependencies cleanly using FlextContainer and FlextRuntime.

from flext_core import FlextContainer, Provide, inject, FlextService

# 1. Register a service
container = FlextContainer.get_global()
container.register_factory("db_client", lambda: DatabaseClient())

# 2. Inject into functions
@inject
def get_user(user_id: str, db=Provide["db_client"]):
    return db.query(user_id)

# 3. Inject into Services
class UserService(FlextService):
    def get_user(self, user_id: str):
        # Access container directly via self.container
        db = self.container.get("db_client").unwrap()
        return db.query(user_id)

CQRS Dispatching

Decouple your business logic using the FlextDispatcher.

from dataclasses import dataclass
from flext_core import FlextDispatcher, FlextResult as r

# 1. Define a Command
@dataclass
class CreateUser:
    username: str
    email: str

# 2. Define a Handler
def handle_create_user(cmd: CreateUser) -> r[str]:
    # Business logic here...
    return r[str].ok(f"User {cmd.username} created")

# 3. Register and Dispatch
dispatcher = FlextDispatcher()
dispatcher.register_handler(CreateUser, handle_create_user)

result = dispatcher.dispatch(CreateUser("alice", "alice@example.com"))

🏗️ Architecture

FLEXT-Core is designed around Clean Architecture and SOLID principles.

  • Protocols First: Interfaces are defined using Protocol to adhere to the Dependency Inversion Principle.
  • Layered Structure:
    • Runtime: Bridges external libraries and provides the DI surface.
    • Container: Manages service lifecycles (Singleton, Factory, Scoped).
    • Handlers/Dispatcher: Orchestrates application flow.

🤝 Contributing

Contributions are welcome! Please read our Contributing Guide to get started.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

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

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

flext_core-0.12.0.dev0.tar.gz (361.9 kB view details)

Uploaded Source

Built Distribution

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

flext_core-0.12.0.dev0-py3-none-any.whl (402.0 kB view details)

Uploaded Python 3

File details

Details for the file flext_core-0.12.0.dev0.tar.gz.

File metadata

  • Download URL: flext_core-0.12.0.dev0.tar.gz
  • Upload date:
  • Size: 361.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for flext_core-0.12.0.dev0.tar.gz
Algorithm Hash digest
SHA256 090838d6f4ef84027fad93f54cfa9a8d270f69c14148428f427f101b0f8fcc2c
MD5 d145f5200176f20b05ad7b940ec7d56d
BLAKE2b-256 fafe2318cae25afee39547a9ee8b4595aa3479ab25cfcb905ef1415b4026ad84

See more details on using hashes here.

Provenance

The following attestation bundles were made for flext_core-0.12.0.dev0.tar.gz:

Publisher: workflow.yaml on flext-sh/flext-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flext_core-0.12.0.dev0-py3-none-any.whl.

File metadata

File hashes

Hashes for flext_core-0.12.0.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 27c4012f8e1a1aa3587e257a737dfd5fe342e953dc3b7878ba8d4154f9f1034a
MD5 987880a2278440c57650531e0c0d5ff9
BLAKE2b-256 10f2507a1586ffe0dd38fa08085a61ffe3fbb504cab97b3989468a0f7fa59f8e

See more details on using hashes here.

Provenance

The following attestation bundles were made for flext_core-0.12.0.dev0-py3-none-any.whl:

Publisher: workflow.yaml on flext-sh/flext-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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