Skip to content

1.2.1

Compare
Choose a tag to compare
@GilbN GilbN released this 04 Feb 14:39
· 5 commits to main since this release

1.2.1 - 2024-02-04

New Release: v1.2.1 - Set environment variables from configuration.

What's New

Environment variable are now automatically set from the configuration. This makes it easier to use the configuration values in your application.
Env variables of all config keys are set as uppercase. e.g. APP_HOST and APP_PORT or APP_CONFIG_APP_HOST and APP_CONFIG_APP_PORT if env_prefix is set to "app_config".

It will also try and convert the values to the correct type. e.g. APP_PORT will be set as an integer if the env value is 8080

Nested values can also be accessed. ex: TABLE_KEY_LEVEL1_KEY_LEVEL2_KEY. This works for any level of nesting.

Any existing env variables that matches will not be overwritten, but instead will overwrite the existing config value.

import os
from simple_toml_configurator import Configuration

os.environ["PROJECT_APP_PORT"] = "1111"
default = {"app": {"host": "localhost", "port": 8080}}
config = Configuration(
    config_path="config_folder",
    defaults=default,
    config_file_name="app_settings",
    env_prefix="project")

print(os.environ["PROJECT_APP_HOST"])  # Output: 'localhost'
print(os.environ["PROJECT_APP_PORT"])  # Output: '1111'

Fixes

  • Fixed a bug where update_config() would not update the attributes of the Configuration object.