Skip to main content

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

Project description

Summary

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

PyPI package version Supported Python versions Supported Python implementations

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.5+

Optional Dependencies

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

appconfigpy-1.0.2.tar.gz (7.4 kB view hashes)

Uploaded source

Built Distribution

appconfigpy-1.0.2-py3-none-any.whl (7.9 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page