Skip to content

Environment¤

Environment-based configuration loading.

See Also¤


datarax.config.environment ¤

Environment variable integration for configuration.

This module provides utilities for integrating environment variables with configuration files, allowing for environment-specific overrides.

logger module-attribute ¤

logger = getLogger(__name__)

get_env_value ¤

get_env_value(env_var: str, default: Any = None, prefix: str = 'DATARAX_') -> str | None

Get a value from an environment variable.

Parameters:

Name Type Description Default
env_var str

The name of the environment variable (without prefix)

required
default Any

Default value to return if the environment variable is not set

None
prefix str

Prefix to apply to the environment variable name

'DATARAX_'

Returns:

Type Description
str | None

The environment variable value, or the default if not set

apply_environment_overrides ¤

apply_environment_overrides(config: dict[str, Any], prefix: str = 'DATARAX_', separator: str = '__') -> dict[str, Any]

Apply environment variable overrides to a configuration dictionary.

Environment variables can override configuration values using a naming convention. For example, to override config.database.host, the environment variable would be DATARAX_DATABASE__HOST.

Parameters:

Name Type Description Default
config dict[str, Any]

The configuration dictionary to apply overrides to

required
prefix str

Prefix for environment variables to consider

'DATARAX_'
separator str

Separator used to indicate nested keys

'__'

Returns:

Type Description
dict[str, Any]

Configuration dictionary with environment overrides applied