Skip to main content

Python Application Configuration.

Project description

https://travis-ci.org/Maples7/py-config.svg?branch=master https://img.shields.io/pypi/v/py-app-config.svg

Python Application Configuration. Py-config organizes hierarchical configurations for your app deployments.

Usage

Installation

pip install py-app-config

Best Practice

Firstly, you should have a config folder under the codebase of your application, like this:

.
├── config
   ├── __init__.py
   ├── default.json
   ├── development.json
   ├── production.json
   └── test.json
.

Secondly, set environment variable PY_ENV to one of the names of JOSN files in the config folder, and it defaults to be development.

In your __init__.py under config folder, these codes can be used:

import os
from py_config import set_config_dir, get_config

config_dir = os.path.abspath(os.path.dirname(__file__))
set_config_dir(config_dir)
config = get_config()

Then, you can use from config import config to import your app config in any other places in you codebase.

The final config would merge default.json and <PY_ENV>.json. See dict-recursive-update for the recursive update rules.

APIs

# Set the config directory path
set_config_dir(
    config_dir=None  # Directory path of `config` folder
)

# Get final config according to the `config_dir`.
# It should be executed every time after a new `config_dir` is set.
get_config()

Relatives

License

MIT

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

py-app-config-1.0.0.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

py_app_config-1.0.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file py-app-config-1.0.0.tar.gz.

File metadata

File hashes

Hashes for py-app-config-1.0.0.tar.gz
Algorithm Hash digest
SHA256 caf679cc3338a3c767925dcf15168b73e8a04f2407817904f2b4dd952f0a2df0
MD5 95ba3bd7bd3cf8057c1d84d8a61cc4b7
BLAKE2b-256 5a140bee1d4aec62434064347fefa93e1c50cd98ec977e321aa71201f02a6643

See more details on using hashes here.

File details

Details for the file py_app_config-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for py_app_config-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 21678da979ee5e42703f175b53df73b4f807a1923dfb2f1f692b653b79f2bd25
MD5 e663f2b687d049499e75bbaee2fd7312
BLAKE2b-256 1a9612d273ab1e62aae7ccc54a6d329188ced6dffac44bd9ca4dec1930219958

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