Skip to main content

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.7.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.7-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: yamlc-0.1.7.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.7.tar.gz
Algorithm Hash digest
SHA256 cc2d537ef4cd3aa34b4c1d938d1cb078ed725c521d02a418a8c18866af32bb4d
MD5 4258066ba88ab975c2be736e24d58c68
BLAKE2b-256 053da9965c00c414777989c0197ff801f1413bd434f03bd36612294d0560dced

See more details on using hashes here.

File details

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

File metadata

  • Download URL: yamlc-0.1.7-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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 8b9eb5c58f456474bc5cbbc595413db407547b49d29953b99914769ced70f8bc
MD5 54d590d17ae3905f40724bbc648b674f
BLAKE2b-256 b5c12faf0e35c5f4cda0eda3c61b20f2757d67c9c214ec57dd3d5c75bf2b5fc7

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