Skip to content

lang_tools.params.webapp

Webapp parameters module.

Modules:

  • webapp_params

    Webapp parameters with environment-aware loading.

Classes:

  • WebappParams

    Webapp parameters loaded from environment variables.

WebappParams

WebappParams(
    stage: EnvStageType | None = None,
    location: EnvLocationType | None = None,
)

Webapp parameters loaded from environment variables.

Load webapp params from environment.

Parameters:

  • stage (EnvStageType | None, default: None ) –

    Environment stage (dev/prod). Loaded from env if None.

  • location (EnvLocationType | None, default: None ) –

    Environment location (local/render). Loaded from env if None.

Methods:

  • __str__

    Return string representation.

  • to_config

    Convert params to WebappConfig.

Source code in src/lang_tools/params/webapp/webapp_params.py
def __init__(
    self,
    stage: EnvStageType | None = None,
    location: EnvLocationType | None = None,
) -> None:
    """Load webapp params from environment.

    Args:
        stage: Environment stage (dev/prod). Loaded from env if None.
        location: Environment location (local/render). Loaded from env if None.
    """
    lg.info("Loading WebappParams")

    self.stage = stage or EnvStageType.from_env_var()
    self.location = location or EnvLocationType.from_env_var()

    self._load_params()

__str__

__str__() -> str

Return string representation.

Source code in src/lang_tools/params/webapp/webapp_params.py
def __str__(self) -> str:
    """Return string representation."""
    s = "WebappParams:"
    s += f"\n  stage: {self.stage.value}"
    s += f"\n  location: {self.location.value}"
    s += f"\n  host: {self.host}"
    s += f"\n  port: {self.port}"
    s += f"\n  debug: {self.debug}"
    s += (
        f"\n  google_client_id: {'[SET]' if self.google_client_id else '[NOT SET]'}"
    )
    return s

to_config

to_config() -> WebappConfig

Convert params to WebappConfig.

Source code in src/lang_tools/params/webapp/webapp_params.py
def to_config(self) -> WebappConfig:
    """Convert params to WebappConfig."""
    return WebappConfig(
        host=self.host,
        port=self.port,
        debug=self.debug,
        app_name=self.app_name,
        app_version=self.app_version,
        public_base_url=self.public_base_url,
        cors=CORSConfig(
            allow_origins=self.cors_allowed_origins,
        ),
        session=SessionConfig(
            secret_key=self.session_secret_key,
            session_cookie_name=self.session_cookie_name,
            max_age=self.session_max_age,
            same_site=self.session_same_site,  # type: ignore[arg-type]
            https_only=self.session_https_only,
        ),
        rate_limit=RateLimitConfig(
            requests_per_minute=self.rate_limit_requests_per_minute,
            burst_size=self.rate_limit_burst_size,
            auth_requests_per_minute=self.rate_limit_auth_requests_per_minute,
        ),
        google_oauth=GoogleOAuthConfig(
            client_id=self.google_client_id,
            client_secret=self.google_client_secret,
            redirect_uri=self.google_redirect_uri,
        ),
    )