Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Small repository that contains experiments around settings management in python

Notifications You must be signed in to change notification settings

MadJlzz/experimental-python-settings-management

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

experimental-python-settings-management

Small repository that contains experiments around settings management in python.

Features

Loading settings from a file. Configuration is defined in config.py and loaded in any other Python module you wish by simply importing settings from config.

settings is a Dynaconf object but act as a normal Python dictionary.

from dynaconf import Dynaconf

settings = Dynaconf(
    settings_files=["settings.yaml"], # load all files in this list
    folder="config", # defines the folder from where to load the files
    core_loaders=["yaml"], # defines the loader to use for the files ; Dynaconf support a lot of loaders
    envvar_prefix="MYAPP_", # defines the prefix for the environment variables loaded
    load_dotenv=True, # load the .env file
    merge_enabled=True # merge all the loaded settings together
)

Dynamic variables in settings files.

postgresql:
  user: postgres
  # password will be loaded from an environment variable called MYAPP_POSTGRES_PASSWORD
  # usually, you inject those at deployment time
  password: "@format {env[MYAPP_POSTGRES_PASSWORD]}"
  host: localhost
  port: 5432
  # database variable will be set from an already defined value: postgresql.user
  database: "@format {this.postgresql.user}"

Validation of settings is also possible with Dynaconf but I prefer personally to use dataclasses or pydantic to define validated data classes.

See the core implementation for more details.

References

Here's a list of references I used to implement this project:

About

Small repository that contains experiments around settings management in python

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages