Skip to content

Configuration

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.

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, field
from orionis.foundation.config.app.entities.app import App
from orionis.foundation.config.app.enums.ciphers import Cipher
from orionis.foundation.config.app.enums.environments import Environments
from orionis.services.environment.env import Env
@dataclass(frozen=True, kw_only=True)
class BootstrapApp(App):
# ... configuration properties
  • name (str) — Application display name.

    • Environment variable: APP_NAME
    • Default value: 'Orionis Application'
  • 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 Environments
    Environments.DEVELOPMENT
    Environments.PRODUCTION
    Environments.TESTING
  • debug (bool) — Debug mode.

    • Environment variable: APP_DEBUG
    • Default value: True
  • 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).
  • port (int) — Network port the application listens on.

    • Environment variable: APP_PORT
    • Default value: 8000
  • workers (int) — Number of worker processes for handling concurrent requests.

    • Environment variable: APP_WORKERS
    • Default value: 1

    Orionis Framework provides the Workers class 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 worker
    workers = Workers(ram_per_worker=0.5).calculate()

    If your application is stateful (maintains state in memory), keep workers = 1 or implement a shared cache system (Memcached, Redis). If it is stateless, you can increase workers according to server capacity.

  • 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.
  • 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.
  • locale (str) — Default regional setting.

    • Environment variable: APP_LOCALE
    • Default value: 'en'
  • fallback_locale (str) — Fallback regional setting.

    • Environment variable: APP_FALLBACK_LOCALE
    • Default value: 'en'
    • Used when the primary language is unavailable.
  • 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 Cipher
    Cipher.AES_128_CBC
    Cipher.AES_256_CBC
    Cipher.AES_128_GCM # Authenticated encryption
    Cipher.AES_256_GCM # Authenticated encryption
  • key (str | None) — Application encryption key.

    • Environment variable: APP_KEY
    • Default value: None
  • maintenance (str | bool) — Maintenance mode flag.

    • Environment variable: APP_MAINTENANCE
    • Default value: False

Defines the authentication system configuration. Currently inherits the base structure without additional custom fields:

from dataclasses import dataclass
from orionis.foundation.config.auth.entities.auth import Auth
@dataclass(frozen=True, kw_only=True)
class BootstrapAppAuth(Auth):
pass

This file will be extended with additional fields in future framework versions.

Configures the application’s caching system. By default, it uses file-based storage.

  • default (Drivers | str) — Default cache driver.

    • Environment variable: CACHE_STORE
    • Default value: Drivers.FILE
  • stores (Stores | dict) — Available store configurations.

    • file: File-based caching.
      • path: Storage path. Environment variable: CACHE_FILE_PATH. Default: "storage/framework/cache/data".

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.

  • 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"]
  • allow_origin_regex (str | None) — Regular expression for pattern-based origins.

    • Default value: None
    • Example: r"^https://.*\.myapp\.com$" for dynamic subdomains.
  • allow_methods (list[str]) — HTTP methods allowed in CORS requests.

    • Default value: ["*"]
    • Restrict in production: ["GET", "POST", "PUT", "DELETE"]
  • allow_headers (list[str]) — HTTP headers the client is allowed to send.

    • Default value: ["*"]
  • expose_headers (list[str]) — Headers exposed to the browser in the response.

    • Default value: []
  • allow_credentials (bool) — Allows credentials (cookies, authorization headers) in CORS requests.

    • Default value: False
  • max_age (int | None) — Seconds to cache the preflight (OPTIONS) response.

    • Default value: 600 (10 minutes)

Since lists cannot be used as default values directly in dataclasses, use field with default_factory:

from dataclasses import dataclass, field
from 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"]
)

Defines the application’s database connections. Supports multiple drivers: SQLite, MySQL, PostgreSQL, and Oracle.

  • default (str) — Default database connection.

    • Environment variable: DB_CONNECTION
    • Default value: "sqlite"
  • connections (Connections | dict) — Available connections.

