A python config module support hierarchical configuration and multi-environment deployment
- Free software: BSD license
- Documentation: https://cfg4py.readthedocs.io.
A python config module that:
- support hierarchical configuration and multiple source (local and remote)
- IDE auto-complete
- configuration template (logging, database, cache, message queue,…) generated by console command
- enable logging in one line
You have a bunch of severs of the same role, which usually share same configuration. But somehow for troubleshooting or maintenance purpose, you’d like some machines could have its own settings at particular moment.
This is how Cfg4Py solves the problem:
- Configure your application general settings at remote service, then implement a RemoteConfigFetcher (Cfg4Py has already implemented one), which pull configuration from remote serivce periodically.
- Change the settings resides on local machine, then the change automatically applied.
The hierarchical design can have different meaning. It’s common to see that you have different settings for development, test and production site. They share many common settings, but a few of them has to be different. Cfg4Py has perfect solution supporting for this: adaptive deployment environment support.
Adaptive Deployment Environment Support
In any serious projects, your application may run at both development, testing and production site. Except for effort of copying similar settings here and there, sometimes we’ll mess up with development environment and production site. Once this happen, it could result in very serious consequence.
To solve this, Cfg4Py developed a mechanism, that you provide different sets for configurations: dev for development machine, test for testing environment and production for production site, and all common settings are put into a file called ‘defaults’.
cfg4py module knows which environment it’s running on by lookup environment variables __cfg4py_server_role__. It can be one of ‘DEV’, ‘TEST’ and ‘PRODUCTION’. If nothing found, it means setup is not finished, and Cfg4Py will refuse to work. If the environment is set, then Cfg4Py will read settings from defaults set, then apply update from either of ‘DEV’, ‘TEST’ and ‘PRODUCTION’ set, according to the environment the application is running on.
Quick logging config
Many python projects are startup prototype. If it works, then we’ll put some really serious effort on it. Before that, we don’t want our effort to be waste on common chores. Even though, we do need logging module at most time, to assist us for better troubleshooting.
for that purpose, Cfg4Py provides a one-liner config for enabling logging:
Apply configuration change on-the-fly
Cfg4Py provides mechanism to automatically apply configuration changes without restart your application. For local files configuration change, it may take effect immediately. For remote config change, it take effect up to refresh_interval settings.
Code assist (auto-complete)
With other python config module, you have to remember all the configuration keys, and refer to each settings by something like cfg[“services”][“redis”][“host”] and etc. It’s hard to remember all configuration keys, and the way we access these settings is less concise than just use cfg.services.redis.host.
Cfg4Py let you access your settings by the latter format all the time. And, if you trigger a build against your configurations, it’ll generate a python class file. After you import this file (named ‘cfg4py_auto_gen.py’) into your project, then you can enjoy auto-complete!
- First release on PyPI.
- add command hint, set_server_role
- export envar
- add pip source, conda source
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size cfg4py-0.6.1-py3-none-any.whl (14.9 kB)||File type Wheel||Python version py3||Upload date||Hashes View|
|Filename, size cfg4py-0.6.1.tar.gz (3.1 MB)||File type Source||Python version None||Upload date||Hashes View|