EnvFileConfigSource#
- pydantic model tollan.config.sources.EnvFileConfigSource[source]#
Configuration source from .env file.
Uses python-dotenv to parse .env files. Supports variable expansion and default values.
Examples
>>> from pathlib import Path >>> from tollan.config.sources import EnvFileConfigSource >>> # Basic usage (requires actual .env file) >>> src = EnvFileConfigSource(order=0, source=Path(".env")) >>> src.format 'envfile'
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.Show JSON schema
{ "title": "EnvFileConfigSource", "description": "Configuration source from .env file.\n\nUses python-dotenv to parse .env files. Supports variable expansion\nand default values.\n\nExamples\n--------\n>>> from pathlib import Path\n>>> from tollan.config.sources import EnvFileConfigSource\n>>> # Basic usage (requires actual .env file)\n>>> src = EnvFileConfigSource(order=0, source=Path(\".env\")) # doctest: +SKIP\n>>> src.format # doctest: +SKIP\n'envfile'", "type": "object", "properties": { "order": { "title": "Order", "type": "integer" }, "name": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Name" }, "enabled": { "default": true, "title": "Enabled", "type": "boolean" }, "enable_if": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Enable If" }, "format": { "const": "envfile", "default": "envfile", "title": "Format", "type": "string" }, "source": { "format": "path", "title": "Source", "type": "string" }, "encoding": { "default": "utf-8", "title": "Encoding", "type": "string" }, "interpolate": { "default": true, "title": "Interpolate", "type": "boolean" } }, "required": [ "order", "source" ] }
- Config:
frozen: bool = True
- Fields:
- Validators:
_validate_name»all fields_validate_source»source
- field format: Literal['envfile'] = 'envfile'#
Format identifier, always ‘envfile’
- Validated by:
_validate_name
- field source: Path [Required]#
Path to .env file
- Validated by:
_validate_name_validate_source
- load(context: dict[str, Any] | None = None) DictConfigT[source]#
Load configuration from .env file.
Uses python-dotenv’s dotenv_values() to parse the file. Returns a dictionary with all key-value pairs from the file.
- Parameters:
context (dict[str, Any] | None, optional) – Context dictionary (unused, for signature compatibility)
- Returns:
Configuration dictionary with string values
- Return type:
- Raises:
ValueError – If source is not enabled for context
FileNotFoundError – If .env file doesn’t exist
Notes
All values are returned as strings (as they appear in the .env file). Type conversion should be handled by the consumer.
Variable expansion is supported if interpolate=True: - ${VAR} expands to the value of VAR - ${VAR:-default} expands to value of VAR or “default” if not set