Configer
This is the repository for the package CONFIGER helps with easy configuration of arguments in a python code.
Introduction
When Python programs grow large, one would eventually need a way to load configurations through a file. The common answer to this would by Python's ConfigParser. But at least I find the result of using ConfigParse an ugly code:
import ConfigParser
Config = ConfigParser.ConfigParser()
Config.read("c:\\tomorrow.ini")
Config.get(section, option)
That's why I packaged my solution to this issue. Configer basically gives you a flattened ConfigParser with extra functionality:
- dot-access of values in the settings file
- dump settings to a file for later use
- add different settings while choosing to overload previous one.
Dependencies
This package is written for Python 2.7.
The only dependency is configparser and will be installed automatically by the setup.py.
Installation
In the root directory, type in
pip install .
Examples
Overall Configer will be a sleek way to disentangle settings away from the mechanics. An exact copy of the above code will be:
from configer import Configer
Config = Configer(default_ps_fname='c:\\tomorrow.ini')
Config.option
Note that you don't have sections anymore and you can access an option with a dot-access approach.
Other use cases would be:
-
Loading default settings
default_ps_fname = 'pyconfiger/Configer/test/sample_settings.ini' ps = Configer(default_ps_fname=default_ps_fname) print(ps.status) # None -
Loading default settings while adding new arguments
ps = Configer(default_ps_fname=default_ps_fname, status=False) print(ps.status) # False ps.status = True print(ps.status) # True ps.new_status = True print(ps.new_status) # True -
Loading default settings while initializing with a dictionary of arguments
ps = Configer(default_ps_fname=default_ps_fname, status=False,**{'somethings': [1.0, 2.0]}) print(ps.somethings) # [1.0, 2.0] -
Adding and overloading with a second Configer instance
ps1 = Configer(status=False) ps2 = Configer(status=True, othersetting = 'this') ps3 = ps1 + ps2 print(ps3.status) # False print(ps3.othersetting) # 'this' ps4 = ps1.overload(ps2) print(ps4.status) # True -
Dumping current Configer instance as an .ini file
ps = Configer(default_ps_fname=default_ps_fname, status=False) print(ps.status) # False ps.dump_settings(fname='~/settings.ini') # saves the settings to the specified file
Tests
To run the tests, type in in the root directory:
python -m unittest discover
License
See LICENSE.txt
Author
Nima Ghorbani, nima.ghorbani@tuebingen.mpg.de
Metadata
Release files for configer 1.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| configer-1.3.1.tar.gz | 4.1 kB | Details |
Release files / configer-1.3.1.tar.gz
| Download URL | configer-1.3.1.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e560406b9bd0b9c5f98c205b84708f2225421f53f9dd67b9211cdaa0c6ff1b3b
|
|
BLAKE2b-256 checksum How to use checksums |
49e1cc2e7500059abce39fe0b95e57047dc52076c7171dadba650ae09e07ca0b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/2.7.15rc1
|