<!-- ---
!-- Timestamp: 2025-08-27 17:09:53
!-- Author: ywatanabe
!-- File: /home/ywatanabe/proj/priority-config/README.md
!-- --- -->
# Priority Config
Universal configuration resolver with clean precedence hierarchy: **direct → config → env → default**
[](https://www.python.org/downloads/)
[](https://pypi.org/project/priority-config/)
[](https://opensource.org/licenses/MIT)
## Installation
```bash
pip install priority-config
```
## Quick Start
```python
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:
```mermaid
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:**
1. **Direct value** - Passed directly to `resolve()`
2. **Config dictionary** - From `config_dict` parameter
3. **Environment variable** - With `env_prefix` + key
4. **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 values
- `env_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 resolve
- `direct_val`: Direct value (highest precedence)
- `default`: Default value if not found elsewhere
- `type`: 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
Yusuke.Watanabe@scitex.ai
<!-- EOF -->
Raw data
{
"_id": null,
"home_page": null,
"name": "priority-config",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "Yusuke Watanabe <Yusuke.Watanabe@scitex.ai>",
"keywords": "configuration, config, environment, precedence, settings",
"author": null,
"author_email": "Yusuke Watanabe <Yusuke.Watanabe@scitex.ai>",
"download_url": "https://files.pythonhosted.org/packages/ed/d5/d19e8fc4294139ea511cd321fb0be7e0715426e5182b35d18d81e25d9fae/priority_config-0.1.1.tar.gz",
"platform": null,
"description": "<!-- ---\n!-- Timestamp: 2025-08-27 17:09:53\n!-- Author: ywatanabe\n!-- File: /home/ywatanabe/proj/priority-config/README.md\n!-- --- -->\n\n# Priority Config\n\nUniversal configuration resolver with clean precedence hierarchy: **direct \u2192 config \u2192 env \u2192 default**\n\n[](https://www.python.org/downloads/)\n[](https://pypi.org/project/priority-config/)\n[](https://opensource.org/licenses/MIT)\n\n## Installation\n\n```bash\npip install priority-config\n```\n\n## Quick Start\n\n```python\nfrom priority_config import PriorityConfig\n\n# Create config resolver\nconfig = PriorityConfig(\n config_dict={\"port\": 3000, \"debug\": True},\n env_prefix=\"MYAPP_\"\n)\n\n# Resolve with precedence\nport = config.resolve(\"port\", None, default=8000, type=int)\n# Returns: 3000 (from config_dict)\n\ndebug = config.resolve(\"debug\", False, default=True, type=bool)\n# Returns: False (direct_value takes precedence)\n\n# Environment variables (MYAPP_HOST) override config\nhost = config.resolve(\"host\", default=\"localhost\")\n# Returns: value from MYAPP_HOST env var, or \"localhost\"\n\n# See resolution log\nconfig.print_resolutions()\n# Configuration Resolution Log:\n# --------------------------------------------------\n# port = 3000 (config)\n# debug = 0 (direct)\n# host = localhost (default)\n```\n\n## How It Works\n\nThe configuration resolution follows a clean precedence hierarchy:\n\n```mermaid\ngraph TD\n A[resolve] --> B{direct_val?}\n B -->|Yes| C[Use direct_val]\n B -->|No| D{Key in config_dict?}\n D -->|Yes| E[Use config_dict value]\n D -->|No| F{Environment variable exists?}\n F -->|Yes| G[Use env var + type conversion]\n F -->|No| H[Use default value]\n \n C --> I[Apply masking if sensitive]\n E --> I\n G --> I\n H --> I\n \n I --> J[Log resolution source]\n J --> K[Return final value]\n \n style C fill:#e1f5fe\n style E fill:#f3e5f5\n style G fill:#e8f5e8\n style H fill:#fff3e0\n style I fill:#fce4ec\n```\n\n**Precedence Order:**\n1. **Direct value** - Passed directly to `resolve()`\n2. **Config dictionary** - From `config_dict` parameter\n3. **Environment variable** - With `env_prefix` + key\n4. **Default value** - Fallback if nothing else found\n\n## Features\n\n- **Clean Precedence**: `direct \u2192 config \u2192 env \u2192 default`\n- **Automatic Type Conversion**: `str`, `int`, `float`, `bool`, `list`\n- **Sensitive Data Masking**: Auto-detects and masks passwords, keys, tokens\n- **Resolution Logging**: Track where each value came from\n- **Zero Dependencies**: Pure Python, works with 3.8+\n\n## API Reference\n\n### `PriorityConfig(config_dict=None, env_prefix=\"\", auto_uppercase=True)`\n\n- `config_dict`: Dictionary with configuration values\n- `env_prefix`: Prefix for environment variables (e.g., \"MYAPP_\")\n- `auto_uppercase`: Whether to uppercase keys for env lookup\n\n### `resolve(key, direct_val=None, default=None, type=str, mask=None)`\n\n- `key`: Configuration key to resolve\n- `direct_val`: Direct value (highest precedence)\n- `default`: Default value if not found elsewhere\n- `type`: Type conversion (`str`, `int`, `float`, `bool`, `list`)\n- `mask`: Override automatic masking of sensitive values\n\n### `print_resolutions()`\n\nPrint resolution log showing where each value came from.\n\n### `clear_log()`\n\nClear the resolution log.\n\n## License\n\nMIT\n\n## Contact\nYusuke.Watanabe@scitex.ai\n\n<!-- EOF -->\n",
"bugtrack_url": null,
"license": null,
"summary": "Universal config resolver with precedence: direct \u2192 config \u2192 env \u2192 default",
"version": "0.1.1",
"project_urls": {
"Documentation": "https://github.com/ywatanabe1989/priority-config",
"Homepage": "https://github.com/ywatanabe1989/priority-config",
"Repository": "https://github.com/ywatanabe1989/priority-config"
},
"split_keywords": [
"configuration",
" config",
" environment",
" precedence",
" settings"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "04d57665a61921aa14adbe67ea6dfe9ceaa178bde8381e9ae2cd3ed43c3648b7",
"md5": "6156eb30a90d303f0a1a89cc097ad0b3",
"sha256": "394b5a7b26d28a0ee714ba25853888596c64cdb2d86bbb59b57d7905d433604c"
},
"downloads": -1,
"filename": "priority_config-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6156eb30a90d303f0a1a89cc097ad0b3",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 5758,
"upload_time": "2025-08-27T07:16:11",
"upload_time_iso_8601": "2025-08-27T07:16:11.614559Z",
"url": "https://files.pythonhosted.org/packages/04/d5/7665a61921aa14adbe67ea6dfe9ceaa178bde8381e9ae2cd3ed43c3648b7/priority_config-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "edd5d19e8fc4294139ea511cd321fb0be7e0715426e5182b35d18d81e25d9fae",
"md5": "9d504d10e3e543c6a695f45a4f2bfd55",
"sha256": "57d5d4082661f90595fac589814c2d268776ad679c131e4ab21545112fb5bd02"
},
"downloads": -1,
"filename": "priority_config-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "9d504d10e3e543c6a695f45a4f2bfd55",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 5556,
"upload_time": "2025-08-27T07:16:12",
"upload_time_iso_8601": "2025-08-27T07:16:12.579853Z",
"url": "https://files.pythonhosted.org/packages/ed/d5/d19e8fc4294139ea511cd321fb0be7e0715426e5182b35d18d81e25d9fae/priority_config-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-27 07:16:12",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ywatanabe1989",
"github_project": "priority-config",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "priority-config"
}