Skip to content

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.toml file (base configuration)
  • .env file (overrides TOML values)
  • Environment variables (override both .env and TOML)
ATTRIBUTE DESCRIPTION
toml_file

Path to the loaded TOML configuration file.

TYPE: Path

metadata

Project metadata section.

TYPE: Metadata

general

General project settings.

TYPE: General

Configuration values are loaded and overridden in the following order:

  1. Values from project.toml.
  2. Values from .env (fields in the format metadata.field or general.field).
  3. 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)

toml_file instance-attribute

toml_file

metadata instance-attribute

metadata

general instance-attribute

general

model_post_init

model_post_init(context)

from_toml classmethod

from_toml(toml_file)

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: Path

RETURNS DESCRIPTION
Configuration

The loaded and validated configuration object.

TYPE: Configuration

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.