Skip to content

thombashi/appconfigpy

Repository files navigation

appconfigpy

Summary

A Python library to create/load an application configuration file.

PyPI package version

Supported Python versions

Supported Python implementations

CI status of Linux/macOS/Windows

Installation

Install from PyPI

pip install appconfigpy

Install from PPA (for Ubuntu)

sudo add-apt-repository ppa:thombashi/ppa
sudo apt update
sudo apt install python3-appconfigpy

Usage

Create a configuration file from user inputs

# configure.py

from appconfigpy import ConfigItem, ConfigManager, DefaultDisplayStyle

app_config_mgr = ConfigManager(
    config_name="example",
    config_items=[
        ConfigItem(
            name="token",
            initial_value=None,
            prompt_text="API Token",
            default_display_style=DefaultDisplayStyle.PART_VISIBLE,
        ),
        ConfigItem(name="path", prompt_text="ABC Path", initial_value="."),
    ],
)

app_config_mgr.configure()
$ ./configure.py
API Token: abcdefghijklmn
ABC Path [.]:
$ cat ~/.example
{
    "path": ".",
    "token": "abcdefghijklmn"
}

Load a configuration file

# load.py

from appconfigpy import ConfigItem, ConfigManager, DefaultDisplayStyle

app_config_mgr = ConfigManager(
    config_name="example",
    config_items=[
        ConfigItem(
            name="token",
            initial_value=None,
            prompt_text="API Token",
            default_display_style=DefaultDisplayStyle.PART_VISIBLE,
        ),
        ConfigItem(name="path", prompt_text="ABC Path", initial_value="."),
    ],
)

print(app_config_mgr.load())
$ ./load.py
{'token': 'abcdefghijklmn', 'path': '.'}

Dependencies

Python 3.7+

Optional Dependencies