One settings module per package
Directive¶
- Each layer or package has its own
settings.py. - It defines a
pydantic_settings.BaseSettingssubclass that is case-insensitive (SettingsConfigDict(case_sensitive=False)). - It exposes a cached
get_settings()and nobody builds the settings class directly. os.getenvandos.environare used only inside a settings module: asettings.pyor a file of asettings/package. Aconfig.pyis not a settings module.- A higher layer imports the settings of the layers below and stacks them as fields of its own.
- In a project with a varlock schema (
.env.schema), the schema declares each variable that a settings class reads, and a settings class reads each variable of the schema. A variable that another program reads carries# @auditIgnorein the schema.
Why¶
Configuration enters the process once, through a typed and validated object, and the settings class of a package lists what the package needs. The schema lists what a deployment sets and validates; when the two lists differ, a variable is read with no validation or set for nothing.
Rules¶
settings-module(BTCONF001)settings-base-class(BTCONF002)settings-direct-instantiation(BTCONF003)settings-env-schema(BTCONF004)