A simple YAML configuration loader
Project description
yamlc
yamlc 是一个简单的 Python 库,用于读取和管理 YAML 配置文件。它允许用户轻松加载、访问和重新加载配置。
特性
- 点语法访问嵌套的配置项。
- 支持重新加载配置文件。
- 可以设置配置文件路径。
安装
使用 pip 安装:
pip install yamlc
示例用法:
from yamlc import Yamlc
# 使用前调用 load 加载配置文件。默认加载当前工作目录下的`config.yaml`
Yamlc.load()
# 使用自定义路径加载配置文件
Yamlc.load("/path/to/config.yaml")
# 获取配置项
value = Yamlc.get("database.host")
print(value) # 输出: localhost (假设配置文件中有此项)
# 获取配置项并指定默认值
value = Yamlc.get("database.host", default="localhost")
print(value) # 如果配置中没有 "database.host",则返回 "localhost"
# 获取 "database" 配置块
database_config = Yamlc.get("database")
print(database_config)
# 输出: {'host': 'localhost', 'port': 5432, 'username': 'user', 'password': 'pass'}
# 假设配置文件中有 "database" 配置块
重新加载配置文件
如果配置文件有修改,可以调用reload方法重新加载配置。
# 重新加载配置文件
Yamlc.reload()
配置文件示例
yaml配置文件格式如下所示:
database:
host: localhost
port: 5432
username: user
password: pass
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
yamlc-0.1.8.tar.gz
(3.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
yamlc-0.1.8-py3-none-any.whl
(4.0 kB
view details)
File details
Details for the file yamlc-0.1.8.tar.gz.
File metadata
- Download URL: yamlc-0.1.8.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c32af655a76c7718eb1f8f09118b3dc513faeb07a966997cf9b432406c06dfb9
|
|
| MD5 |
d4a080c64ba8cfc0c0c7d7c3747536ae
|
|
| BLAKE2b-256 |
4d4a83d3a137a0485683e263df8ad6328317143354f52c55eafc99c169fb620f
|
File details
Details for the file yamlc-0.1.8-py3-none-any.whl.
File metadata
- Download URL: yamlc-0.1.8-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4f3c85676d176f32a252dd6e9d467efb5647e93741389fbe4c1559aaf52b634
|
|
| MD5 |
01ae35d0078fe07dc30c718d08cca1c4
|
|
| BLAKE2b-256 |
65de710503dd2eac972d44ae7eaf2ac397711b4d37a5914a7729f2637a83509f
|