Skip to main content

多路径配置文件加载器

Project description

mrconfig

多路径配置文件加载器,支持 JSON、YAML、TOML 格式

安装

pip install mrconfig

支持格式

格式 扩展名 说明
JSON .json 标准 JSON 格式
YAML .yaml, .yml YAML 格式
TOML .toml TOML 格式(Python 3.11+)

使用

from mrconfig import ConfigLoader

# 简单用法:当前目录 + XDG 目录
loader = ConfigLoader(name=".myapp.yaml", xdg="app/config.yaml")
config = loader.load(default={"debug": False})

参数说明

参数 说明
name 当前目录下的配置文件名(默认 .yaml
xdg XDG 配置目录下的路径
env 环境变量名,指向配置文件路径(最高优先级)

XDG 配置路径

平台 路径
Linux ~/.config/{filename}
macOS ~/.config/{filename}
Windows %APPDATA%\{filename}

可通过环境变量覆盖:

  • Linux/macOS: XDG_CONFIG_HOME
  • Windows: APPDATA

API

ConfigLoader

class ConfigLoader:
    def __init__(
        self,
        name: str | None = None,
        xdg: str | None = None,
        env: str | None = None,
        loaders: dict | None = None,
    ): ...
    def load(self, default: dict | None = None) -> dict | None: ...

load_config(name=None, xdg=None, env=None, default=None)

便捷函数

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

mrconfig-0.1.1.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

mrconfig-0.1.1-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file mrconfig-0.1.1.tar.gz.

File metadata

  • Download URL: mrconfig-0.1.1.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mrconfig-0.1.1.tar.gz
Algorithm Hash digest
SHA256 81234ea1a17ccb1af3b184583057532377f6fca98dbbbbe6a4076a3f6040ac54
MD5 3ac39a36ef00a5d262f0783dba4055a9
BLAKE2b-256 9f57252bebc899f568398c716a759721da0adb538b1d5a704adb68a1ff530539

See more details on using hashes here.

Provenance

The following attestation bundles were made for mrconfig-0.1.1.tar.gz:

Publisher: release.yml on ricsy/mrconfig

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mrconfig-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mrconfig-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mrconfig-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1ca7f7f4ae9b0d3edfcdd372ad3c8d8308cd174014cb0ff47210a86420c5666c
MD5 d677e37050d817f54ee832e50bf3cad7
BLAKE2b-256 ad29db0bd8f53344a285ba1bdc53024100d66c2bb2aa542c718f9bee76a61404

See more details on using hashes here.

Provenance

The following attestation bundles were made for mrconfig-0.1.1-py3-none-any.whl:

Publisher: release.yml on ricsy/mrconfig

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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