Configuration¶
Configuration management for LavenderTown using environment variables and .env files.
Overview¶
LavenderTown automatically loads configuration from .env files when the package is imported. Configuration is searched in the following order:
- Current directory (
.env) - Parent directories (up to project root)
- Home directory (
.lavendertown.env)
Functions¶
get_config ¶
Get configuration value from environment variable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Environment variable name to retrieve |
required |
default
|
str | None
|
Default value to return if key is not set |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
Configuration value as string, or default if not set |
Example
Get log level with default::
log_level = get_config("LAVENDERTOWN_LOG_LEVEL", "WARNING")
Source code in lavendertown/config.py
get_config_bool ¶
Get boolean configuration value from environment variable.
Converts common truthy values (1, true, yes, on) to True, everything else to False.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Environment variable name to retrieve |
required |
default
|
bool
|
Default value to return if key is not set |
False
|
Returns:
| Type | Description |
|---|---|
bool
|
Boolean configuration value |
Source code in lavendertown/config.py
get_config_int ¶
Get integer configuration value from environment variable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Environment variable name to retrieve |
required |
default
|
int | None
|
Default value to return if key is not set or invalid |
None
|
Returns:
| Type | Description |
|---|---|
int | None
|
Integer configuration value, or default if not set or invalid |
Source code in lavendertown/config.py
Usage Example¶
from lavendertown.config import get_config, get_config_bool, get_config_int
# Get string configuration
log_level = get_config("LAVENDERTOWN_LOG_LEVEL", "WARNING")
# Get boolean configuration
debug_mode = get_config_bool("LAVENDERTOWN_DEBUG", False)
# Get integer configuration
max_rows = get_config_int("LAVENDERTOWN_MAX_ROWS", 1000000)
Environment Variables¶
Common environment variables:
LAVENDERTOWN_LOG_LEVEL: Logging level (e.g., "INFO", "WARNING", "DEBUG")LAVENDERTOWN_DEBUG: Enable debug mode (boolean)LAVENDERTOWN_OUTPUT_DIR: Default output directory for exports
Configuration is automatically loaded when you import LavenderTown: