A configuration file handler supporting YAML, JSON and TOML formats
Project description
bp-config
一个支持 YAML/JSON/TOML 格式的配置文件处理器
功能特性
- 支持读取和写入 YAML、JSON、TOML 格式的配置文件
- 自动根据文件扩展名选择对应的解析器
- 支持 UTF-8 编码,完美处理中文内容
- 简洁易用的 API 设计
安装
pip install bp-config
快速开始
from bp_config import ConfigHandler
# 初始化处理器
handler = ConfigHandler() # 默认使用当前目录
# handler = ConfigHandler(root="/path/to/config") # 指定配置目录
# 读取配置
config = handler.read_config("config.yaml") # 或 config.json/config.toml
# 修改配置
config["new_key"] = "value"
# 写入配置
handler.write_config("config.yaml", config)
API 文档
ConfigHandler()
read_config(filename)
读取并解析配置文件
参数:
filename: 配置文件名(相对或绝对路径)
返回: 解析后的字典对象
异常:
ValueError: 不支持的格式
FileNotFoundError: 文件不存在
IOError: 读取失败
write_config(filename, config)
将配置写入文件
参数:
filename: 要写入的文件名
config: 要写入的配置字典
异常:
ValueError: 不支持的格式
IOError: 写入失败
许可证 MIT 许可证 - 详见 LICENSE 文件
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
bp_config-0.1.0.tar.gz
(3.4 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
File details
Details for the file bp_config-0.1.0.tar.gz.
File metadata
- Download URL: bp_config-0.1.0.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e394a442e5364065a138a9605bbf680a42c65e820a5077cdbd51089f68bd8b2b
|
|
| MD5 |
cdb5cbf6958ef53b9c3729df7a4751e1
|
|
| BLAKE2b-256 |
247007d8f136e2d66b70237aced8e3b395988cd7b5d54dce53492d15bb7ad15e
|
File details
Details for the file bp_config-0.1.0-py3-none-any.whl.
File metadata
- Download URL: bp_config-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e175a7f02564a29be647ca0bf715308948b895d74dae493397fdbe17f3ca09c
|
|
| MD5 |
c0a3e990d3fb40d8e16a78e64b015087
|
|
| BLAKE2b-256 |
eb7527125d52446d7c04c5a9785365f86d8f4477e52c407ac5b925ab69fad44f
|