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.1.tar.gz (45.9 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.1-py3-none-any.whl (31.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: confumo-0.1.1.tar.gz
  • Upload date:
  • Size: 45.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for confumo-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f37215481bf42d5a68029d2a62b4a4cb58e4339fa0d2d98d77e8b7fa417a1e4d
MD5 c1d5d6097dfbc3bcdaebd7602b9e88cc
BLAKE2b-256 ee39fe1bffb5a9831bbf8bcde911e45b5a6fed86f5cc8578ef45ef43771dce74

See more details on using hashes here.

Provenance

The following attestation bundles were made for confumo-0.1.1.tar.gz:

Publisher: publish.yml on actx4gh/confumo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: confumo-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 31.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for confumo-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e5d43225fa9575044ca105b37e98f0aa231f5c84309dcaf1a0d61ad84bdf170e
MD5 6d2d9852bf2ddda652b1dd530af91b04
BLAKE2b-256 ee63d3765460fdf1961b100c397669c6ef39b77d5c93601d47c4a13f7799431c

See more details on using hashes here.

Provenance

The following attestation bundles were made for confumo-0.1.1-py3-none-any.whl:

Publisher: publish.yml on actx4gh/confumo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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