Structum Lab - Framework DocumentationΒΆ

Framework Version: 0.1.0 (Alpha) Documentation Status: Alpha License: Apache 2.0 Copyright: Β© 2025 PythonWoods

[!NOTE] Nota sul Versionamento: Attualmente il progetto Γ¨ in fase Alpha. Tutti i pacchetti (Core e Plugin) seguono il versionamento sincronizzato (β€œLockstep”) del framework principale (structum-lab). In futuro, i plugin adotteranno un versionamento semantico indipendente.


OverviewΒΆ

Structum (lat. struttura): A solid, invisible, and modular foundation for modern Python applications.

Structum Lab is not another web framework, CLI tool, or ORM. It’s a foundational framework designed to manage application lifecycle, configuration, observability, and plugin ecosystemsβ€”leaving you free to choose your preferred technologies for the final implementation.

PhilosophyΒΆ

  • Protocol-First Architecture: Built on typing.Protocol interfaces, not rigid inheritance

  • Zero Core Dependencies: Core uses only Python Standard Library

  • Enterprise-Ready: Production features (health checks, metrics, graceful shutdown) from day one

  • Modular by Design: Install only what you need via independent packages


Quick NavigationΒΆ

πŸš€ Getting StartedΒΆ

πŸ“¦ Core ModulesΒΆ

πŸ”Œ PluginsΒΆ

πŸ“– GuidesΒΆ


InstallationΒΆ

Core FrameworkΒΆ

# Install core framework (minimal dependencies)
pip install -e packages/core

With PluginsΒΆ

# Configuration engine
pip install -e packages/dynaconf

# Observability stack  
pip install -e packages/observability

# Authentication
pip install -e packages/auth

# Database support
pip install -e packages/database

# Dependency injection
pip install -e packages/di

# Bootstrap validation
pip install -e packages/bootstrap

Development EnvironmentΒΆ

# Clone repository
git clone https://github.com/pythinwoods/structum-lab.git
cd structum-lab

# Install all packages in development mode
pip install -e packages/core
pip install -e packages/dynaconf
pip install -e packages/observability
pip install -e packages/auth
pip install -e packages/database
pip install -e packages/di
pip install -e packages/bootstrap

# Install development tools
pip install -e "packages/core[dev]"

Quick StartΒΆ

1. Minimal Example (Core Only)ΒΆ

The configuration system works out-of-the-box without any setup:

from structum_lab.config import get_config

# Get the singleton instance
config = get_config()

# Write configuration (automatically persisted)
config.set("server.host", "0.0.0.0")
config.set("server.port", 8080)

# Read configuration (with safe defaults)
host = config.get("server.host", default="localhost")
port = config.get("server.port", default=8000)

print(f"Server starting on {host}:{port}")

Output:

Server starting on 0.0.0.0:8080

2. Production Example (With Plugins)ΒΆ

Full-featured application with type-safe configuration and observability:

from structum_lab.config import set_config_provider, get_config
from structum_lab.plugins.dynaconf import DynaconfConfigProvider
from structum_lab.plugins.observability import setup_logging, get_logger
from structum_lab.plugins.bootstrap import SystemBootstrapper, EnvValidator

def setup_application():
    """
    Initialize Structum with production features.
    Called once at application startup.
    """
    # 1. Validation: Ensure environment is ready
    boot = SystemBootstrapper()
    boot.add_validator(EnvValidator(required=["APP_ENV", "DB_URL"]))
    boot.run_or_exit()  # Fails fast if environment invalid
    
    # 2. Configuration: Load multi-layer config with validation
    provider = DynaconfConfigProvider(
        root_path=".",
        env_prefix="MYAPP",
        current_env=os.getenv("APP_ENV", "development")
    )
    provider.auto_discover()  # Scans config/app/*.toml
    set_config_provider(provider)
    
    # 3. Observability: Setup structured logging
    setup_logging()
    
    logger = get_logger(__name__)
    logger.info("Application initialized", env=provider.current_env)

def main():
    setup_application()
    
    # Your application code
    config = get_config()
    db_url = config.get("database.url")
    
    logger = get_logger(__name__)
    logger.info("Connecting to database", url=db_url)
    
    # ... rest of your application

if __name__ == "__main__":
    main()

Project StructureΒΆ

Structum Lab uses a monorepo architecture with independent packages:

structum-lab/
β”œβ”€β”€ packages/                          # Monorepo packages
β”‚   β”œβ”€β”€ core/src/structum_lab/        # Core framework (protocols & base)
β”‚   β”œβ”€β”€ dynaconf/src/structum_lab/    # Configuration engine
β”‚   β”œβ”€β”€ observability/src/structum_lab/ # Logging & metrics
β”‚   β”œβ”€β”€ auth/src/structum_lab/        # Authentication
β”‚   β”œβ”€β”€ database/src/structum_lab/    # Database interfaces
β”‚   β”œβ”€β”€ di/src/structum_lab/          # Dependency injection
β”‚   └── bootstrap/src/structum_lab/   # Startup validation
β”‚
β”œβ”€β”€ demo/                              # Example applications
β”‚   β”œβ”€β”€ 01-logging-basics/
β”‚   β”œβ”€β”€ 02-observability-full/
β”‚   β”œβ”€β”€ 03-zero-config/
β”‚   β”œβ”€β”€ 04-web-integration/
β”‚   └── 10-di-fastapi/
β”‚
β”œβ”€β”€ docs/                              # Documentation (you are here)
β”‚   β”œβ”€β”€ modules/                       # Core module documentation
β”‚   β”œβ”€β”€ plugins/                       # Plugin documentation
β”‚   └── guides/                        # Tutorial guides
β”‚
└── pyproject.toml                     # Root monorepo configuration

