YouConfigMe helps you manage config in a pythonic way
Project description
YouConfigMe
YouConfigMe helps you manage config in a pythonic way.
Core ideas
Explicit is better than implicit
There are several ways to define configuration variables, with different levels of explicitness. From most to less explicit:
- Variable defined in config file
- Variable set as env var
Defaults are reasonable
Sometimes you might need a variable to exist even if it hasn't been defined. So, you should be able to provide defaults.
Types are inherent to the variable
Most of the time, variables are defined as strings, on .ini
files or as env vars. But what if your variable is an int
? You should be able to get it as an int
.
Sections are good
Config sections are a good thing: separate your config vars under reasonable namespaces.
Install
Clone this repo, and install it.
pip install YouConfigMe
Development
Start by cloning the repo/forking it.
You should install YouConfigMe's dev packages to help.
pip install .[dev]
pip install .[test]
After that, install the pre-commit hooks:
pre-commit install
This will install several code formatting tools and set them up to run before commits. Also, it will run tests before pushing.
Docs
To update the docs to the latest changes
cd docs
make html
Version bumping
This project uses bump to quickly bump versions.
By default running bump
will bump the patch version. You can bump minor/major versions like so:
bump --minor
bump --major
Tests
The tests
folder contains several tests that run using pytest
that should give you an idea of how to use this.
Quickstart
Assume you have an .ini
file at the root of your project that looks like this:
[a]
key1=1
key2=2
[b]
key3=3
key4=4
You can use it like this:
from youconfigme import AutoConfig, ConfigItemNotFound
import os
os.environ["A_KEY4"] = "key4value"
config = AutoConfig()
print(config.a.key1(cast=int)) # returns 1
print(config.a.key2()) # returns '2'
print(config.a.key3()) # raises ConfigItemNotFound
print(config.a.key3(default='key3value')) # return 'key3value'
print(config.a.key4()) # returns 'key4value'
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
File details
Details for the file youconfigme-0.2.4.tar.gz
.
File metadata
- Download URL: youconfigme-0.2.4.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29adf7cf246bbeb139424dc4e9b23a8aa0f2eebeadfb730a584c4293f974d0b9 |
|
MD5 | 0e3234d2e52615796120e9dc7a9c7c23 |
|
BLAKE2b-256 | 9de0578a79d433713e0a709917756301e8be3aa1f2c6e2cad4d29cefc3dc33c6 |