Skip to main content

Platform-aware configuration management (CLI flags + env + YAML/JSON deep-merge)

Project description

Confumo

Confumo derives from "Confuse more". It's a thin python module that acts like a framework to command‑line flags, environment variables, and YAML/JSON files into a single, "deep‑merged" configuration object. The object is always a singleton (one per application name) and can be exposed at module scope so existing code keeps working.

One line to register your flags, one line to expose the config to the rest of your project.


Highlights

Description
Merged sources argparse • ENV vars • YAML/JSON • defaults
Singleton registry Only one ArgumentParser run per app_name
Auto flag inheritance Base class + mix‑ins + leaf class all show up in --help
Lazy “print‑once” help Libraries defer --help; root application prints merged help
Module‑level proxy from my_app.config import log_level still works
Deep‑merge Powered by confuse
Cross‑platform paths Uses platformdirs

Installation

pip install confumo

1 · Define a config class

# ui_layer/config.py
import argparse
from confumo import Confumo

class UIConfig(Confumo):
    def add_args(self, p: argparse.ArgumentParser):
        p.add_argument('--theme',   choices=['light', 'dark', 'auto'], default='auto')
        p.add_argument('--font',    default='Roboto')

    def _init_subclass(self):
        self.theme = self.args.theme                 # CLI / env / YAML
        self.font  = self.cfg['font'].get(str)

    def to_dict(self):
        return {'theme': self.theme, 'font': self.font}

2 · Expose it (library mode)

UIConfig is meant to be reused by many apps, so the library defers --help printing:

# ui_layer/config.py  (bottom of file)
config = Confumo.expose(
    'ui_layer',          # app_name
    UIConfig,            # concrete subclass
    globals(),
    root=False           # ← do *not* print help here
)

Now any package can do:

from ui_layer import config
print(config.theme)

and the singleton is shared process‑wide.


3 · Extend it in an application

# cool_app/config.py
import argparse
from confumo import Confumo
from ui_layer.config import UIConfig

class CoolAppConfig(UIConfig):
    def add_args(self, p: argparse.ArgumentParser):
        p.add_argument('--log_level', default='INFO',
                       choices=['DEBUG','INFO','WARNING','ERROR','CRITICAL'])
        p.add_argument('--library_path', default='~/Pictures')

    def _init_subclass(self):
        super()._init_subclass()
        self.log_level    = self.cfg['log_level'].get(str)
        self.library_path = self.cfg['library_path'].get(str)

    def to_dict(self):
        base = super().to_dict()
        base.update({'log_level': self.log_level,
                     'library_path': self.library_path})
        return base

config = Confumo.expose(
    'cool_app',        # same as CLI program name
    CoolAppConfig,
    globals(),
    publish_to=('ui_layer.config',)   # make ui_layer widgets see the same instance
)  # root=True by default → prints merged --help

Running the application:

python cool_app/main.py --help

prints all flags (--theme, --font, --log_level, --library_path, …) exactly once.


4 · Access the config

from cool_app import config               # module‑level shortcut
print(config.library_path)

# or, import‑order‑safe lookup
from confumo import Confumo
cfg = Confumo.get('cool_app', CoolAppConfig)

Both lines refer to the same singleton.



Precedence order

  1. CLI flags (--foo bar)
  2. Environment variables (COOL_APP__FOO=bar)
  3. YAML file (-c settings.yml) or default path
  4. Defaults hard‑coded in your subclass

confuse handles deep‑merging dicts & lists.


Persist the merged config

path = config.save_yaml()  # ~/.config/cool_app/cool_app_config.yaml (Linux)

The file contains the fully merged state for later inspection.


Testing helpers

config.copy() returns a shallow clone whose attribute changes don’t affect the singleton.


License

AGPLv3 (see LICENSE)

Under the AGPLv3, any modified version or derivative work that is used, especially in a networked or distributed environment—by a school, company, or other organization—must also be licensed under the AGPLv3, with its source code made available to users.

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

confumo-0.1.3.tar.gz (47.6 kB view details)

Uploaded Source

Built Distribution

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

confumo-0.1.3-py3-none-any.whl (34.8 kB view details)

Uploaded Python 3

File details

Details for the file confumo-0.1.3.tar.gz.

File metadata

  • Download URL: confumo-0.1.3.tar.gz
  • Upload date:
  • Size: 47.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for confumo-0.1.3.tar.gz
Algorithm Hash digest
SHA256 549fa36d099140719d05d5435b49a63f21ec35e1bf781e71da7a8b1a0cf08aaf
MD5 38ba215861ce2e2cff90c11be5373ab6
BLAKE2b-256 794f9a5f5a9979115ec4ab3e0c44ae809db0cec4f8c0d5e8d443309d8fe36aac

See more details on using hashes here.

File details

Details for the file confumo-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: confumo-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 34.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for confumo-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 aaf852ee3f7078490025ff0891346ea27838802aebe9f6b84f92116e3dc6726a
MD5 1ce99601a206764648c659868126b9fb
BLAKE2b-256 d0f14526d80d47fdfffcb40d84edd6bc0ef7101d460a6b6e82e1a13c35a7b839

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