Skip to content

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

License

Notifications You must be signed in to change notification settings

Maples7/py-config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

py-config

https://travis-ci.org/Maples7/py-config.svg?branch=master

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages