多路径配置文件加载器
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81234ea1a17ccb1af3b184583057532377f6fca98dbbbbe6a4076a3f6040ac54
|
|
| MD5 |
3ac39a36ef00a5d262f0783dba4055a9
|
|
| BLAKE2b-256 |
9f57252bebc899f568398c716a759721da0adb538b1d5a704adb68a1ff530539
|
Provenance
The following attestation bundles were made for mrconfig-0.1.1.tar.gz:
Publisher:
release.yml on ricsy/mrconfig
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mrconfig-0.1.1.tar.gz -
Subject digest:
81234ea1a17ccb1af3b184583057532377f6fca98dbbbbe6a4076a3f6040ac54 - Sigstore transparency entry: 1185081534
- Sigstore integration time:
-
Permalink:
ricsy/mrconfig@335db5a8a1858e5cadf49e73718ea87b75e403e1 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/ricsy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@335db5a8a1858e5cadf49e73718ea87b75e403e1 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ca7f7f4ae9b0d3edfcdd372ad3c8d8308cd174014cb0ff47210a86420c5666c
|
|
| MD5 |
d677e37050d817f54ee832e50bf3cad7
|
|
| BLAKE2b-256 |
ad29db0bd8f53344a285ba1bdc53024100d66c2bb2aa542c718f9bee76a61404
|
Provenance
The following attestation bundles were made for mrconfig-0.1.1-py3-none-any.whl:
Publisher:
release.yml on ricsy/mrconfig
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mrconfig-0.1.1-py3-none-any.whl -
Subject digest:
1ca7f7f4ae9b0d3edfcdd372ad3c8d8308cd174014cb0ff47210a86420c5666c - Sigstore transparency entry: 1185081536
- Sigstore integration time:
-
Permalink:
ricsy/mrconfig@335db5a8a1858e5cadf49e73718ea87b75e403e1 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/ricsy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@335db5a8a1858e5cadf49e73718ea87b75e403e1 -
Trigger Event:
release
-
Statement type: