Skip to main content

A simple configuration file manager for python

Project description

# Simple Config

A simple configuration file manager for python. Best suited for simple scripts that need
to take user defined configuration parameters.

Configuration is saved in JSON format to a file of your chosing.

## Why?

This is mostly intended to be used in quick and dirty scripts and simple CLI apps.
This does not intend to replace `configparser`. There are instances where I feel
that bootstrapping `configparser` is an overkill. This is where `simple_config` chips in.

## Installation

Install if using `pipenv` by running the command below.

pipenv install simple-config

Or, if you are not using `pipenv`, run the following:

pip install simple-config

## Usage

`simple-config` provides a `Config` class. It is intended to be instantiated
at the module level once and used the instance everywhere.

Put this in a file called ``:

from simple_config import Config

default_settings = {
"is_registered": True,
"token": "aK3NJe3PnXJr"
settings = Config("/path/to/config.json", defaults=default_settings)

Here, the first argument is the path to the configuration file.
The `defaults` keyword argument takes the default configuration
options for your app.
If the config file does not exist, it will be created and populated
with the default values.

Now, import the instance of `Config` i.e. `settings` wherever necessary and use:

from config import settings


### Mutating the config

Sometimes there might be a need to update the config, e.g. to save state of
the app. The `Config` class provides `update` instance method.


The update method will update the parameters and write it to the config
file as well.

## Multiple configs

There can exist more than one `Config` instance in an application. For example,
the application auto-generated state can be saved in one file and user's config
can be saved in another instance.

## Run the tests

Go to the root of this project and run:

python -m unittest discover

## Similar projects

* [yapconf](

Project details

Download files

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

Files for simple-config, version 1.0.1
Filename, size File type Python version Upload date Hashes
Filename, size simple-config-1.0.1.linux-x86_64.tar.gz (2.5 kB) File type Source Python version None Upload date Hashes View
Filename, size simple_config-1.0.1-py2.py3-none-any.whl (4.9 kB) File type Wheel Python version py2.py3 Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page