允许轻松加载配置设置的库。

theatro-cfg-loader的Python项目详细描述


Build StatusCoverageDocumentation Status

Cfg装载机

Cfg Loader是一个允许轻松加载配置设置的库。 它使用marshmallow将输入数据反序列化为目标格式的配置数据。

主要特点

要求

Python>;=3.6

一个简单的例子

>>>fromcfg_loaderimportConfigSchema,BaseConfigLoader>>>frommarshmallowimportfields# Declare your configuration schema>>>classMyConfigSchema(ConfigSchema):...setting1=fields.Str()...setting2=fields.Int(required=True)...setting3=fields.Float(missing=13.2)# Declare mapping to substitute environment variable>>>substitution_mapping={'FILE_PATH':'file'}# Initialize config loader>>>my_config_loader=BaseConfigLoader(MyConfigSchema,substitution_mapping=substitution_mapping)# Load configuration>>>config=my_config_loader.load({'setting1':'/home/folder/${FILE_PATH?:file path required}','setting2':'4'})>>>config=={'setting1':'/home/folder/file','setting2':4,'setting3':13.2}True# Invalid input data>>>my_config_loader.load({'setting1':'/home/folder/${FILE_PATH?:file path required}','setting3':13.4})Traceback(mostrecentcalllast):...cfg_loader.exceptions.ValidationError:{'setting2':['Missing data for required field.']}>>>my_config_loader.load({'setting2':12,'setting3':'string'})Traceback(mostrecentcalllast):...cfg_loader.exceptions.ValidationError:{'setting3':['Not a valid number.']}# Variable substitution invalid>>>my_config_loader.load({'setting2':'${UNSET_VARIABLE?Variable "UNSET_VARIABLE" required}'})Traceback(mostrecentcalllast):...cfg_loader.exceptions.UnsetRequiredSubstitution:Variable"UNSET_VARIABLE"required

文档

完整的文档可在https://cfg-loader.readthedocs.io/en/stable/上找到。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java运行时异常:com。安卓建设者德兴。DexArchiveMergerException:无法合并dex   java UDP如何获取传入数据报的目标地址   java如何将一些内容保存到列中并将其读回对象   属性类Java   java如何将二进制数据附加到HSQL(2.3.2)blob中?   试图在Maven项目中使用OpenJPA连接到Derby数据库,但出现“java.sql.SQLException”错误。   java(JavaFX)如何将类的实例传递给FXML控制器而不知道该控制器的名称?   sql为什么单线程使我的Java程序更快?   在单独的窗口上显示控制台输出[java]   java在Hadoop集群之外从Eclipse访问HDFS   java在我的类中初始化以下实例的最佳方法是什么?   java类单例或组件。它必须从不同的地方调用   java如何将配置文件自动下载到项目的根目录?