项目作者: DongjunLee

项目描述 :
hb-config: easy to configure your python project especially Deep Learning experiments
高级语言: Python
项目地址: git://github.com/DongjunLee/hb-config.git
创建时间: 2017-08-26T06:29:03Z
项目社区:https://github.com/DongjunLee/hb-config

开源协议:MIT License

下载







Project Introduction



PyPI version






build status


Requirements Status


Dependency Status






Codecov







hb-config: easy to configure your python packge

hb-config is utility for easy to configure your python project especially Deep Learning experiments.

Feature

  • Do not use any boilerplate code
  • Singleton Class (immediately use anywhere)
  • Supports formats: .json and .yaml
  • Access property using __getattr__ function Config.TOKEN
  • Edit property using __setattr__ function Config.TOKEN = "{token}"
  • every config data’s type is dict

Install

using pip

  1. $ pip install hb-config

or clone repository

  1. git clone https://github.com/hb-research/hb-config.git
  2. python setup.py install

Usage

  • base path : config/
  • config3.yml example
  1. project: hb-config
  2. example: true
  3. bot:
  4. in_bot:
  5. test: haha
  6. simple: wow
  • Using like dict
    • only one difference : Config[“project”] -> Config.project
    • using get Config.get(“project”), Config.get(“project”, {})
    • using set Config.project = “set value”
  • Add description with python annotation. #

Load config

  1. >>> from hbconfig import Config
  2. >>> Config("config3")
  3. >>> Config
  4. Read config file name: config3.yml
  5. {
  6. "project": "hb-config",
  7. "example": true,
  8. "bot": {
  9. "in_bot": {
  10. "test": "haha",
  11. "simple": "wow"
  12. }
  13. }
  14. }

Get

  1. >>> Config.bot.in_bot
  2. {
  3. "test": "haha"
  4. "simple": "wow"
  5. }
  6. >>> Config.project
  7. 'hb-config'
  8. >>> Config.bot.in_bot.get("simple")
  9. 'wow'
  10. >>> Config.bot.in_bot.get("not_exist_key", "default_value")
  11. 'default_value'

Set

  • The config file does not change.
  1. >>> Config.bot.in_bot
  2. {
  3. "test": "haha"
  4. "simple": "wow"
  5. }
  6. >>> Config.bot.in_bot = "hello"
  7. >>> Config.bot.in_bot
  8. 'hello'

Description

  • example config
  1. project: hb-config # project name
  2. example: true # is it example?
  3. bot:
  4. in_bot:
  5. test: haha
  6. simple: wow
  1. >>> Config
  2. Read config file name: ./config/config
  3. {
  4. "project": "hb-config",
  5. "example": true,
  6. "bot": {
  7. "in_bot": {
  8. "test": "haha",
  9. "simple": "wow"
  10. }
  11. }
  12. }
  13. >>> Config.description
  14. {'example': 'is it example?', 'project': 'project name'}