Configuration
Configuration Files
Section titled “Configuration Files”Orionis Framework manages application configuration using frozen dataclasses (frozen=True), centralizing parameters in the config/ directory. These files allow you to define key aspects such as database, email, sessions, CORS, and other essential behaviors.
Each file defines a dataclass that extends a base framework class and uses Env.get() to load values from environment variables, with safe default values as fallback.
app.py
Section titled “app.py”Contains the main application configuration: runtime environment, networking, workers, localization, and encryption.
The configuration is defined using a frozen dataclass that extends the base App class:
from dataclasses import dataclass, fieldfrom orionis.foundation.config.app.entities.app import Appfrom orionis.foundation.config.app.enums.ciphers import Cipherfrom orionis.foundation.config.app.enums.environments import Environmentsfrom orionis.services.environment.env import Env
@dataclass(frozen=True, kw_only=True)class BootstrapApp(App): # ... configuration propertiesProperties
Section titled “Properties”-
name(str) — Application display name.- Environment variable:
APP_NAME - Default value:
'Orionis Application'
- Environment variable:
-
env(str | Environments) — Runtime environment.- Environment variable:
APP_ENV - Default value:
Environments.DEVELOPMENT - Options:
DEVELOPMENT,TESTING,PRODUCTION
from orionis.foundation.config.app.enums.environments import EnvironmentsEnvironments.DEVELOPMENTEnvironments.PRODUCTIONEnvironments.TESTING - Environment variable:
-
debug(bool) — Debug mode.- Environment variable:
APP_DEBUG - Default value:
True
- Environment variable:
-
host(str) — IP address the application listens on.- Environment variable:
APP_HOST - Default value:
'127.0.0.1' - Use
'0.0.0.0'to allow external access (with caution in production).
- Environment variable:
-
port(int) — Network port the application listens on.- Environment variable:
APP_PORT - Default value:
8000
- Environment variable:
-
workers(int) — Number of worker processes for handling concurrent requests.- Environment variable:
APP_WORKERS - Default value:
1
Orionis Framework provides the
Workersclass to automatically calculate the optimal number based on available CPU and RAM:from orionis.services.system.workers import Workers# Automatic calculation based on CPU and RAM (0.5 GB per worker by default)workers = Workers().calculate()# With custom RAM allocation per workerworkers = Workers(ram_per_worker=0.5).calculate()If your application is stateful (maintains state in memory), keep
workers = 1or implement a shared cache system (Memcached, Redis). If it is stateless, you can increase workers according to server capacity. - Environment variable:
-
reload(bool) — Automatic reload when code changes are detected.- Environment variable:
APP_RELOAD - Default value:
True - Only works with
workers = 1. Must be disabled in production.
- Environment variable:
-
timezone(str) — Application time zone.- Environment variable:
APP_TIMEZONE - Default value:
'UTC' - Accepts any valid time zone:
'America/New_York','Europe/Madrid','America/Bogota', etc.
- Environment variable:
-
locale(str) — Default regional setting.- Environment variable:
APP_LOCALE - Default value:
'en'
- Environment variable:
-
fallback_locale(str) — Fallback regional setting.- Environment variable:
APP_FALLBACK_LOCALE - Default value:
'en' - Used when the primary language is unavailable.
- Environment variable:
-
cipher(str | Cipher) — Encryption algorithm for sensitive data.- Environment variable:
APP_CIPHER - Default value:
Cipher.AES_256_CBC
from orionis.foundation.config.app.enums.ciphers import CipherCipher.AES_128_CBCCipher.AES_256_CBCCipher.AES_128_GCM # Authenticated encryptionCipher.AES_256_GCM # Authenticated encryption - Environment variable:
-
key(str | None) — Application encryption key.- Environment variable:
APP_KEY - Default value:
None
- Environment variable:
-
maintenance(str | bool) — Maintenance mode flag.- Environment variable:
APP_MAINTENANCE - Default value:
False
- Environment variable:
auth.py
Section titled “auth.py”Defines the authentication system configuration. Currently inherits the base structure without additional custom fields:
from dataclasses import dataclassfrom orionis.foundation.config.auth.entities.auth import Auth
@dataclass(frozen=True, kw_only=True)class BootstrapAppAuth(Auth): passThis file will be extended with additional fields in future framework versions.
cache.py
Section titled “cache.py”Configures the application’s caching system. By default, it uses file-based storage.
Properties
Section titled “Properties”-
default(Drivers | str) — Default cache driver.- Environment variable:
CACHE_STORE - Default value:
Drivers.FILE
- Environment variable:
-
stores(Stores | dict) — Available store configurations.file: File-based caching.path: Storage path. Environment variable:CACHE_FILE_PATH. Default:"storage/framework/cache/data".
cors.py
Section titled “cors.py”Configures CORS (Cross-Origin Resource Sharing) behavior, controlling which external origins can interact with your API and under what conditions.
When a browser makes a request from a different origin (domain, protocol, or port), the server responds with CORS headers automatically generated from this configuration.
Properties
Section titled “Properties”-
allow_origins(list[str]) — Allowed origins that can access the API.- Default value:
["*"] - Specify concrete domains in production:
["https://myapp.com", "https://admin.myapp.com"]
- Default value:
-
allow_origin_regex(str | None) — Regular expression for pattern-based origins.- Default value:
None - Example:
r"^https://.*\.myapp\.com$"for dynamic subdomains.
- Default value:
-
allow_methods(list[str]) — HTTP methods allowed in CORS requests.- Default value:
["*"] - Restrict in production:
["GET", "POST", "PUT", "DELETE"]
- Default value:
-
allow_headers(list[str]) — HTTP headers the client is allowed to send.- Default value:
["*"]
- Default value:
-
expose_headers(list[str]) — Headers exposed to the browser in the response.- Default value:
[]
- Default value:
-
allow_credentials(bool) — Allows credentials (cookies, authorization headers) in CORS requests.- Default value:
False
- Default value:
-
max_age(int | None) — Seconds to cache the preflight (OPTIONS) response.- Default value:
600(10 minutes)
- Default value:
Since lists cannot be used as default values directly in dataclasses, use field with default_factory:
from dataclasses import dataclass, fieldfrom orionis.foundation.config.cors.entities.cors import Cors
@dataclass(frozen=True, kw_only=True)class BootstrapCors(Cors): allow_origins: list[str] = field( default_factory=lambda: ["https://myapp.com", "https://admin.myapp.com"] )database.py
Section titled “database.py”Defines the application’s database connections. Supports multiple drivers: SQLite, MySQL, PostgreSQL, and Oracle.
Properties
Section titled “Properties”-
default(str) — Default database connection.- Environment variable:
DB_CONNECTION - Default value:
"sqlite"
- Environment variable:
-
connections(Connections | dict) — Available connections.
SQLite
Section titled “SQLite”| Property | Environment Variable | Default Value |
|---|---|---|
driver | — | "sqlite" |
url | DB_URL | "sqlite:///database/database.sqlite" |
database | DB_DATABASE | "database.sqlite" |
prefix | DB_PREFIX | "" |
foreign_key_constraints | DB_FOREIGN_KEYS | SQLiteForeignKey.OFF |
busy_timeout | DB_BUSY_TIMEOUT | 5000 |
journal_mode | DB_JOURNAL_MODE | SQLiteJournalMode.DELETE |
synchronous | DB_SYNCHRONOUS | SQLiteSynchronous.NORMAL |
| Property | Environment Variable | Default Value |
|---|---|---|
driver | — | "mysql" |
host | DB_HOST | "127.0.0.1" |
port | DB_PORT | 3306 |
database | DB_DATABASE | "orionis" |
username | DB_USERNAME | "root" |
password | DB_PASSWORD | "" |
unix_socket | DB_SOCKET | "" |
charset | — | MySQLCharset.UTF8MB4 |
collation | — | MySQLCollation.UTF8MB4_UNICODE_CI |
engine | — | MySQLEngine.INNODB |
strict | — | True |
PostgreSQL
Section titled “PostgreSQL”| Property | Environment Variable | Default Value |
|---|---|---|
driver | — | "pgsql" |
host | DB_HOST | "127.0.0.1" |
port | DB_PORT | 5432 |
database | DB_DATABASE | "orionis" |
username | DB_USERNAME | "postgres" |
password | DB_PASSWORD | "" |
charset | DB_CHARSET | PGSQLCharset.UTF8 |
search_path | — | "public" |
sslmode | — | PGSQLSSLMode.PREFER |
Oracle
Section titled “Oracle”| Property | Environment Variable | Default Value |
|---|---|---|
driver | — | "oracle" |
host | DB_HOST | "localhost" |
port | DB_PORT | 1521 |
username | DB_USERNAME | "sys" |
password | DB_PASSWORD | "" |
service_name | DB_SERVICE_NAME | "ORCL" |
sid | DB_SID | None |
dsn | DB_DSN | None |
tns_name | DB_TNS | None |
encoding | DB_ENCODING | OracleEncoding.AL32UTF8 |
nencoding | DB_NENCODING | OracleNencoding.AL32UTF8 |
filesystems.py
Section titled “filesystems.py”Defines the application’s filesystem using a multi-disk pattern, where each disk represents a storage location with its own configuration.
Properties
Section titled “Properties”-
default(str) — Default storage disk.- Environment variable:
FILESYSTEM_DISK - Default value:
"local" - Options:
"local","public","aws"
- Environment variable:
-
disks(Disks | dict) — Available disks.
local Disk — Private Storage
Section titled “local Disk — Private Storage”path: Storage path. Default:"storage/app/private".
public Disk — Public Storage
Section titled “public Disk — Public Storage”path: Storage path. Default:"storage/app/public".url: Base URL for web access. Default:"/static".
aws Disk — Amazon S3
Section titled “aws Disk — Amazon S3”| Property | Default Value | Description |
|---|---|---|
key | "" | AWS Access Key ID |
secret | "" | AWS Secret Access Key |
region | "us-east-1" | Bucket region |
bucket | "" | Bucket name |
url | None | Custom URL (CloudFront) |
endpoint | None | Custom endpoint (MinIO) |
use_path_style_endpoint | False | Path-style vs subdomain-style |
throw | False | Throw exceptions on errors |
logging.py
Section titled “logging.py”Configures the logging system with multiple channels representing different storage and rotation strategies.
Properties
Section titled “Properties”-
default(str) — Default logging channel.- Environment variable:
LOG_CHANNEL - Default value:
"stack" - Options:
"stack","hourly","daily","weekly","monthly","chunked"
- Environment variable:
-
channels(Channels | dict) — Available channels.
stack Channel — Cumulative Logging
Section titled “stack Channel — Cumulative Logging”Basic logging without automatic rotation.
| Property | Default Value |
|---|---|
path | "storage/logs/stack.log" |
level | Level.INFO |
hourly Channel — Hourly Rotation
Section titled “hourly Channel — Hourly Rotation”| Property | Default Value |
|---|---|
path | "storage/logs/hourly_{suffix}.log" |
level | Level.INFO |
retention_hours | 24 |
daily Channel — Daily Rotation
Section titled “daily Channel — Daily Rotation”| Property | Default Value |
|---|---|
path | "storage/logs/daily_{suffix}.log" |
level | Level.INFO |
retention_days | 7 |
at | time(0, 0) (midnight) |
weekly Channel — Weekly Rotation
Section titled “weekly Channel — Weekly Rotation”| Property | Default Value |
|---|---|
path | "storage/logs/weekly_{suffix}.log" |
level | Level.INFO |
retention_weeks | 4 |
monthly Channel — Monthly Rotation
Section titled “monthly Channel — Monthly Rotation”| Property | Default Value |
|---|---|
path | "storage/logs/monthly_{suffix}.log" |
level | Level.INFO |
retention_months | 4 |
chunked Channel — Size-Based Rotation
Section titled “chunked Channel — Size-Based Rotation”| Property | Default Value |
|---|---|
path | "storage/logs/chunked_{suffix}.log" |
level | Level.INFO |
mb_size | 10 MB |
files | 5 files maximum |
Logging Levels
Section titled “Logging Levels”from orionis.foundation.config.logging.enums.levels import Level
Level.DEBUG # Detailed information for debuggingLevel.INFO # General operational informationLevel.WARNING # Warnings that do not prevent operationLevel.ERROR # Errors affecting specific functionalitiesLevel.CRITICAL # Critical errors that may stop the applicationmail.py
Section titled “mail.py”Defines the available email transports: SMTP for real delivery and file-based storage for development.
Properties
Section titled “Properties”-
default(str) — Default transport.- Environment variable:
MAIL_MAILER - Default value:
"smtp" - Options:
"smtp","file"
- Environment variable:
-
mailers(Mailers | dict) — Available transports.
smtp Transport
Section titled “smtp Transport”| Property | Environment Variable | Default Value |
|---|---|---|
url | MAIL_URL | "" |
host | MAIL_HOST | "" |
port | MAIL_PORT | 587 |
encryption | MAIL_ENCRYPTION | "TLS" |
username | MAIL_USERNAME | "" |
password | MAIL_PASSWORD | "" |
timeout | — | None |
file Transport
Section titled “file Transport”path: Storage directory. Default:"storage/mail".
Ideal for development and testing — emails are saved as files for inspection without actual delivery.
Common SMTP Providers
Section titled “Common SMTP Providers”# Gmailsmtp = Smtp(host="smtp.gmail.com", port=587, encryption="TLS", username="your_email@gmail.com", password="your_app_password")
# SendGridsmtp = Smtp(host="smtp.sendgrid.net", port=587, encryption="TLS", username="apikey", password="your_api_key")
# Outlooksmtp = Smtp(host="smtp-mail.outlook.com", port=587, encryption="TLS", username="your_email@outlook.com", password="your_password")
# Mailgunsmtp = Smtp(host="smtp.mailgun.org", port=587, encryption="TLS", username="postmaster@your_domain.mailgun.org", password="your_password")queue.py
Section titled “queue.py”Configures the application’s job queue system.
Properties
Section titled “Properties”-
default(str) — Default queue connection.- Environment variable:
QUEUE_CONNECTION - Default value:
"async"
- Environment variable:
-
brokers(Brokers | dict) — Available brokers.
database Broker
Section titled “database Broker”| Property | Default Value | Description |
|---|---|---|
jobs_table | "jobs" | Jobs table |
failed_jobs_table | "failed_jobs" | Failed jobs table |
queue | "default" | Queue name |
visibility_timeout | 60 | Seconds before a job becomes visible again |
retry_delay | 90 | Seconds between retries |
max_attempts | 3 | Maximum attempts per job |
strategy | Strategy.FIFO | Processing strategy (First In, First Out) |
session.py
Section titled “session.py”Configures the application’s HTTP session handling.
Properties
Section titled “Properties”| Property | Environment Variable | Default Value | Description |
|---|---|---|---|
secret_key | APP_KEY | — | Key for signing session cookies |
session_cookie | SESSION_COOKIE_NAME | "orionis_session" | Cookie name |
max_age | SESSION_MAX_AGE | 1800 (30 min) | Duration in seconds (None = until browser closes) |
same_site | SESSION_SAME_SITE | SameSitePolicy.LAX | SameSite policy: lax, strict, none |
path | SESSION_PATH | "/" | Cookie path |
https_only | SESSION_HTTPS_ONLY | False | Restrict to HTTPS |
domain | SESSION_DOMAIN | None | Cookie domain |
testing.py
Section titled “testing.py”Configures the behavior of the framework’s automated tests.
Properties
Section titled “Properties”| Property | Default Value | Description |
|---|---|---|
verbosity | VerbosityMode.DETAILED | Output detail level (0: silent, 1: minimal, 2: detailed) |
fail_fast | False | Stop execution after the first failure |
start_dir | "tests" | Root test directory |
file_pattern | "test_*.py" | Test file pattern |
method_pattern | "test*" | Test method pattern |
cache_results | False | Save results to a JSON file |
from orionis.foundation.config.testing.enums import VerbosityMode
VerbosityMode.SILENT # 0 - No outputVerbosityMode.MINIMAL # 1 - Minimal outputVerbosityMode.DETAILED # 2 - Detailed outputBootstrapping
Section titled “Bootstrapping”The bootstrapping process is responsible for initializing the application, loading configurations, and preparing all services. This process ensures that parameters are available and validated before any component starts operating.
Bootstrapping File
Section titled “Bootstrapping File”The bootstrap/app.py file is the central initialization point. It creates the Application instance, registers configurations, routes, service providers, and executes the startup:
from pathlib import Pathfrom app.console.scheduler import Schedulerfrom app.exceptions.handler import ExceptionHandlerfrom app.providers.app_service_provider import AppServiceProviderfrom orionis.foundation.application import Application
app = Application( base_path=Path(__file__).parent.parent, compiled=True, compiled_path="storage/framework/bootstrap", compiled_invalidation_paths=[ "app", "bootstrap", "config", "resources", "routes", ".env" ],)
app.withRouting( console="routes/console.py", web="routes/web.py", api="routes/api.py", health="/up",)
app.withScheduler(Scheduler)app.withExceptionHandler(ExceptionHandler)
app.withProviders( AppServiceProvider,)
app.create()Startup Process
Section titled “Startup Process”During app.create(), the framework executes the following stages:
- Configuration loading: Reads files from the
config/directory and merges them with the framework’s default values. - Validation: Verifies that types and values are correct according to the defined dataclasses.
- Provider registration: Instantiates and registers all eager providers in the service container.
- Configuration lock: The configuration becomes immutable (frozen) after startup.
Configuration Compilation
Section titled “Configuration Compilation”The compiled=True parameter enables configuration caching in the directory specified by compiled_path. The paths listed in compiled_invalidation_paths are monitored to automatically invalidate the cache when changes are detected.
This speeds up startup in production by avoiding configuration file reloads on each start.
Default Values and Fallback
Section titled “Default Values and Fallback”Orionis follows the principle of “works out of the box”:
- Every configuration includes safe default values for development.
- If a configuration is not customized, the framework’s defaults are used.
- It is possible to run an application without modifying any file in the
config/directory.
Custom Configuration
Section titled “Custom Configuration”Using withConfig Methods
Section titled “Using withConfig Methods”In addition to customizing files in config/, you can override configurations directly in bootstrap/app.py using the withConfig* methods on the Application instance. Each method accepts keyword arguments matching the fields of the corresponding dataclass:
app.withConfigApp( name='My Application', env='production', debug=False, workers=4,)
app.withConfigCors( allow_origins=["https://myapp.com"], allow_credentials=True,)
app.withConfigDatabase( default="pgsql",)The available methods are:
| Method | Configuration File |
|---|---|
withConfigApp() | config/app.py |
withConfigAuth() | config/auth.py |
withConfigCache() | config/cache.py |
withConfigCors() | config/cors.py |
withConfigDatabase() | config/database.py |
withConfigFilesystems() | config/filesystems.py |
withConfigLogging() | config/logging.py |
withConfigMail() | config/mail.py |
withConfigQueue() | config/queue.py |
withConfigSession() | config/session.py |
withConfigTesting() | config/testing.py |
withConfigPaths() | Application directory paths |
Directory Path Configuration
Section titled “Directory Path Configuration”The withConfigPaths() method allows you to customize the application’s directory paths. The available keys correspond to the project’s main directories:
app.withConfigPaths( app="app", console="app/console", exceptions="app/exceptions", http="app/http", models="app/models", providers="app/providers", notifications="app/notifications", services="app/services", jobs="app/jobs", bootstrap="app/bootstrap", config="config", database="database/database", resources="resources", routes="routes", storage="storage", tests="tests",)Paths are resolved relative to the application’s base_path.
Runtime Access
Section titled “Runtime Access”Once the application has been initialized with app.create(), all configurations are available globally.
Reading Configurations
Section titled “Reading Configurations”Use the Application facade with dot notation to access any configuration value:
from orionis.support.facades.application import Application
# Simple valuesname = Application.config('app.name')environment = Application.config('app.env')debug = Application.config('app.debug')
# Nested valuessmtp_host = Application.config('mail.mailers.smtp.host')smtp_port = Application.config('mail.mailers.smtp.port')cache_driver = Application.config('cache.default')
# Full configuration (no key)all_config = Application.config()If the key does not exist, the method returns None.
Modifying Configurations
Section titled “Modifying Configurations”You can alter configurations at runtime by providing the key and the new value:
from orionis.support.facades.application import Application
Application.config('app.debug', False)Application.config('cache.default', 'file')Restoring Configurations
Section titled “Restoring Configurations”To revert all runtime changes and return to the original bootstrapping values:
from orionis.support.facades.application import Application
Application.resetRuntimeConfig()