Simple configuration handling in Python.
Project description
no_config
把yaml
、json
和toml
等配置文件映射为类,需要很多冗余代码
或者魔术字符串
。这对代码的维护工作提出了更高的要求,no_config能简化这种映射,仅仅需要两行代码即可完成映射。更多文档信息请参考https://ncdhz.github.io/no_config。
快速开始
下面将用一个简短的例子介绍本库该怎么使用,例子中使用的源码在examples/start/start.py。
-
配置文件
# 创建配置文件start.yaml user: username: ncdhz password: ncdhz
-
源码文件
from os import path from no_config import Config # 配置注入 @Config class User: password = None username = None if __name__ == '__main__': # 配置初始化 # 全局只需一次初始化 # 在更改配置之后可以通过此函数刷新配置 Config.init(path.join(path.dirname(__file__), 'start.yaml')) print(User.password) print(User.username)
安装
pip安装
pip install no_config
源码安装
git clone https://github.com/ncdhz/no_config.git
# 进入no_config目录执行下面语句
pip install .
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
no_config-0.0.4.tar.gz
(4.6 kB
view details)
Built Distribution
File details
Details for the file no_config-0.0.4.tar.gz
.
File metadata
- Download URL: no_config-0.0.4.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7235bf6889c36af5b4610f3e099665b59e8f2a0bb5c6a579735aa43e1e505863 |
|
MD5 | d79c40c0daf72bd4c792c25764dbe300 |
|
BLAKE2b-256 | e7194ac20a3bc90749f43b27f1f9c70a12b3535b5f70c8b0ca8eab48c8acd29f |
File details
Details for the file no_config-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: no_config-0.0.4-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1595ec5ba89534b7e0a3a6c8116ece328bbd66e7e2ee4fa2d9539f0b1d588a33 |
|
MD5 | 3d5af435f8ff6cb188239da28992bf5d |
|
BLAKE2b-256 | e2cd04a81b2062c309cda8d2171dc322fae286140e739423e994b9b51f77dd16 |