Package: dymmond-settings
Dymmond Lazy Settings🚀 Generic settings system applied to any application. 🚀Documentation:https://settings.dymmond.com📚Source Code:https://github.com/dymmond/dymmond-settingsThe official supported version is always the latest released.MotivationNot overcomplicating what it should be easy by default.In the current technological environment almost for certain, every system needs some sort of settings.
These settings are often inside asettings.pyfile or similar and then internally is called everywhere
needed.The problem encountered is the fact that those are not consideredlazy.What does that mean? Means that you often face issues when trying to get your application up and running
and those settings need be loaded beforehand but not evaluated until the time "comes".Thedymmond-settingswas created with the purpose of addressing those samelazysettings problems.The current Dymmond ecosystem uses a similar system an it was where this package came from.No hard dependencies, just pure Python usingdataclasses. Yes, you read properly, the settings
system is built on top of the default Python dataclasses, which means, you can take full advantage
of the built-in in your favour.Of course some defaults are provided and some extra functionality on top to make sure you can use
it without too much hassle.InstallationTo install, you can simply run.$pipinstalldymmond-settingsHow to use itThis is the best part. Inspired by the way the Dymmond ecosystem
(Esmerald,Edgy,Saffier,Mongoz) operates, these settings
aim to mimic exactly the same behaviour.You can simply import the globalSettingsobject and extend and then call thesettingslazy
object anywhere in your code without the risk of blowing up beforehand.DefaultsThe settings system provides some defaults for you that usually are common in every application
butyou are not entitled to use them.These defaults can be overridden at any given time, of course.Attributesdebug- Boolean flag generally used to indicate if the application should be in debug mode
or not. This is particularly useful if you want to separate some settings by environment.Default:Falseenvironment- String value indicating the the environment of thesettings. This can be
particularly useful if you want to show specific settings by the given environment. You can use
the provided values fromdymmond_settings.enums.EnvironmentTypeor create your own.Default:productionversion- A value indicating a possible theversionof your application running the settings.
It defaults to the current version ofdymmond_settingsif nothing is provided.Default:dymmond_settings.__version__FunctionsAlthough Pythondataclassesalso provides that same functionality for you,dymmond_settingsmakes it easier for you to use it.Alldymmond_settingsobjects can be used with any of the normaldataclassesfunctionalities
and applications.dict()This simply converts your settings module into a python dictionary. This provides the same level
of functionality ofasdictfrom the Pythondataclassesmodule whenexclude_noneis set
toFalse(default).Parameters:exclude_none- Excludes the values containingNone.upper- Boolean flag indicating if the keys should be in upper case.fromdataclassesimportdataclass,fieldfromdymmond_settingsimportSettings@dataclassclassAppSettings(Settings):...my_settings=AppSettings()my_settings.dict()Or if you want to exclude theNonevalues.fromdataclassesimportdataclass,fieldfromdymmond_settingsimportSettings@dataclassclassAppSettings(Settings):...my_settings=AppSettings()my_settings.dict(exclude_none=True)Or if you want the keys to be upper case.fromdataclassesimportdataclass,fieldfromdymmond_settingsimportSettings@dataclassclassAppSettings(Settings):...my_settings=AppSettings()my_settings.dict(upper=True)tuple()This simply converts your settings module into a python tuple but is slightly different from theastuplefrom Pythondataclassesmodule.The default fromdataclassesprovides a tuple with all the values of the object providedastuplewhereasdymmond_settingstuple function providesa list of tuples key/pair valued.As perdictfunctionality, thetuple()also provides aexclude_nonein case you want
a list attributes with the values set.Parameters:exclude_none- Excludes the values containingNone.upper- Boolean flag indicating if the keys should be in upper case.fromdataclassesimportdataclass,fieldfromdymmond_settingsimportSettings@dataclassclassAppSettings(Settings):...my_settings=AppSettings()my_settings.tuple()Or if you want to exclude theNonevalues.fromdataclassesimportdataclass,fieldfromdymmond_settingsimportSettings@dataclassclassAppSettings(Settings):...my_settings=AppSettings()my_settings.tuple(exclude_none=True)Or if you want the tuple to contain thekeysin upper case.fromdataclassesimportdataclass,fieldfromdymmond_settingsimportSettings@dataclassclassAppSettings(Settings):...my_settings=AppSettings()my_settings.tuple(upper=True)How to use itThere are many ways you can use the settings and all of them valid. Here we show just a few examples
how to use it.The auto detectionWhen using the settings system, you kinda need to be able to tell your application where to look up
for the settings when loading, right?Well yes and no, if you don't want to rely of the auto-load
of the settings for you and you want to take charge of if, you can simply skip this but if you don't,
well, this is the way.As mentioned before, to make sure you use the automatic detection of the settings in your applicationyou need to set an environment variable, calledSETTINGS_MODULE.When theSETTINGS_MODULEis set and pointing to your settings, this will make thesettingsobject fromdymmond_settingsaware of it and make it available globally and in lazy mode.Confusing? Well, let us see an example.Let us imagine we have asettings.pyfile somewhere in the code, example:myapp/config/settings.py.Let us also create our custom application settings and provide some values, like this:fromdataclassesimportdataclass,fieldfromdymmond_settingsimportSettings@dataclassclassAppSettings(Settings):debug:bool=Falsemy_setting:str=field(default="works")Simple so far, right? Ok, no we need to make sure our system is aware of these new settings and for
that we will set theSETTINGS_MODULEto point it out to our custom settings. Like this:$SETTINGS_MODULE='myapp.config.settings.AppSettings'python...And that is it, really! Although looking very simple, there is a lot of magic happening behind the scenes
that you don't need to worry about.Now, because we made the application aware, we are also able to use thesettingsobject provided
by thedymmond_settingsanywhere in your code base by simply importing it.Like this:fromdymmond_settingsimportsettingsdefget_my_settings()->str:returnsettings.my_settingThis simplesettingsis very powerful andlazy, which makes it perfect if you want to use it
anywhere in your codebase without those annoying imports happening all over the place.