Architecture OverviewΒΆ

Protocol-Based DesignΒΆ

Structum separates interfaces (protocols) from implementations (plugins):

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Application Code                      β”‚
β”‚   Uses: get_config(), get_logger()      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Core Protocols (packages/core)        β”‚
β”‚   β€’ ConfigProviderInterface             β”‚
β”‚   β€’ LoggerInterface                     β”‚
β”‚   β€’ AuthInterface                       β”‚
β”‚   β€’ DatabaseInterface                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Plugin Implementations                β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚   β”‚ Dynaconf β”‚Observableβ”‚ Auth     β”‚   β”‚
β”‚   β”‚ Provider β”‚ Logger   β”‚ Provider β”‚   β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Benefits:

  • Testability: Mock providers without changing application code

  • Flexibility: Switch implementations (JSON β†’ Dynaconf β†’ Vault) without refactoring

  • Type Safety: Full static type checking with mypy strict mode


Core FeaturesΒΆ

1. Configuration ManagementΒΆ

Multi-layer resolution with precedence:

  1. Runtime β†’ config.set() modifications

  2. Environment β†’ MYAPP_DATABASE__HOST variables

  3. Secrets β†’ config/.secrets.toml (git-ignored)

  4. Application β†’ config/app/*.toml (versioned)

  5. Defaults β†’ Hard-coded fallbacks

Example:

# Layer 4: Application default
# config/app/database.toml
[default]
host = "localhost"

# Layer 2: Environment override
export MYAPP_DATABASE__HOST=prod.db.com

# Result:
config.get("database.host")  # "prod.db.com" (ENV wins)

Read more β†’

2. ObservabilityΒΆ

Structured logging with automatic context propagation:

from structum_lab.plugins.observability import get_logger

logger = get_logger(__name__)
logger.info("User login", user_id=123, ip="10.0.0.1")

# Output (JSON):
# {"timestamp": "2025-01-12T10:00:00Z", "level": "INFO", 
#  "message": "User login", "user_id": 123, "ip": "10.0.0.1"}

Prometheus metrics with automatic collection:

from structum_lab.plugins.observability import get_metrics

metrics = get_metrics("myapp.api")
metrics.increment("requests.total", tags={"endpoint": "/users"})
metrics.timing("request.duration", 0.250)

Read more β†’

3. AuthenticationΒΆ

Production-ready JWT authentication with Argon2 password hashing:

from structum_lab.plugins.auth import JWTAuthProvider

auth = JWTAuthProvider.from_config()
tokens = auth.authenticate("username", "password", user_repo)

if tokens:
    access_token = tokens.access_token    # Short-lived (15min)
    refresh_token = tokens.refresh_token  # Long-lived (7 days)

Read more β†’


Why Structum?ΒΆ

vs. Django/FlaskΒΆ

Django/Flask are opinionated web frameworks. Structum is a foundation layer:

Feature

Django/Flask

Structum

Scope

Web-only

Any Python app (CLI, API, workers)

Dependencies

Heavy

Minimal (stdlib only for core)

Configuration

Settings modules

Multi-layer with validation

Observability

Bring your own

Built-in (structured logs + metrics)

Type Safety

Limited

Full mypy strict support

Use Structum + FastAPI for a modern, type-safe web stack.

vs. Pydantic SettingsΒΆ

Pydantic Settings handles config loading. Structum provides the complete foundation:

  • βœ… Configuration (Pydantic + multi-layer)

  • βœ… Logging (structured + context)

  • βœ… Metrics (Prometheus)

  • βœ… Authentication (JWT + Argon2)

  • βœ… Database (interfaces + pooling)

  • βœ… Bootstrap validation

  • βœ… Plugin system


Next StepsΒΆ

New UsersΒΆ

  1. βœ… Read Configuration Guide

  2. βœ… Explore Demo Applications

  3. βœ… Review Module Documentation

Existing ProjectsΒΆ

  1. βœ… Read Enterprise Architecture Guide

  2. βœ… Plan migration strategy (incremental adoption)

  3. βœ… Start with configuration subsystem

ContributorsΒΆ

  1. βœ… Read Contributing Guidelines

  2. βœ… Review AI Development Guide

  3. βœ… Check ROADMAP.md for planned features


Support & CommunityΒΆ


LicenseΒΆ

Distributed under the Apache 2.0 License.
Copyright Β© 2025 PythonWoods.

See LICENSE for details.