Configuration

The configuration of your Expanse application is done through configuration files located in the config directory or through environment variables or a mix of both.

Configuring via files

Default configuration files are present in the config directory of your application. The purpose of each setting is documented and you can add extra settings as you see fit. Note that you can also remove any non-mandatory setting or remove configuration files you don't need.

These configuration files are organized by purpose for your application: application configuration, database configuration, etc.

The settings are represented by Pydantic settings classes which provides validation natively and allows you to use environment variables to configure your application.

Configuring via environment variables

It is often good practice to provide settings to your application through the environment. This makes it more flexible without having to tinker with configuration files. This is especially useful since the requirements of your application might differ between the development environment and the production one: for instance, you might want to use a SQLite database in development and a PostgreSQL one in production.

Most standard settings in Expanse can be configured via environment variables. If you have a .env file at the root of your application, Expanse will automatically load it on application startup.

When setting up your application via the official installer, a .env.example file will be present with examples of settings configuration and will be automatically copied to a .env file which will serve as the default settings.

Accessing the configuration

If you need to retrieve settings for your application, you can either retrieve the configuration from the service container or type-hint the Config class anywhere dependency injection is available.

from expanse.common.configuration.config import Config
from expanse.container.container import Container


def route_endpoint(container: Container, config: Config) -> None:
    # Retrieve config from container
    config2 = container.make(Config)

    assert config == config2

To retrieve a specific setting, you can use the get() method on the Config class:

config = container.make(Config)
value = config.get("app.name")

# You can also give a default value if the setting is not currently set
value = config.get("app.name", "My app")