Skip to main content

A lightweight, layered configuration management library for Python that merges constants, default YAML files, and user-provided configs with optional fallback control.

Project description

jps-config-manager

Build Publish to PyPI codecov

A lightweight, layered configuration management library for Python that merges constants, default YAML files, and user-provided configs with optional fallback control.


🚀 Overview

jps-config-manager provides a clean, unified configuration system for Python applications and CLI tools.
It supports:

  • A project's Python constants (e.g., constants.py)
  • A default configuration YAML file
  • A user-supplied configuration file provided via --config-file
  • Optional fallback behavior (enabled by default, user-controlled via default_fallback: false)
  • Strong validation and typed accessors

It is ideal for applications that require predictable, validated, hierarchical configuration loading (e.g., pipelines, services, CLI utilities).


✨ Features

✅ Layered Configuration

Configuration is merged in the following order:

  1. Project defaults (constants.py)
  2. Default YAML file (e.g., conf/config.yaml)
  3. User-provided YAML file (--config-file)

Later layers override earlier ones.

✅ Optional Fallback Support

Users may disable fallback entirely:

behavior:
  default_fallback: false

When disabled, all required values must be explicitly provided. Missing keys raise descriptive validation errors.

✅ Singleton Manager

A global configuration object ensures consistent access across your application:

from jps_config_manager import ConfigManager

cfg = ConfigManager.instance()

✅ Typed Getters

Strongly-typed retrieval:

  • get_str()
  • get_int()
  • get_float()
  • get_bool()
  • get_list()
  • get_path()
  • get_file()
  • get_dir()

✅ YAML Loading + Validation

Includes robust YAML loading (safe_load) and validation of required config keys.

✅ Dotted-Path Access

Native support for hierarchical lookups:

cfg.get("pipeline.depth_metric")

📁 Example Project Integration

Project directory layout

project_a/
├── src/project_a/
│   ├── cli.py
│   ├── constants.py
│   ├── main.py
│   └── ...
├── conf/config.yaml
└── pyproject.toml

constants.py

DEFAULTS = {
    "pipeline": {
        "depth_metric": "median",
        "trim_prop": 0.1,
    },
    "paths": {
        "reference": "/opt/ref.fasta"
    },
    "behavior": {
        "default_fallback": True,
    }
}

CLI entrypoint (cli.py)

import typer
from jps_config_manager import ConfigManager
from project_a import constants

app = typer.Typer()

@app.command()
def run(config_file: str = typer.Option(None, "--config-file")):
    ConfigManager.initialize(
        project_defaults=constants.DEFAULTS,
        default_config_file="conf/config.yaml",
        user_config_file=config_file,
    )

    run_pipeline()

Using the configuration in the application

from jps_config_manager import ConfigManager

def run_pipeline():
    cfg = ConfigManager.instance()

    metric = cfg.get_str("pipeline.depth_metric")
    trim = cfg.get_float("pipeline.trim_prop")
    ref  = cfg.get_file("paths.reference")

    print("Using:", metric, trim, ref)

🧪 Example Usage (Minimal)

Using fallback (default)

pipeline:
  depth_metric: trimmed_mean

Result configuration:

  • depth_metric → "trimmed_mean"
  • trim_prop → 0.1 (default)
  • behavior.default_fallback → True

Disabling fallback

behavior:
  default_fallback: false

pipeline:
  depth_metric: trimmed_mean

Missing trim_prop will raise:

ValueError: Missing required configuration value at: pipeline.trim_prop

📦 Installation

pip install jps-config-manager

Or from source:

make install

🧪 Development

make fix && make format && make lint
make test

The test suite includes:

  • YAML loader tests
  • Deep merge tests
  • Fallback logic tests
  • Validation tests
  • ConfigManager singleton tests
  • Typed getter tests
  • Path resolution tests

📜 License

MIT License © Jaideep Sundaram

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

jps_config_manager-0.0.0.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

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

jps_config_manager-0.0.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file jps_config_manager-0.0.0.tar.gz.

File metadata

  • Download URL: jps_config_manager-0.0.0.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for jps_config_manager-0.0.0.tar.gz
Algorithm Hash digest
SHA256 fe611bac39f846f8da67d6fcfd862ba78fe99b61c8a86bc125c88a332aacab90
MD5 c074481cfe388ee8b468a3433afa2a6d
BLAKE2b-256 c38b82b3c02e1cc37c482a729e92f1a1e65690de39f14f4098839733511e35df

See more details on using hashes here.

File details

Details for the file jps_config_manager-0.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for jps_config_manager-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d1421e10a6ce848e52df95e5e05a161d7387da973d73b0eacf84f975f264b548
MD5 7e32cf8da2a085416507927e3350adb4
BLAKE2b-256 e8198af07f90ce4c0b0eab5f9463099866e96b81024552c4008f67aed9917fba

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