Skip to main content

json-based configuration manager with placeholder resolution, environment variable injection, and dynamic DLL path loading

Project description

Bottom AI CHANGELOG LICENSE

PyPI versionLicense: MIT

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 PATH and 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 in setup_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:

More docs


License

This project is licensed under the MIT License - see the LICENSE file for details.


© 2026 org.slashlib

TOP AI CHANGELOG LICENSE

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

org_slashlib_py_configloader-0.1.0.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

org_slashlib_py_configloader-0.1.0-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file org_slashlib_py_configloader-0.1.0.tar.gz.

File metadata

File hashes

Hashes for org_slashlib_py_configloader-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9bb0aca53f2d10cdea721220264d9700812d5c3af4735dde2304226ca91ca93a
MD5 1577c2599b074826389031ff15ec9a00
BLAKE2b-256 49c3c1f244c02805f1ae3311cbb8fe659cb58359583e7c5b80a4df5415851dab

See more details on using hashes here.

File details

Details for the file org_slashlib_py_configloader-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for org_slashlib_py_configloader-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f2ed2e300394a60b2090f8b51644a957f09dc4088bb535724f2fa98c5a54813f
MD5 4f161fbe6e6728510b5e8b229ef39bc8
BLAKE2b-256 610bb7346b802c927822fb6a2e0659a9ad5be052f477b0501d75089b058a8d0a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page