pyyaml-erb
解析 yaml 配置文件中的的环境变量
运行环境
介绍
模仿 Ruby 的 ERB 能力,把 yaml 配置文件中的环境变量做简单解析。
安装说明
执行脚本:
python -m pip install --upgrade pip
python -m pip install pyyaml-erb
使用说明
在代码中引入 pyyaml-erb 包,读取配置 yml 配置文件即可:
import erb.yml as yaml
with open(SETTING_PATH, 'r', encoding='utf-8') as file :
settings = yaml.load(file.read())
配置示例可参考 settings.yml,使用教程可参考单元测试 test_yaml_erb.py。
例如环境变量为 JAVA_HOME,只需要在 yaml 配置为 <%= ENV["KEY"] %> 或 <%= ${KEY} %> 的值表达式即可识别并解析。
一般而言,值表达式有以下几种配置模式:
key_1: <%= ENV["VAR_1"] %>: 默认的使用方式key_2: <%= ENV["VAR_2"] or None %>: 跟默认方式一样,多了默认值为 None,没意义key_3: <%= ENV["VAR_3"] || null %>: 跟默认方式一样,多了默认值为 None,没意义key_4: <%= ENV["VAR_4"] || "nil" %>: 跟默认方式一样,多了默认值为 None,没意义key_5: <%= ENV["VAR_5"] || default %>: 若环境变量不存在,会设置为默认值key_6: "<%= ENV['VAR_6'] or 'default' %>": 若环境变量不存在,会设置为默认值key_7: <%= ENV["VAR_7"] || 7 %>: 若环境变量不存在,会设置为默认值,且默认值会解析为整型key_8: <%= ENV["VAR_8"] || 1.23 %>: 若环境变量不存在,会设置为默认值,且默认值会解析为浮点型key_9: <%= ENV["VAR_9"] || true %>: 若环境变量不存在,会设置为默认值,且默认值会解析为布尔型key_10: <%= ENV["VAR_10"] || 'False' %>: 若环境变量不存在,会设置为默认值,且默认值会解析为布尔型key_0: '<%= ENV["VAR_0"] || ${VAR_11} or default %>': 混合模式
引号用双引号或单引号都可以,值表达式外围用不用引号包围都可以,表达式之间用
||或or都可以
Metadata
Release files for pyyaml-erb 1.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyyaml-erb-1.0.6.tar.gz | 9.5 kB | Without provenance | Details for pyyaml-erb-1.0.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyyaml_erb-1.0.6-py3-none-any.whl | Python 3 | none | any | Details for pyyaml_erb-1.0.6-py3-none-any.whl |
Total release size: 14.9 kB
Release files / pyyaml-erb-1.0.6.tar.gz
| Download URL | pyyaml-erb-1.0.6.tar.gz |
|---|---|
| Size | 9.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2d0ebcd66944f49b765d866cb6b01a72b2a4ddfbd1cdd74e6f2d3d8fc18686a6
|
|
BLAKE2b-256 checksum How to use checksums |
b32a175696695f9eb3aff2bf5e79fb4353c31faf622d030c3b28ce49e7e63770
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Release files / pyyaml_erb-1.0.6-py3-none-any.whl
| Download URL | pyyaml_erb-1.0.6-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b5701de94c0961eeb3f3e2e63933669c484e339578c0244427230d5a0fb03aa4
|
|
BLAKE2b-256 checksum How to use checksums |
a7658c0b6f8940821f4875fd29e51c4d92c899201c3b9d64b2c0e5c3dedb57e3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Security for pyyaml-erb 1.0.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.