Package: concrete-settings
Welcome to Concrete SettingsConcrete Settingsis a Python library which facilitates
configuration management in big and small projects.The library was born out of necessity to manage a huge
decade-old Django-based SaaS solution with more than two hundred
different application settings scattered aroundsettings.py.What does this setting do?What type is it?Why does it have such a weird format?Is this the final value, or it changes somewhere on the way?Sometimes developers spenthoursseeking answers to these
questions.Concrete Settigns tackles these problems altogether.
It was designed to be developer and end-user friendly.
The settings are defined via normal Python code with few
tricks which significantly improve readability
and maintainability.ContentsWelcome to Concrete SettingsA small exampleConcrete conceptsWhat’s inside?Catch an invalid value earlyEasily warn about deprecationGroup settings and nest themThere is even moreAwesome configuration projectsWords of gratitudeA small exampleTake a look at a small example of Settings class with one
boolean settingDEBUG. A developer defines the
settings in application code, while an end-user
chooses to store the configuration in a YAML file:# settings.pyfromconcrete_settingsimportSettingsclassAppSettings(Settings):#: Turns debug mode on/offDEBUG:bool=Falseapp_settings=AppSettings()app_settings.update('/path/to/user/settings.yml')app_settings.is_valid(raise_exception=True)# settings.ymlDEBUG:trueAccessing settings:>>>print(app_settings.DEBUG)True>>>print(AppSettings.DEBUG.__doc__)Turns debug mode on/offConcrete conceptsSettings aredefined in classes. Python mechanism
of inheritance and composition apply here, so settings can bemixed(multiple inheritance)
and benested(settings as class fields).
Settings aretype-annotatedand arevalidated.
Documentation matters! Each settings can be documented in Sphinx-style comments#:written
above its definition.
An instance ofSettingscan be updated i.e. read from any kind of source:
YAML, JSON or Python files, environmental variables, Python dicts, and you can add more!Finally, Concrete Settings comes with batteries like Django 3.0 support out of the box.Concrete Settings are here to improve configuration handling
whether you are starting from scratch, or dealing with an
old legacy Cthulhu.
Are you ready to try it out?pip installconcrete-settingsand welcome to thedocumentation!What’s inside?So, you are a kind of a developer who expects more show cases in aREADME?
Let’s see!Catch an invalid value earlyFor example, the defaulttype validatorworks like this:fromconcrete_settingsimportSettingsclassAppSettings(Settings):SPEED:int='abc'app_settings=AppSettings()print(app_settings.is_valid(raise_exception=False))print(app_settings.errors)Output:False
{'SPEED': ["Expected value of type `<class 'int'>` got value of type `<class 'str'>`"]}Easily warn about deprecationUsebehaviorsto control settings during theirinitialization,validation,readingandwritingoperations:fromconcrete_settingsimportSettings,Settingfromconcrete_settings.contrib.behaviorsimportdeprecatedclassAppSettings(Settings):MAX_SPEED:int=30@deprecatedapp_settings=AppSettings()app_settings.is_valid()Running this code withpython-Wdefaultyields:DeprecationWarning: Setting `MAX_SPEED` in class `<class '__main__.AppSettings'>` is deprecated.Group settings and nest themDifferent settings in a huge setting file?
Why have those stupidGROUP_PREFIXES_...?
Instead group and nest settings:fromconcrete_settingsimportSettingsclassDBSettings(Settings):USER='alex'PASSWORD='secret'SERVER='localhost@5432'classCacheSettings(Settings):ENGINE='DatabaseCache'TIMEOUT=300classLoggingSettings(Settings):LEVEL='INFO'FORMAT='%(asctime)s%(levelname)-8s%(name)-15s%(message)s'classAppSettings(Settings):DB=DBSettings()CACHE=CacheSettings()LOG=LoggingSettings()app_settings=AppSettings()app_settings.is_valid()# also invokes DB, CACHE and LOG validationprint(app_settings.LOG.LEVEL)There is even moreThere is even more for you to discover indocumentation,
and there is more to come.Yourcontribution, be it
abug report,pull request,suggested feature,commentsandcriticismare very welcome!Awesome configuration projectsConcrete Settings is not the first and surely not the last library to handle
configuration in Python projects.goodconf- Define configuration variables and load them from environment or
JSON/YAML file. Also generates initial configuration files and
documentation for your defined configuration.profig- is a straightforward configuration library for Python.
Its objective is to make the most common tasks of configuration
handling as simple as possible.everett- is a Python configuration library with the following goals:
flexible configuration from multiple configured environments;
easy testing with configuration and easy documentation of configuration
for users.python-decouple- strict separation of settings from code. Decouple helps you to organize
your settings so that you can change parameters without having to redeploy
your app.Why should you trust Concrete Settings instead of picking some other library?
Concrete Settings tries to make configuration definition, processing and maintenance smooth and transparent for developers. Its implicit definition syntax eliminates extra code and allows you to focus on  what is important.Words of gratitudeIt is hard to imagine a software project without the infrastructure that supports it.
Concrete Settings exists as an open source library only thanks to the services and the tools
that are used to host, build and maintain it.My warmest words of gratitude go toGithubfor hosting the project source,Read the Docsfor hosting the documentation,Travis CIfor continuous integration process
and`pyupio <https://pyup.io>`_ for keeping dependencies up-to-date!Many thanks for the authors and contributors of the libraries used to build the project.All these wonderful services and tools have been providedpro bono.