A module for retrieving program settings from various sources in a consistant method.
Project description
setoptconf is a Python library that can be used to retrieve program settings from a variety of common sources:
Command Line
Environment Variables
INI Files
JSON Files
YAML Files
Python Objects/Modules
The goal of this project is to define your desired settings in a simple and consistent way, and then point setoptconf at as many of the sources as you’d like to use, and let it comb them all, looking for your settings.
This README is admittedly very light on details. Full documentation will come in time. For now, here’s an example of its use:
Import the library:
import setoptconf as soc
Instantiate the manager:
manager = soc.ConfigurationManager('myprogram')
Define the settings we’d like to collect:
manager.add(soc.StringSetting('foo')) manager.add(soc.IntegerSetting('bar', required=True)) manager.add(soc.BooleanSetting('baz', default=True))
Retreive the settings from our desired sources, combining the settings and overriding with the priority implied by the order of the sources we pass:
config = manager.retrieve( # This source pulls from the command line using argparse. soc.CommandLineSource, # This source pulls from environment variables that are prefixed # with MYPROGRAM_* soc.EnvironmentVariableSource, # This source pulls from the named INI files. It stops at the first # file it finds. soc.ConfigFileSource(('.myprogramrc', '/etc/myprogram.conf')), )
We now have a Configuration object named config that has three attributes; foo, bar, and baz.
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 setoptconf-0.3.0.tar.gz
.
File metadata
- Download URL: setoptconf-0.3.0.tar.gz
- Upload date:
- Size: 13.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2ecbd27c0c7d0d53990e2df98d9aad6490df8b75b71c621d8c441d6e91e3161 |
|
MD5 | d7ccdb0886877d8b9be91ebd3d0ba39c |
|
BLAKE2b-256 | 78649ba5400dd9a605f2af9c1d2351cf6b9e0a0aa7157d020aa3a11ae3c95ea4 |
File details
Details for the file setoptconf-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: setoptconf-0.3.0-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1fa613dc4a6fbfbaab9a52319d1e369d030e8ed80455b151574ccf3390ec86c6 |
|
MD5 | 199b0405fb3dd5a58e1bc9e0eaf5a793 |
|
BLAKE2b-256 | 3c9892a42f481277db22f527fe4eda593b546eddb76484fdd9c4da9682a88bbd |