从python应用程序的环境中加载配置。
python-set-ings的Python项目详细描述
已弃用
此包已弃用。pydantic提供same featureset和更多。
python集合
从python应用程序的环境中加载配置。支持类型转换和默认值。设置以一种与ide配合良好且易于阅读的方式提供。
安装
pipenv install python-set-ings
或pip install python-set-ings
用法
# my_app/settings.pyfromset_ingsimportPropertyfromset_ingsimportSettingsasSettingsBaseSettings(SettingsBase):_PREFIX='YOUR_PREFIX'FOO=Property(10,cast=int)BAR=Property()settings=Settings()
然后确保设置了在设置中定义的环境变量。
对于上面的示例,您必须设置YOUR_PREFIX_BAR
,并且可以选择
YOUR_PREFIX_FOO
。
要在应用程序中的任何位置使用设置:
frommy_app.settingsimportsettingsprint(settings.FOO+2)
贡献
安装
git clone git@github.com:evocount/python-set-ings.git
cd python-set-ings
pipenv install --dev
运行测试
pipenv run pytest --cov
许可证
这个项目是根据MIT License授权的。