Skip to main content

Smart tiny config library for flask-like config

Project description

desing_config.py

Smart tiny config library for flask-like config

How to install

pip install design_config

You can find source code of library on GitHub

How to use

import os
from design_config import DesignConfig, D, ___

class Config(DesignConfig):

    """ is D("") """
    PROP_ZERO = ___
    
    """ is 'hello' """
    PROP_ONE = 'Hello'

    """ 'World' if in init_data_dict not PROP_TWO
    As usually init_data_dict is os.environ """
    PROP_TWO = D('World')

    """ 'Hello World!' or 'hello {PROP_TWO}!' for any PROP_TWO """
    PROP_THREE = '{PROP_ONE} {PROP_TWO}!'


config = Config()

If your global environment variables contain $PROP_TWO , it will be replaced in the config with the appropriate value. Otherwise, it will remain by default (World)

D means "default"

config.PROP_THREE # "Hello World!"

config['PROP_THREE'] # "Hello World!"
config['{PROP_THREE}!!'] # "Hello World!!!"
config['{PROP_FOUR}'] # "PROP_FOUR"

config('{PROP_ONE} Tom') # "Hello Tom"
config('PROP_FOUR', 'London') # "London"
config('PROP_TWO', 'London') # "World"
config('{PROP_ZERO}', 'London') # ""
config('{PROP_FOUR}', 'London') # "PROP_FOUR"

config.path('{PROP_ONE}', 'some_folder', '{PROP_TWO}2') # os.path.join("Hello","some_folder","World2")

You can use DesignConfig with Flask like that:

class MyFlaskConfig(DesignConfig):

    VERSION = '2'

    FLASK_DEBUG = D(True)
    IS_PRODUCTION = D(False)
    DEBUG = D(True)

    PROJECT_PATH = D('/base')

    REDIS_HOST = D('localhost')
    REDIS_PORT = D('6379')

    """..."""

config = MyFlaskConfig()

my_flask_app = Flask(__name__, static_folder='static', static_url_path='')
my_flask_app.config.from_object(config)

"""..."""

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

design_config-0.0.3.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

design_config-0.0.3-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file design_config-0.0.3.tar.gz.

File metadata

  • Download URL: design_config-0.0.3.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for design_config-0.0.3.tar.gz
Algorithm Hash digest
SHA256 23e6026464410c70fa1dd0ea7b763aae09cf43caff6300a5974064ae5c9269d9
MD5 411e3f349296aa4e1fb864e3a38d875d
BLAKE2b-256 7d5b8f077e8c5d34e027b7be97555107369175de1ad7aeb067aa77f40a4aa62e

See more details on using hashes here.

File details

Details for the file design_config-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for design_config-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 78bf07ded02631abcc75962e5888b9db1b8d1dc1dfe96268b45b9091fd67caff
MD5 8d98855f32497ada20be61078a447b34
BLAKE2b-256 0e94695cfa416768cc319ae7e7795c07b02e9074f70a91b10ffd06d5582dcac2

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