Skip to main content

Introduction

config_bat is a package helps developers easily config the app using config.json file.

Getting Started

  1. Installation process:
pip install config_bat
  1. Usage:

Getting config: if there is no config in config.json, return default_value

from config_bat import config
your_config = config.get("config_key",default_value)

# Get nested config data
# You can get nested dict data for cases that you have many value spread out for the same master key
# Example dict: two mongodb master key config, but only username is different from dev and prod
# The "common" key is readed by default.
# If the config apears both in "common" and other stages, the stage config will be used.

nestedConfig = {
  "common":{
    "mongodb":{
      "host":"localhost"
    },
    "development":{
      "mongodb":{
        "username":"test"
      }
    }
  }
}

host = config.get("mongodb",default_value)["host"] # Return KeyError
host = config.get("mongodb.host",default_value) # Return "test"

The default_value is optional, if default_value is not provided, the function will return None.

  1. API references:

Environment variables:

The package behavior can be overrided by export these environment variables:

CONFIG_PATH: the path to config file. Default: "/config/config.json".

APP_STAGE: define in config.json.

config.json file:

The first level key is the stage of the app. You can define the config nested in those keys.

The "common" key is readed by default. If the config apears both in "common" and other stages, the stage config will be used.

If you want to use environmen variables, place a "$" character before you variable name.

Example of config.json:

{
  "common": {
    // Environmental variables
    "JWT_SECRET": "$SEC_KEY",
    "port": 8080
  },
  "development": {
   // Nested config
    "mongodb": {
      "host": "localhost",
      "user": "dev_user",
      "pass": "dev_pass"
    }
  },
  "production": {
    "mongodb": {
      "host": "your.domain",
      "user": "prod_user",
      "pass": "prod_pass"
    }
  }
}

Release files for config-bat 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for config-bat 0.4.1
File Size Uploaded
config_bat-0.4.1.tar.gz 2.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for config-bat 0.4.1
File Interpreter ABI Platform
config_bat-0.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 6.4 kB

Release files / config_bat-0.4.1.tar.gz

Download URL config_bat-0.4.1.tar.gz
Size 2.7 kB
Tags Source
SHA-256 checksum
How to use checksums
315d7fc9d8e4029e42e918b61ce20959b0ece144591188d44376aee31aa84321
BLAKE2b-256 checksum
How to use checksums
5d80855c65c52c47c93d9a1a17424f010faa98cd51aef019e231809eb7b53b77
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

Release files / config_bat-0.4.1-py3-none-any.whl

Download URL config_bat-0.4.1-py3-none-any.whl
Size 3.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e1e66e2268011d81e7809cb2f6650f98d6c97b1c4d5aecc3c6fa40ddc7afd296
BLAKE2b-256 checksum
How to use checksums
bf02d3ac64ea5334fea61d0302239bcfb7bf303e1c974b7b94ef249630de1d96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 release files

0.4.0

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page