A unified YAML configuration manager supporting local files and dynamic Nacos configuration with hot-reloading, environment variable substitution, and built-in encryption (SM2/SM4) support.
Project description
YAML Configuration Management: Local Files + Nacos Dynamic Configuration
This project provides a unified YAML configuration loading framework that supports both local YAML files and Nacos configuration center, with features such as hot updates, environment variable substitution, and encrypted value decoding.
Install the core package:
pip install yamlpyconfig
If you need Nacos support:
pip install yamlpyconfig[nacos]
1. Local YAML Configuration
Your configuration folder (e.g., /config) must contain at least:
application.yaml- Optional:
application-{profile}.yaml
1.1 Profile Resolution Rules
The active profile is determined with the following priority (from highest to lowest):
- Environment variable:
APP_PROFILE - Environment variable:
SPRING_PROFILES_ACTIVE - The
profilefield insideapplication.yaml - If none of the above exist →
application-{profile}.yamlwill NOT be loaded
Notes
- The configuration directory must contain
application.yaml. Missing this file causes an error. - If a profile is resolved but
application-{profile}.yamldoes not exist, an exception is raised.
2. Loading Configuration from Nacos
To enable Nacos, declare the config-sources.nacos section inside your local configuration:
config-sources:
nacos:
server-addr: "192.168.30.36:9090"
namespace: "dev"
group: "DEFAULT_GROUP"
username: "nacos"
password: "{encrypted}VuFvNZOg/q7ZQoIUGWydBw=="
imports:
- data-id: "gateway.yaml"
- data-id: "application-ext.yaml"
2.1 Configuration Merge Priority (Low → High)
- Local
application.yaml - Local
application-{profile}.yaml - Nacos imports (following the order declared; later entries override earlier ones)
3. Key Features and Usage Examples
3.1 Basic Usage
Example: load configuration and print updates automatically:
@pytest.mark.asyncio
async def test_config_manager_with_nacos(self):
async with ConfigManager("./") as config_manager:
logger.info(config_manager.get_config())
while True:
await asyncio.sleep(5)
logger.info(config_manager.get_config())
When entering the async with block:
- Local configuration is loaded first
- If Nacos is configured → it connects automatically and listens for real-time updates
3.2 Environment Variable Interpolation
Local YAML files support Spring-style placeholders:
key-with-default: ${KEY1:DEFAULT_VALUE}
key: ${KEY2}
Behavior:
- If the environment variable exists → its value is used
- If it does not exist → use the default value after the colon
- If no default value is provided →
Noneis returned
3.3 Encrypted Field Support (SM2 / SM4)
Sensitive fields (passwords, secret keys, etc.) can be encrypted and marked with the {encrypted} prefix:
password: "{encrypted}VuFvNZOg/q7ZQoIUGWydBw=="
To enable automatic decryption, specify the algorithm and key when initializing ConfigManager:
@pytest.mark.asyncio
async def test_config_manager_with_nacos_decrypt(self):
# SM4 example — uses a symmetric key
async with ConfigManager(
"./",
crypto_algorithm=AlgorithmEnum.SM4,
key="lSU543Tes6wmjnb+PMVQNg=="
) as config_manager:
logger.info(config_manager.get_config())
Explanation:
- SM4 → symmetric encryption (pass the secret key)
- SM2 → asymmetric encryption (provide the private key; public key optional depending on use case)
Project details
Release history Release notifications | RSS feed
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 yamlpyconfig-0.1.2.tar.gz.
File metadata
- Download URL: yamlpyconfig-0.1.2.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
440a9079c502ad81f0f6485ed275d96faf88a38bfd226c4a8712dcee44f52084
|
|
| MD5 |
de9df7b1e57d37f019fd939d2ac54611
|
|
| BLAKE2b-256 |
cabce3d864ffde12d3ffdfb589edf8e6049a5e93ad6d8bf10ebb4a468421d14c
|
File details
Details for the file yamlpyconfig-0.1.2-py3-none-any.whl.
File metadata
- Download URL: yamlpyconfig-0.1.2-py3-none-any.whl
- Upload date:
- Size: 21.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8934fef9abba2a0f385a040705d9a9035848b9e43ba3f4d49f3a173b5abc3cd
|
|
| MD5 |
805c58c091209772c605636e9080c78d
|
|
| BLAKE2b-256 |
60558add2d20462c751417352a46d9bb3fa96a6358496e8698c0c44e139de17f
|