lang_tools.params.sample_params
¶
Sample params - canonical reference implementation of the Params pattern.
This module is the authoritative example of how to write a Params class
in this project. It pairs with SampleConfig in
src/lang_tools/config/sample_config.py.
Config / Params split:
- Config (
src/lang_tools/config/) defines only the shape of settings using Pydantic models. It never reads environment variables. - Params (this file) loads actual values and constructs the config
model via
to_config().
Pattern rules:
-
__init__acceptsenv_type: EnvType | None = Noneas its only argument beyondself. Pass it explicitly when you have it; it will be inferred from environment variables whenNone. Keeping the argument present - even when not yet needed - makes the API consistent and future-proof across all Params classes. -
__init__does nothing except storeenv_typeand call_load_params(). Keep it as a one-liner delegation so the loading logic is easy to test in isolation. -
_load_params()orchestrates loading in a fixed order:
a. _load_common_params() - attributes shared across all envs.
b. Dispatch on env_type.stage (DEV / PROD) via match; each
branch sets or overrides stage-specific attributes and then
dispatches further on env_type.location (LOCAL / RENDER).
-
_load_common_params()writes values as Python literals, notos.getenv()calls. If a value is the same in every environment, write it once here. If it changes between environments, set it only in the relevant stage or location method - never duplicate it. -
Secrets are the exception to the no-env-var rule: load them from environment variables using the module-level
_load_secret()helper. It usesos.environ[VAR], which raisesKeyErrornaturally when the variable is missing - no custom exception is needed. This surfaces broken configurations at startup rather than at the point of use. -
to_config()constructs and returns the Pydantic config model. -
__str__produces a human-readable summary. Every secret field must be rendered as[REDACTED]- never call.get_secret_value()inside__str__.
See Also
SampleConfig - the paired config model in src/lang_tools/config/.
docs/guides/params_config.md - full guide with rationale.
Classes:
-
SampleParams–Sample params - reference implementation of the Params pattern.
SampleParams
¶
Sample params - reference implementation of the Params pattern.
Loads actual runtime values for the given deployment environment and
exposes a typed SampleConfig via to_config().
Non-secret values are written as Python literals inside the appropriate loading method - not read from environment variables. If a value differs between environments, write it only in the relevant stage or location method; do not repeat it across branches.
Secrets are the exception: they are loaded via _load_secret() in
_load_common_params(), which means a missing secret is caught at
startup.
Parameters:
-
env_type(EnvType | None, default:None) –Deployment environment (stage + location). If
None, inferred fromENV_STAGE_TYPEandENV_LOCATION_TYPEenvironment variables (defaults:dev/local).
Load sample params for the given environment.
Parameters:
-
env_type(EnvType | None, default:None) –Deployment environment (stage + location). If
None, inferred fromENV_STAGE_TYPEandENV_LOCATION_TYPEenvironment variables.
Methods:
-
__repr__–Return the string representation of the object.
-
__str__–Return a human-readable summary with secrets masked.
-
to_config–Assemble and return the typed config model.
Source code in src/lang_tools/params/sample_params.py
__repr__
¶
__str__
¶
Return a human-readable summary with secrets masked.
Source code in src/lang_tools/params/sample_params.py
to_config
¶
Assemble and return the typed config model.
Returns:
-
SampleConfig(SampleConfig) –A Pydantic model carrying all settings. The secret is preserved as
SecretStr.