Skip to main content

`konfetti` provides a framework-independent way for configuration of applications or libraries written in Python.

Project description

codecov Build Version Python versions License

Description

konfetti is a Python configuration management library that simplifies the process of setting up your application to run on your company’s infrastructure.

This library will help you to retrieve secrets from Vault, manages the access to settings required by our monitoring services, such as Datadog and Sentry, and set up tests for evaluating your app’s behavior.

Konfetti manages your app’s configuration settings through lazy evaluation: It only calls and configures what your app needs and when it needs it.

Key benefits:

Configurable lazy evaluation - You can choose the moment when Konfetti will evaluate your the configuration of your app.

Faster & simpler test runs - No need for evaluating the configuration of the whole project if it’s not used.

Faster and flexible testing - Isolating small parts of your application no longer requires you to perform a complete setup for each test.

Integration with popular Web Application Frameworks - Konfetti can seamlessly work with Django, Flask, and Celery.

The interface design and features are heavily inspired by decouple, Django, envparse and dynaconf.

Quickstart

Before Konfetti can perform its tasks, you’ll need to create a settings module and then tell Konfetti the location of this module.

1. Creating the Settings Module

Please find the application settings, for your production, local, or other environments, using the following path: app_name/settings/production.py

Next, please review the below code block and copy the relevant parts in your settings file.

> :warning: Variables need to be named with all uppercase letters, other variables will be ignored

> :warning: If your app requires Vault access, then you’ll need to specify `VAULT_ADDR` and `VAULT_TOKEN` in the settings module

# app_name/settings/production.py
from konfetti import env, vault

VAULT_ADDR = env("VAULT_ADDR")
VAULT_TOKEN = env("VAULT_TOKEN")

DEBUG = env("DEBUG", default=False)
DATABASE_URI = vault("path/to/db")

Apart from the import statement from konfetti import env, vault, you can remove the settings for the features that you don’t use.

If, for instance, you don’t use a database, then you can remove the DATABASE_URI variable. Depending on your settings, it might also be called DB_URI, or similar.

Furthermore, you can remove VAULT_ADDR and VAULT_TOKEN if your app doesn’t require secrets.

2. Configuring the Access Point

# app_name/settings/__init__.py
from konfetti import Konfig, AsyncVaultBackend

config = Konfig(vault_backend=AsyncVaultBackend("/secret/team"))

In your app’s environment variables, please add the KONFETTI_SETTINGS variable with the path to your settings module. In the case of the code block above, it would be:

export KONFETTI_SETTINGS=app_name.settings.production

Alternatively the access point could be initiated from an object, importable string, mapping or a JSON file:

Object

class TestSettings:
    VALUE = "secret"
config = Konfig.from_object(TestSettings, ...)

Importable string

config = Konfig.from_object("path.to.settings", ...)

# If the config is in the same module
SECRET = vault("/path/to")["secret"]
config = Konfig.from_object(__name__, ...)

Mapping

config = Konfig.from_mapping({"SECRET": 42}, ...)

JSON

config = Konfig.from_json("/path/to.json")

Usage

The settings module/class with configuration options shouldn’t be accessed directly, because the aforementioned features are implemented in the access point level.

from app_name.settings import config

async def something():
    await config.DATABASE_URI  # asynchronously taken from Vault
    debug = config.DEBUG  # Usual sync access

Documentation

For full documentation, please see https://konfetti.readthedocs.io/en/latest/

Or you can look at the docs/ directory in the repository.

Python support

Konfetti supports Python 2.7, 3.5, 3.6, 3.7 and 3.8

License

The code in this project is licensed under MIT license. By contributing to konfetti, you agree that your contributions will be licensed under its MIT license.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

konfetti-0.8.0-py2.py3-none-any.whl (26.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file konfetti-0.8.0-py2.py3-none-any.whl.

File metadata

  • Download URL: konfetti-0.8.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 26.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.4

File hashes

Hashes for konfetti-0.8.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0466b4246bb8f59499184bd9b542da3587a0c3938f76b9e8a91113176031047e
MD5 2eeae22b844eab69add891cd07f73b79
BLAKE2b-256 4e20f59a2f9b7ed781b643b463417156996cbeb1516fef9020ebf6c649e98f0a

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