Skip to main content

Configuration Manager

Project description

dwgriffin-config

dwgriffin's config library.

Installation

python3 -m pip install dwgriffin-config

Classes

ConfigManager

Takes a dictionary of default settings. Merges configuration settings from defaults, config file, environment variables, and CLI arguments.

Usage

import argparse
import os
from dwgriffin_config import ConfigManager


parser = argparse.ArgumentParser(description="An example CLI tool")
parser.add_argument("--timeout", type=int, default=None)
parser.add_argument("--flags", type=bool, default=None)
parser.add_argument("--hostname", type=str, default=None)
args = parser.parse_args()

defaults = {
    "timeout": 300,
    "flags": False,
    "hostname": "example.com",
}
os.environ["APP_TIMEOUT"] = "600"

config = ConfigManager(
    defaults = defaults,
    config_file = "./config.ini",  # sets "hostname = example2.com"
    env_prefix = "APP_",
    cli_args = args,
)

print(config.all())

produces:

{'timeout': 600, 'flags': False, 'hostname': 'example2.com'}

License

GNU General Public License v3.0 or later

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

dwgriffin_config-0.1.0.tar.gz (42.2 kB view details)

Uploaded Source

Built Distribution

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

dwgriffin_config-0.1.0-py3-none-any.whl (30.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dwgriffin_config-0.1.0.tar.gz
  • Upload date:
  • Size: 42.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for dwgriffin_config-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e59e3817948d07ece95e095162690d9e4641d81f028cb4a5bb210e4907c15093
MD5 1433e1ad53dd96d0686c8241062b2def
BLAKE2b-256 f4bea3c9cadb3241083901a0b27db0dc64814f2d7d36c0180755aa2a4de526fe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dwgriffin_config-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 315fccd21e43877747fbc56c92a12d06ad473756350d4f5a30623bae422189b6
MD5 d7f889af121c89d2d923f7c035a3aba6
BLAKE2b-256 c18d7577b395607a16b8807f165dee69b7643026bd0f47596b81ac3aef415303

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