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.1.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.1-py3-none-any.whl (30.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dwgriffin_config-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 2a03f307445f945bb86dd680e249321cd59fe1fa7ce1e22f81b7551cd569f379
MD5 c46e72c8ca0f23e32730626aa9b1dc55
BLAKE2b-256 b46e54cfb77075647b04fb5f469b6091938d17db9822dc96edb9ce44f1b1da55

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dwgriffin_config-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f84930ae908f0fe3fa0332036595e7040a3e38f1d3c27f0982bea53774db37e1
MD5 246b29584005987980bc9663bce6b926
BLAKE2b-256 170241cc5c0d7de22b7392973dbc2c05deb89623d4c32a7faf7a1767fed120d9

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