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"

Also you can use int, bool, and float values:

class Config(DesignConfig):

    PROP_FIVE = D(55)

    PROP_SIX = D(True)

    PROP_SEVEN = D(7.7)

config = Config({
    'PROP_FIVE': '5', 
    'PROP_SIX': 'FALSE',
    'PROP_SEVEN': '7e7'
})

config.PROP_FIVE # 5
config.PROP_SIX # False
config.PROP_SEVEN # 7e7

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.8.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

design_config-0.0.8-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: design_config-0.0.8.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.6

File hashes

Hashes for design_config-0.0.8.tar.gz
Algorithm Hash digest
SHA256 a5f247d557f9c6ec2a0ed76619e15a75371305d9866a901c555cec1bccf3a3e9
MD5 e7600a9e10b3aa8981df692a31229e30
BLAKE2b-256 5f32f6027efa966e17bf447cd5c3dcff6e538684be05db2f6754c8883dd43e07

See more details on using hashes here.

File details

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

File metadata

  • Download URL: design_config-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.6

File hashes

Hashes for design_config-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 74c28b9df165a0329292dc5598ddd0188ee156a7c646dc5093e90d31fc87a6af
MD5 9bf1f389542538f75daf1e7b457b9954
BLAKE2b-256 09beb9f62f280f834867b02941df126b63639b382df063dd0d1a7c3afe444d8e

See more details on using hashes here.

Supported by

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