Skip to main content

simply store/load/modify user configurations

Project description

pyscfg - Python Simple Configuration

A simple solution to store/load/modify user configurations for your Python project.

version: 0.1.0
contributors: suppetia

Setup

installing via pip

pip install pyscfg

installing from source

git clone https://github.com/suppetia/pyscfg.git
cd pyscfg
python setup.py install

Simple Usage

from pyscfg import SimpleConfigs

# uses file 'configs.yml' (default) to store the user configurations
cfg = SimpleConfigs()

# set configurations depending on user preferences
if user_chooses_this:
    cfg["num"] = 1
else:
    cfg["num"] = -1

Specify a path to configuration file.

# uses file 'configs.yml' in subdirectory 'data' to store the user configurations
cfg = SimpleConfigs("data/configs.yml")

Use default values for your configurations stored in a dictionary. These values will be assigned if the keys aren't in the configurations already. The configurations file is updated.

from pyscfg import SimpleConfigs


defaults = {
    "foo": "John",
    "bar": "Doe",
    "num": 0
}

# uses file 'configs.yml' (default) to store the user configurations
cfg = SimpleConfigs(defaults=defaults)

print(cfg["num"]) # prints 0

if user_chooses_this:
    cfg["num"] = 1
else:
    cfg["num"] = -1

print(cfg["num"]) # prints 1 or -1

You can also write your defaults into a configuration file (supported: YAML, JSON) and pass it to the constructor.

# uses file 'default_cfg.yml' in subdirectory 'data' to load the default configuration values
cfg = SimpleConfigs(defaults="data/default_cfg.yml")

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

pyscfg-0.1.0.tar.gz (3.2 kB view hashes)

Uploaded Source

Built Distribution

pyscfg-0.1.0-py3-none-any.whl (3.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page