The Configuration class¶
Each call of the get_configuration() function returns a Configuration object.
gamslib.projectconfiguration.configuration.Configuration
¶
Bases: BaseModel
Represents the complete configuration for a GAMS project.
This class aggregates configuration data from multiple sources:
project.tomlfile (base configuration).envfile (overrides TOML values)- Environment variables (override both
.envand TOML)
| ATTRIBUTE | DESCRIPTION |
|---|---|
toml_file |
Path to the loaded TOML configuration file.
TYPE:
|
metadata |
Project metadata section.
TYPE:
|
general |
General project settings.
TYPE:
|
Configuration values are loaded and overridden in the following order:
- Values from
project.toml. - Values from
.env(fields in the formatmetadata.fieldorgeneral.field). - Values from environment variables prefixed with
GAMSCFG_(e.g.,GAMSCFG_METADATA_PUBLISHER).
Example usage:
config = Configuration.from_toml(Path("project.toml"))
print(config.metadata.publisher)
print(config.general.loglevel)
from_toml
classmethod
¶
Load configuration from a TOML file and return a Configuration object.
Reads the specified TOML file, validates its structure, and constructs a
Configuration instance.
Automatically sets the toml_file attribute and applies overrides from .env
and environment variables.
| PARAMETER | DESCRIPTION |
|---|---|
toml_file
|
Path to the TOML configuration file.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Configuration
|
The loaded and validated configuration object.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If the TOML file does not exist. |
TOMLDecodeError
|
If the TOML file cannot be parsed. |
ValueError
|
If validation fails for required fields or types. |