Priority Config
Universal configuration resolver with clean precedence hierarchy: direct → config → env → default
Installation
pip install priority-config
Quick Start
from priority_config import PriorityConfig
# Create config resolver
config = PriorityConfig(
config_dict={"port": 3000, "debug": True},
env_prefix="MYAPP_"
)
# Resolve with precedence
port = config.resolve("port", None, default=8000, type=int)
# Returns: 3000 (from config_dict)
debug = config.resolve("debug", False, default=True, type=bool)
# Returns: False (direct_value takes precedence)
# Environment variables (MYAPP_HOST) override config
host = config.resolve("host", default="localhost")
# Returns: value from MYAPP_HOST env var, or "localhost"
# See resolution log
config.print_resolutions()
# Configuration Resolution Log:
# --------------------------------------------------
# port = 3000 (config)
# debug = 0 (direct)
# host = localhost (default)
How It Works
The configuration resolution follows a clean precedence hierarchy:
graph TD
A[resolve] --> B{direct_val?}
B -->|Yes| C[Use direct_val]
B -->|No| D{Key in config_dict?}
D -->|Yes| E[Use config_dict value]
D -->|No| F{Environment variable exists?}
F -->|Yes| G[Use env var + type conversion]
F -->|No| H[Use default value]
C --> I[Apply masking if sensitive]
E --> I
G --> I
H --> I
I --> J[Log resolution source]
J --> K[Return final value]
style C fill:#e1f5fe
style E fill:#f3e5f5
style G fill:#e8f5e8
style H fill:#fff3e0
style I fill:#fce4ec
Precedence Order:
- Direct value - Passed directly to
resolve() - Config dictionary - From
config_dictparameter - Environment variable - With
env_prefix+ key - Default value - Fallback if nothing else found
Features
- Clean Precedence:
direct → config → env → default - Automatic Type Conversion:
str,int,float,bool,list - Sensitive Data Masking: Auto-detects and masks passwords, keys, tokens
- Resolution Logging: Track where each value came from
- Zero Dependencies: Pure Python, works with 3.8+
API Reference
PriorityConfig(config_dict=None, env_prefix="", auto_uppercase=True)
config_dict: Dictionary with configuration valuesenv_prefix: Prefix for environment variables (e.g., "MYAPP_")auto_uppercase: Whether to uppercase keys for env lookup
resolve(key, direct_val=None, default=None, type=str, mask=None)
key: Configuration key to resolvedirect_val: Direct value (highest precedence)default: Default value if not found elsewheretype: Type conversion (str,int,float,bool,list)mask: Override automatic masking of sensitive values
print_resolutions()
Print resolution log showing where each value came from.
clear_log()
Clear the resolution log.
License
MIT
Contact
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
priority_config-0.1.1.tar.gz
(5.6 kB
view details)
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 priority_config-0.1.1.tar.gz.
File metadata
- Download URL: priority_config-0.1.1.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.11.0rc1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
57d5d4082661f90595fac589814c2d268776ad679c131e4ab21545112fb5bd02
|
|
| MD5 |
9d504d10e3e543c6a695f45a4f2bfd55
|
|
| BLAKE2b-256 |
edd5d19e8fc4294139ea511cd321fb0be7e0715426e5182b35d18d81e25d9fae
|
File details
Details for the file priority_config-0.1.1-py3-none-any.whl.
File metadata
- Download URL: priority_config-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.11.0rc1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
394b5a7b26d28a0ee714ba25853888596c64cdb2d86bbb59b57d7905d433604c
|
|
| MD5 |
6156eb30a90d303f0a1a89cc097ad0b3
|
|
| BLAKE2b-256 |
04d57665a61921aa14adbe67ea6dfe9ceaa178bde8381e9ae2cd3ed43c3648b7
|