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.
```bash
pipenv install simple-config
```
Or, if you are not using `pipenv`, run the following:
```bash
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 `config.py`:
```python
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:
```python
from config import settings
print(settings.token)
```
### 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.
```python
settings.update(token="Ju901jK1Rb")
```
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
python -m unittest discover
```
## Similar projects
* [yapconf](https://github.com/loganasherjones/yapconf)
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.
```bash
pipenv install simple-config
```
Or, if you are not using `pipenv`, run the following:
```bash
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 `config.py`:
```python
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:
```python
from config import settings
print(settings.token)
```
### 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.
```python
settings.update(token="Ju901jK1Rb")
```
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
python -m unittest discover
```
## Similar projects
* [yapconf](https://github.com/loganasherjones/yapconf)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file simple-config-1.0.1.linux-x86_64.tar.gz
.
File metadata
- Download URL: simple-config-1.0.1.linux-x86_64.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9588085ebb82a9b6ec21d60917c908acda68da6473eb2ac6178f9f3b59ebf16 |
|
MD5 | abee887903bea3a51c2dce9dda3d5ded |
|
BLAKE2b-256 | 5505a0f51d7c29920f91330ce87707bf0fa6f769e2838c1c434a311cbc2d56d7 |
File details
Details for the file simple_config-1.0.1-py2.py3-none-any.whl
.
File metadata
- Download URL: simple_config-1.0.1-py2.py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06e62440ae51a49073935d84cf21d2fb3c812d3bec6dce392e0b36cd4e1f487c |
|
MD5 | d1ba6860e51eb00f8befee5d972a44f4 |
|
BLAKE2b-256 | 639d250327515576377d533be41e566f3b27fdbf9d1f88545def24fd2e44fc44 |