Skip to main content

A thin and smart config provider for python apps

Project description

QuickConfig


Description

QuickConfig is a super lightweight dynamic config provider for python applications. The config provider uses a runtime config that can be imported to any part of your application. quick_config parses and loads your environment configs only once based on the runtime environment, and the built configs can be imported anywhere in your application!

Features

  • Builds modular configs which overwrite a base config based on the config required for the application run time environment. Ex: the base config will be overwritten by the development config if the app is running in the local or development runtime environment.
  • Has a built-in API for queryable environment flags like config.is_dev() or config.is_prod() for environment specific code paths
  • Creates a simple logger with a console and file handler at application run time which can be used anywhere in the application after importing the quick_config config.
  • Creates callable methods on the globally loaded config object which mirror the names of the configs allowing engineers to call the methods in the app for their values instead of doing config lookups
    • Allows for indexable accessors to configs which are collections. I.e., lists, tuples or maps/dictionaries

Installation

$> pip install quick_config

Design

The quick config provider relies on a standard structure for an application's configurations. All configurations must be provided in a config directory. Configs in the config directory must follow the standard deployment configuration names like staging.py or test.py or production.py. Once the runtime environment is set via an environment variable called environment, the config provider will read that and populate the configs available to the entire application as callable methods which can also be indexed if the provided congig is a collection (list, tuple, or map).

Usage

  1. Create an application like a Django/Flask Application which has runtime configs which may differ for each run time environment using the following nomenclature:
    • create a directory called config
    • create files in the directory with the following structure
    # config/base.py:
    import os
    
    ENV_VARS = {
        "some_api_key": os.environ.get('my_api_key'),
         "db_name": "my_default_db",
         "db_driver": "inmemory_sqlite",
         "important_array": ['a', 'b', 'c', 'd']
    }
    
    # config/production.py:
    import os
    
    ENV_VARS = {
         "db_name": os.environ.get("production_db"),   # overwrites base.py
         "db_driver": "mysql",
         "important_array": [1, 2, 3, 4]  # overwrites base.py
    }
    
    # config/development.py: 
    ENV_VARS = {
         "db_name": "my_dev_db",
    }
    
    • Note the use of ENV_VARS in each environment file. That is required
  2. Install the quick_config package pip install quick_config
  3. Use the environment vars in your application directly:
# in my_app/my_module/file.py
from quick_config import config

class MyModule:    
    def __init__(self):
        self.logger = config.get_logger()
        self.api_key = config.some_api_key()

        # depending on environment, this will change
        self.important_index_value = config.important_array(0)

db_connection_info = {
    "db_name": config.db_name(),
    "driver": config.driver(),
}

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

quick_config-0.2.4.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

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

quick_config-0.2.4-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file quick_config-0.2.4.tar.gz.

File metadata

  • Download URL: quick_config-0.2.4.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.1

File hashes

Hashes for quick_config-0.2.4.tar.gz
Algorithm Hash digest
SHA256 12fcd2ceda09c4de8a4cde0ea3111f6534a9b3cd2cdc11abd99344bf77020e26
MD5 10324b852975872a76421ef1a048d218
BLAKE2b-256 d26466b507f7e8254ab43fa3856451faa721662a3d7e087b27dd2673ccc9f909

See more details on using hashes here.

File details

Details for the file quick_config-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: quick_config-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.1

File hashes

Hashes for quick_config-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 648c7ba9255e90ba92b5f71c76e60694761f56d3db91a21785c9f0de9e47b337
MD5 49f3ce9de922a76eb17c0fa45fae2e38
BLAKE2b-256 d5d207f75d8ad3cb76d4c4cd788a3e28be3d499a89e16fe1f118e94eade83cf6

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