Skip to main content

A simple YAML configuration loader

Project description

yamlc

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

特性

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

安装

使用 pip 安装:

pip install yamlc

示例用法:

from yamlc import Yamlc

# 可选方法,用于加载 YAML 配置文件。若未调用,会在首次访问配置时自动加载。
# 未指定路径时,默认会在当前工作目录下查找 "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.10.tar.gz (3.5 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.10-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: yamlc-0.1.10.tar.gz
  • Upload date:
  • Size: 3.5 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.10.tar.gz
Algorithm Hash digest
SHA256 57a64d8033c77dc5ffbc71867ae54cc551d7ebf03bc400d27735ed0a92dd2be8
MD5 1e0b0b154bec02ef36b9f78d6ecf02da
BLAKE2b-256 0e3a4f0e054d4fa7d374176355b4f898e682bba4ecfc41fa568caee12ded0956

See more details on using hashes here.

File details

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

File metadata

  • Download URL: yamlc-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 3.7 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.10-py3-none-any.whl
Algorithm Hash digest
SHA256 6890a3244aaefabd1ec0c4f7fe2eb595a93a4916a3558f9b5d63eeb58d5caf9f
MD5 1e48f90dead208a01d7c119535805011
BLAKE2b-256 208d7c65757294002cb9d829c4e8440b98ff5ab1ecd2eeacdb1d6ddbd57e89e5

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