Skip to main content

A simple YAML configuration loader

Project description

yamlc

yamlc 是一个简单的 Python 库,用于读取和管理 YAML 配置文件。它允许用户轻松加载、访问和重新加载配置。

特性

  • 点语法访问嵌套的配置项。
  • 支持重新加载配置文件。
  • 可以设置配置文件路径。

安装

使用 pip 安装:

pip install yamlc

示例用法:

from yamlc import Yamlc

# 可选方法,用于加载 YAML 配置文件。若未调用,会在首次访问配置时自动加载。
# 未指定路径时,按优先级依次尝试:
# 1. 当前工作目录下的 "config.yaml"
# 2. 主脚本所在目录下的 "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.9.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yamlc-0.1.9-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file yamlc-0.1.9.tar.gz.

File metadata

  • Download URL: yamlc-0.1.9.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.20

File hashes

Hashes for yamlc-0.1.9.tar.gz
Algorithm Hash digest
SHA256 d11eca56e4c5d0f7fe1186036973565348f26dce58651b22b85c28256cbefb27
MD5 8e180b6ff92e2a632ec8c52f280b1ff3
BLAKE2b-256 1701cb2c3688d190a38339072ef73d47f73b9d4f06316803f6913fe0f3e4c3ea

See more details on using hashes here.

File details

Details for the file yamlc-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: yamlc-0.1.9-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

Hashes for yamlc-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 fb37907558a72b9109ad24eba114c7aea1b86182a31fb709cf56b6782062cd78
MD5 c4ffbafdbb26ea6d6bb6f2464a13c28d
BLAKE2b-256 bdf2f829da0f5f09b8b0e4cedb87b60d0bcb31ac15a3cbecf7b81e2b73cc78d9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page