集装箱应用的方便配置
container-app-conf的Python项目详细描述
容器应用程序配置
container app conf是一个易于读取应用程序值的库 从多个地方,比如一个yaml文件和环境变量 同时提供类型验证。
这个库的最初目的是有一个简单的配置方法 在某种容器中运行的应用程序(本例中为Docker) 使用环境变量,同时仍然提供使用 一种更简单的配置形式,如yaml文件。
如何使用
pip install container-app-conf
扩展Config
基
fromcontainer_app_confimportConfigfromcontainer_app_conf.entry.stringimportStringConfigEntryclassAppConfig(Config):@propertydefconfig_file_names(self)->[str]:return["my_app_config_file_name"]MY_CONFIG=StringConfigEntry(yaml_path=["my_app_config_file_name","example"],none_allowed=False)
配置类型
Name | Description | Type |
---|---|---|
^{ | Parses ^{ | ^{ |
^{ | Parses input to an integer | ^{ |
^{ | Parses input to a floating number | ^{ |
^{ | Takes the raw string input | ^{ |
^{ | Parses a comma separated string to a list of items specified in another ^{ | ^{ |
ConfigEntry
基类来拥有。默认值
通过使用
default
构造函数参数。
允许None
默认情况下,仅当默认值为None
时,才允许使用None
值。
这意味着无法在示例中设置MY_CONFIG
项
在顶部到None
,即使在初始解析之后。指定空文本
在yaml或相应的环境变量中,将导致
例外。如果希望允许设置None
值,可以使用
none_allowed
构造函数参数。
贡献
github是用于社会编码的:如果您想编写代码,我鼓励通过forks的pull请求进行贡献 关于这个仓库。为bug和新特性创建github票证,并评论您感兴趣的特性。
许可证
container-app-conf Copyright (c) 2019 Markus Ressel Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.