Skip to content

Settings

py_moodle.settings

Single source of truth for configuration.

Reads environment variables following the pattern MOODLE_<ENV>_URL / USERNAME / PASSWORD and supports environment-specific CAS URLs and predefined webservice tokens.

Classes:

Name Description
Settings

Holds all configuration for a specific Moodle environment.

Functions:

Name Description
load_settings

Load settings for the requested environment.

Classes

Settings dataclass

Settings(
    env_name: str,
    url: str,
    username: str,
    password: str,
    use_cas: bool,
    cas_url: Optional[str],
    webservice_token: Optional[str],
)

Holds all configuration for a specific Moodle environment.

Attributes:

Name Type Description
env_name str
url str
username str
password str
use_cas bool
cas_url Optional[str]
webservice_token Optional[str]

Attributes

env_name instance-attribute
env_name: str
url instance-attribute
url: str
username instance-attribute
username: str
password instance-attribute
password: str
use_cas instance-attribute
use_cas: bool
cas_url instance-attribute
cas_url: Optional[str]
webservice_token instance-attribute
webservice_token: Optional[str]

Functions

load_settings

load_settings(env: Optional[str] = None) -> Settings

Load settings for the requested environment.

Parameters:

Name Type Description Default
env Optional[str]

Environment key ("local", "staging", "prod", etc.). Falls back to the MOODLE_ENV variable if omitted.

None

Returns:

Name Type Description
Settings Settings

Configuration object populated for the selected environment.

Raises:

Type Description
ValueError

If any required core variable (URL, USERNAME, PASSWORD) is missing.