PropertyEnvironment VariableDefault Value
driver"sqlite"
urlDB_URL"sqlite:///database/database.sqlite"
databaseDB_DATABASE"database.sqlite"
prefixDB_PREFIX""
foreign_key_constraintsDB_FOREIGN_KEYSSQLiteForeignKey.OFF
busy_timeoutDB_BUSY_TIMEOUT5000
journal_modeDB_JOURNAL_MODESQLiteJournalMode.DELETE
synchronousDB_SYNCHRONOUSSQLiteSynchronous.NORMAL
PropertyEnvironment VariableDefault Value
driver"mysql"
hostDB_HOST"127.0.0.1"
portDB_PORT3306
databaseDB_DATABASE"orionis"
usernameDB_USERNAME"root"
passwordDB_PASSWORD""
unix_socketDB_SOCKET""
charsetMySQLCharset.UTF8MB4
collationMySQLCollation.UTF8MB4_UNICODE_CI
engineMySQLEngine.INNODB
strictTrue
PropertyEnvironment VariableDefault Value
driver"pgsql"
hostDB_HOST"127.0.0.1"
portDB_PORT5432
databaseDB_DATABASE"orionis"
usernameDB_USERNAME"postgres"
passwordDB_PASSWORD""
charsetDB_CHARSETPGSQLCharset.UTF8
search_path"public"
sslmodePGSQLSSLMode.PREFER
PropertyEnvironment VariableDefault Value
driver"oracle"
hostDB_HOST"localhost"
portDB_PORT1521
usernameDB_USERNAME"sys"
passwordDB_PASSWORD""
service_nameDB_SERVICE_NAME"ORCL"
sidDB_SIDNone
dsnDB_DSNNone
tns_nameDB_TNSNone
encodingDB_ENCODINGOracleEncoding.AL32UTF8
nencodingDB_NENCODINGOracleNencoding.AL32UTF8

Defines the application’s filesystem using a multi-disk pattern, where each disk represents a storage location with its own configuration.

  • default (str) — Default storage disk.

    • Environment variable: FILESYSTEM_DISK
    • Default value: "local"
    • Options: "local", "public", "aws"
  • disks (Disks | dict) — Available disks.

  • path: Storage path. Default: "storage/app/private".
  • path: Storage path. Default: "storage/app/public".
  • url: Base URL for web access. Default: "/static".
PropertyDefault ValueDescription
key""AWS Access Key ID
secret""AWS Secret Access Key
region"us-east-1"Bucket region
bucket""Bucket name
urlNoneCustom URL (CloudFront)
endpointNoneCustom endpoint (MinIO)
use_path_style_endpointFalsePath-style vs subdomain-style
throwFalseThrow exceptions on errors

Configures the logging system with multiple channels representing different storage and rotation strategies.

  • default (str) — Default logging channel.

    • Environment variable: LOG_CHANNEL
    • Default value: "stack"
    • Options: "stack", "hourly", "daily", "weekly", "monthly", "chunked"
  • channels (Channels | dict) — Available channels.

Basic logging without automatic rotation.

PropertyDefault Value
path"storage/logs/stack.log"
levelLevel.INFO
PropertyDefault Value
path"storage/logs/hourly_{suffix}.log"
levelLevel.INFO
retention_hours24
PropertyDefault Value
path"storage/logs/daily_{suffix}.log"
levelLevel.INFO
retention_days7
attime(0, 0) (midnight)
PropertyDefault Value
path"storage/logs/weekly_{suffix}.log"
levelLevel.INFO
retention_weeks4
PropertyDefault Value
path"storage/logs/monthly_{suffix}.log"
levelLevel.INFO
retention_months4
PropertyDefault Value
path"storage/logs/chunked_{suffix}.log"
levelLevel.INFO
mb_size10 MB
files5 files maximum
from orionis.foundation.config.logging.enums.levels import Level
Level.DEBUG # Detailed information for debugging
Level.INFO # General operational information
Level.WARNING # Warnings that do not prevent operation
Level.ERROR # Errors affecting specific functionalities
Level.CRITICAL # Critical errors that may stop the application

