Skip to main content

YouConfigMe helps you manage config in a pythonic way

Project description

YouConfigMe

PyPI - Downloads PyPI GitHub Workflow Status GitHub Workflow Status Code style: black

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. I prefer to go as close as possible to the Twelve Factor App guide since it's what most people expect anyways.

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.

Motivation

The main motivation for youconfigme to exist is that most simple config libraries do not take sections into account. And it bugs me greatly.

Install

Clone this repo, and install it.

pip install .

Or from PyPI.

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.

You might find nox quite useful to run tests and ensure linting is as expected.

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.

Config discovery

The preferred order should be:

  1. Environment variables
  2. Config file
  3. Default value

Quickstart

Assume you have an .ini file at the root of your project that looks like this:

[a]
key1=1
key2=2
key7=7

[b]
key3=3
key4=4

You can use it like this:

from youconfigme import AutoConfig
import os

os.environ["A_KEY4"] = "key4value"
os.environ["A_KEY7"] = "key7value"
config = AutoConfig()


print(config.a.key1())				# returns '1'
print(config.a.key1(cast=int))			# returns 1
print(config.a.key2(default='default2val'))	# returns '2'
print(config.a.key3())				# raises ConfigItemNotFound
print(config.a.key3(default='key3value'))	# return 'key3value'
print(config.a.key4())				# returns 'key4value'
print(config.a.key7())				# returns 'key7value'

Project details


Download files

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

Source Distribution

youconfigme-0.6.13.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

youconfigme-0.6.13-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file youconfigme-0.6.13.tar.gz.

File metadata

  • Download URL: youconfigme-0.6.13.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for youconfigme-0.6.13.tar.gz
Algorithm Hash digest
SHA256 f94743cd88e5b039f3a0452f6c4af6cfa8029641f8c87960221a5db38ab5d89b
MD5 0b762c13efcb91b761b08654c737a798
BLAKE2b-256 0c402e029dadc42eb656a5c952674602bc98c5b6bd3028800b504f14859981e2

See more details on using hashes here.

File details

Details for the file youconfigme-0.6.13-py3-none-any.whl.

File metadata

  • Download URL: youconfigme-0.6.13-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for youconfigme-0.6.13-py3-none-any.whl
Algorithm Hash digest
SHA256 7095bc0e0f80c736a91e88e07fdb831ddea286b5e4d76b37846a8f29db4cdff1
MD5 aef8ef6470be036c3e7d90a91f97b4b9
BLAKE2b-256 388a0b9250ff0950b00751aa498310b93f4227250c0bacddcf88f38de11b3bf3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page