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.0.tar.gz (6.1 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.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mrconfig-0.1.0.tar.gz
  • Upload date:
  • Size: 6.1 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.0.tar.gz
Algorithm Hash digest
SHA256 09ba4a487196c7f131047b82a7b0bb88c1ef88ce5290ea19d88288686ba8baac
MD5 da084eac8385d34a2fbdfb138874be34
BLAKE2b-256 624c89cf978828565a9f66825bf66db5ec01d1d1fac48688bbb0f1703ede2ad4

See more details on using hashes here.

Provenance

The following attestation bundles were made for mrconfig-0.1.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: mrconfig-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 29210e6ab3065b7948789b2da1a1a13ca8a49af07adc589a0ac42448a3f160d5
MD5 1870cd0aed5fa4283a9f8c5e2c47093c
BLAKE2b-256 115c9620ad589014d71284f70eabaf74beb80f00622085be1828f71c69baa659

See more details on using hashes here.

Provenance

The following attestation bundles were made for mrconfig-0.1.0-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