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 merges command-line flags, environment variables, and YAML/JSON files into a single, deep-merged configuration object. The object is always a singleton 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
        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',
    UIConfig,
    globals(),
    root=False,
)

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',
    CoolAppConfig,
    globals(),
    publish_to=('ui_layer.config',),
)

Running the application:

python cool_app/main.py --help

prints all flags exactly once.

4 · Access the config

from cool_app import config
print(config.library_path)

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 and 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 do not affect the singleton.

License

This repository ships under 0BSD; see LICENSE.

Licensing / provenance notice

This repository may include AI-generated material and minimal human-authored material. To the extent any portion of this repository is not copyrightable, it is made available without restriction.

No third-party source or license texts are currently bundled in-tree. Any third-party material added later remains subject to its original terms.

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.5.tar.gz (11.7 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.5-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: confumo-0.1.5.tar.gz
  • Upload date:
  • Size: 11.7 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.5.tar.gz
Algorithm Hash digest
SHA256 ec1e4ddf481d142fe8b563aa4da4201251e628fa5de6b76a5f75d742fe5f282b
MD5 8707162bf3b7b99742abbb477445fbb5
BLAKE2b-256 8466f5a10af1b0af7ae4c22dac68f7c2d577ef36092c65527f72e5897a73fb12

See more details on using hashes here.

File details

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

File metadata

  • Download URL: confumo-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 11.6 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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 7d098942414025946134b4330c7c991cc238ea843369408875ea3d1560781de2
MD5 976ba65c5adc52be5d6d1f6c17b6aa1b
BLAKE2b-256 053ca7698abeb3f2fe247b37665abbaf78eca0e019b902667663909df0219653

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