Defines the available email transports: SMTP for real delivery and file-based storage for development.

  • default (str) — Default transport.

    • Environment variable: MAIL_MAILER
    • Default value: "smtp"
    • Options: "smtp", "file"
  • mailers (Mailers | dict) — Available transports.

PropertyEnvironment VariableDefault Value
urlMAIL_URL""
hostMAIL_HOST""
portMAIL_PORT587
encryptionMAIL_ENCRYPTION"TLS"
usernameMAIL_USERNAME""
passwordMAIL_PASSWORD""
timeoutNone
  • path: Storage directory. Default: "storage/mail".

Ideal for development and testing — emails are saved as files for inspection without actual delivery.

# Gmail
smtp = Smtp(host="smtp.gmail.com", port=587, encryption="TLS",
username="your_email@gmail.com", password="your_app_password")
# SendGrid
smtp = Smtp(host="smtp.sendgrid.net", port=587, encryption="TLS",
username="apikey", password="your_api_key")
# Outlook
smtp = Smtp(host="smtp-mail.outlook.com", port=587, encryption="TLS",
username="your_email@outlook.com", password="your_password")
# Mailgun
smtp = Smtp(host="smtp.mailgun.org", port=587, encryption="TLS",
username="postmaster@your_domain.mailgun.org", password="your_password")

Configures the application’s job queue system.

  • default (str) — Default queue connection.

    • Environment variable: QUEUE_CONNECTION
    • Default value: "async"
  • brokers (Brokers | dict) — Available brokers.

PropertyDefault ValueDescription
jobs_table"jobs"Jobs table
failed_jobs_table"failed_jobs"Failed jobs table
queue"default"Queue name
visibility_timeout60Seconds before a job becomes visible again
retry_delay90Seconds between retries
max_attempts3Maximum attempts per job
strategyStrategy.FIFOProcessing strategy (First In, First Out)

Configures the application’s HTTP session handling.

PropertyEnvironment VariableDefault ValueDescription
secret_keyAPP_KEYKey for signing session cookies
session_cookieSESSION_COOKIE_NAME"orionis_session"Cookie name
max_ageSESSION_MAX_AGE1800 (30 min)Duration in seconds (None = until browser closes)
same_siteSESSION_SAME_SITESameSitePolicy.LAXSameSite policy: lax, strict, none
pathSESSION_PATH"/"Cookie path
https_onlySESSION_HTTPS_ONLYFalseRestrict to HTTPS
domainSESSION_DOMAINNoneCookie domain

Configures the behavior of the framework’s automated tests.

PropertyDefault ValueDescription
verbosityVerbosityMode.DETAILEDOutput detail level (0: silent, 1: minimal, 2: detailed)
fail_fastFalseStop 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_resultsFalseSave results to a JSON file
from orionis.foundation.config.testing.enums import VerbosityMode
VerbosityMode.SILENT # 0 - No output
VerbosityMode.MINIMAL # 1 - Minimal output
VerbosityMode.DETAILED # 2 - Detailed output

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.

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 Path
from app.console.scheduler import Scheduler
from app.exceptions.handler import ExceptionHandler
from app.providers.app_service_provider import AppServiceProvider
from 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()

During app.create(), the framework executes the following stages:

  1. Configuration loading: Reads files from the config/ directory and merges them with the framework’s default values.
  2. Validation: Verifies that types and values are correct according to the defined dataclasses.
  3. Provider registration: Instantiates and registers all eager providers in the service container.
  4. Configuration lock: The configuration becomes immutable (frozen) after startup.

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.

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.

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:

MethodConfiguration 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

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.


Once the application has been initialized with app.create(), all configurations are available globally.

Use the Application facade with dot notation to access any configuration value:

from orionis.support.facades.application import Application
# Simple values
name = Application.config('app.name')
environment = Application.config('app.env')
debug = Application.config('app.debug')
# Nested values
smtp_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.

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')

To revert all runtime changes and return to the original bootstrapping values:

from orionis.support.facades.application import Application
Application.resetRuntimeConfig()