json-based configuration manager with placeholder resolution, environment variable injection, and dynamic DLL path loading
Project description
org.slashlib.py.configloader
A lightweight, JSON-based configuration manager for Python projects. It automatically locates your project root, resolves nested placeholders, injects environment variables, and manages system paths.
Features
- Root Discovery: Automatically finds the project root based on a marker file (default:
pyproject.json). - Placeholder Resolution: Supports recursive interpolation of settings using the
{path.to.key}syntax. - Environment Injection: Automatically sets environment variables defined in the configuration.
- Path Management: Dynamically updates the system
PATHand registers DLL directories (Windows). - Asset Helper: Built-in utility to read mandatory file assets defined in your config.
- [[docs|Developer Documentation]]
Installation
Install the package (maybe in editable mode: -e) within your project directory. This will automatically resolve and install the required dependencies:
pip install .
Configuration Example (pyproject.json)
{
"env": {
"path": [
"./bin",
"./tools/external"
],
"dllpath": [
"./libs/native"
],
"vars": {
"DATABASE_URL": "postgres://user:pass@localhost/db",
"LOG_LEVEL": "DEBUG"
}
},
"paths": {
"data_dir": "{ROOT}/data",
"raw_files": "{paths.data_dir}/raw"
},
"assets": {
"schema": "./assets/schema.sql"
}
}
Usage
The ConfigLoader follows a "setup-and-forget" philosophy. Upon import, the library automatically creates a singleton instance that handles root discovery, placeholder resolution, and environment injection.
import logging
import org.slashlib.py.configloader
# 1. Automatic Initialization
# The 'configloader' is already initialized and has processed your 'pyproject.json'.
# Environment variables and PATH/DLL paths are already updated.
# 2. Optional: Setup Logging
# Uses the 'assets.logging' path from your JSON to initialize colorlog/logging.
# Defaults to "assets.logging" if no path is provided.
org.slashlib.py.configloader.setup_logging()
# 3. Access the processed configuration
# Placeholders like {ROOT} or {paths.data_dir} can be resolved.
data_dir = org.slashlib.py.configloader.config['paths']['data_dir']
# 4. Use the Resolve Helper (Recommended)
# Safely access nested nodes with dot-notation and optional default values.
db_port = org.slashlib.py.configloader.resolve("env.vars.DATABASE_PORT", default=5432)
# 5. Use the Asset Helper
# Conveniently read file contents using keys defined in your 'assets' section.
schema_content = org.slashlib.py.configloader.read_asset("schema")
# 6. Native Integration
# Environment variables are already accessible via the standard 'os' module.
import os
print(f"Database URL: {os.environ.get('DATABASE_URL')}")
# 7. Logging is ready to use
logger = logging.getLogger(__name__)
logger.info("Application started successfully.")
Requirements
- Python 3.8+
- Dependencies:
colorlog: Used for optional colored console output insetup_logging().
Documentation & Obsidian
The project root is pre-configured as an Obsidian Vault. If you open this folder directly in Obsidian, all settings and documentation links will be available immediately via the included .obsidian directory.
The following community plugins are pre-configured in the vault to enhance the documentation experience:
- File Include: Embed code files directly into your markdown documentation.
- Folder Notes: Add descriptions at the folder level.
- Front Matter Title: Use metadata for descriptive file titles.
- Hide Folders: Keeps the structure clean by hiding internal directories.
- Iconic & Icons: Improved visual navigation.
License
This project is licensed under the MIT License - see the LICENSE file for details.
© 2026 org.slashlib
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 org_slashlib_py_configloader-0.1.0.tar.gz.
File metadata
- Download URL: org_slashlib_py_configloader-0.1.0.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9bb0aca53f2d10cdea721220264d9700812d5c3af4735dde2304226ca91ca93a
|
|
| MD5 |
1577c2599b074826389031ff15ec9a00
|
|
| BLAKE2b-256 |
49c3c1f244c02805f1ae3311cbb8fe659cb58359583e7c5b80a4df5415851dab
|
File details
Details for the file org_slashlib_py_configloader-0.1.0-py3-none-any.whl.
File metadata
- Download URL: org_slashlib_py_configloader-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2ed2e300394a60b2090f8b51644a957f09dc4088bb535724f2fa98c5a54813f
|
|
| MD5 |
4f161fbe6e6728510b5e8b229ef39bc8
|
|
| BLAKE2b-256 |
610bb7346b802c927822fb6a2e0659a9ad5be052f477b0501d75089b058a8d0a
|