Skip to main content

This package provides a configuration base class to be extended with list of KEYS (same prefix) that could be overridden by environment variables.

Project description

configprops

Introduction

This package provides a configuration base class to be extended with list of KEYS (same prefix) that could be overridden by environment variables.

API

class ConfigurationProperties(key_name_prefix:str, dot_env:bool=False, debug=False):
 ...

flag dot_env means loading .env file.

Examples

#!/usr/bin/env python3

from configprops import ConfigurationProperties
import os


class AppTestConfig(ConfigurationProperties):
    TEST_APP_CONFIG_KEY_TEXT = 'Original'
    TEST_APP_CONFIG_KEY_BOOL = True
    TEST_APP_CONFIG_KEY_INT = 32
    TEST_APP_CONFIG_KEY_FLOAT = 3.3
    TEST_APP_CONFIG_KEY_OTHER = 55


def test_override():
    os.environ['TEST_APP_CONFIG_KEY_BOOL'] = '0'
    os.environ['TEST_APP_CONFIG_KEY_FLOAT'] = '8.5'
    os.environ['TEST_APP_CONFIG_KEY_INT'] = '185'

    config = AppTestConfig('TEST_APP_CONFIG_')

    assert config.TEST_APP_CONFIG_KEY_BOOL == False
    assert config.TEST_APP_CONFIG_KEY_OTHER == 55
    assert config.TEST_APP_CONFIG_KEY_FLOAT == 8.5
    assert config.TEST_APP_CONFIG_KEY_INT == 185

Project details


Download files

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

Files for configprops, version 1.5.1
Filename, size File type Python version Upload date Hashes
Filename, size configprops-1.5.1-py3-none-any.whl (3.2 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size configprops-1.5.1.tar.gz (3.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page