Configuration
austial.config provides a ConfigModule.for_root() dynamic module that
loads a .env file and exposes its values (plus the rest of the process
environment) through an injectable ConfigService.
Setup
from austial import Module
from austial.config import ConfigModule
@Module(imports=[ConfigModule.for_root()])
class AppModule:
passConfigModule.for_root(env_file=".env", is_global=True):
- loads
env_fileviapython-dotenv’sload_dotenv(env_file, override=False)(a missing file or missingpython-dotenvis a no-op, not an error), - builds one
ConfigServicesnapshottingos.environ, - is registered
@Global()by default (is_global=True), so you don’t need to re-importConfigModulein every feature module that wantsConfigService.
Using ConfigService
from austial import Injectable
from austial.config import ConfigService
@Injectable()
class ApiKeyGuard:
def __init__(self, config: ConfigService):
self._expected = config.get("API_KEY", "changeme")class ConfigService:
def get(self, key: str, default: Any = None) -> Any: ...
def get_or_throw(self, key: str) -> Any: ... # raises KeyError if the key is missingUse get_or_throw for configuration that has no sane default (a secret
key, an external API URL) so a missing value fails fast at
startup-adjacent code rather than silently falling through as None.
.env files
A scaffolded project ships a .env.example — copy it to .env before
running:
cp .env.example .envPORT=8000
API_KEY=changeme.env is git-ignored by default; .env.example is the checked-in template
documenting which variables a deployment needs to set.
Last updated on