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.Protocolinterfaces, not rigid inheritanceZero 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ΒΆ
Configuration - Multi-layer config with dot-notation
Authentication - JWT, RBAC, password hashing
Database - Connection pooling, transactions, health checks
π PluginsΒΆ
Dynaconf Plugin - Advanced configuration engine (Type-safe, Multi-source)
Observability Plugin - Structured logging & Prometheus metrics
Auth Plugin - Production-ready authentication
Database Plugin - SQLAlchemy integration
Bootstrap Plugin - Startup validation & health checks
DI Plugin - Dependency injection for FastAPI
π 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:
Runtime β
config.set()modificationsEnvironment β
MYAPP_DATABASE__HOSTvariablesSecrets β
config/.secrets.toml(git-ignored)Application β
config/app/*.toml(versioned)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)
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)
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)
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ΒΆ
β Read Configuration Guide
β Explore Demo Applications
β Review Module Documentation
Existing ProjectsΒΆ
β Read Enterprise Architecture Guide
β Plan migration strategy (incremental adoption)
β Start with configuration subsystem
ContributorsΒΆ
β Read Contributing Guidelines
β Review AI Development Guide
β Check ROADMAP.md for planned features
Support & CommunityΒΆ
Documentation: https://structum-lab.readthedocs.io
Issues: GitHub Issues
Discussions: GitHub Discussions
Changelog: CHANGELOG.md
LicenseΒΆ
Distributed under the Apache 2.0 License.
Copyright Β© 2025 PythonWoods.
See LICENSE for details.