A simple configuration management tool for python.
Project description
confng-py
A simple configuration management tool for python. You can use it to manage your python application's configuration in a simple and flexible way.
Install
pip install confng-py
Usage
from confng import Conf
# create a new Conf instance with a config object and MergeEnvOptions
# If you don't want to merge environment variables, you can omit the merge_env_options option.
# The value of `config` is JSON. You can parse it from json/toml/yaml/... file, or directly pass an object.
# The logic should be implemented in your own code.
conf = Conf(
ConfOptions(
config={
"name": "foo",
"server": {
"port": 3000,
"host": "localhost",
},
"logs": [
{
"level": "info",
"output": "console",
},
],
"nums": [1, 2, 3],
},
merge_env_options=MergeEnvOptions(prefix="FOO", separator="__"),
)
)
print(conf.get('name')); # foo
print(conf.get('server.port')); # 3000
print(conf.get('server.host')); # localhost
# The inner of Conf will guess the type of the value automatically from the initial config object.
# So the inital config object should be in full form, and the value of each key should be in the correct type.
# if the following environment variables setted
# FOO__SERVER__PORT=4000
# FOO__SERVER__HOST=example.com
print(conf.get('server.port')); # here will return 4000 and the data type is number.
print(conf.get('server.host')); # example.com
Load config from file
import os
import json
from confng import Conf
# read config from conifg/default.json
config_path = os.path.join('config', 'default.json')
with open(config_path, 'r') as f:
config = json.load(f)
conf = Conf(ConfOptions(config=config))
print(conf.get('name'));
Thanks
This package is inspired by the following packages:
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file confng_py-0.2.2.tar.gz.
File metadata
- Download URL: confng_py-0.2.2.tar.gz
- Upload date:
- Size: 17.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de6b956a9ff1d75b6e755e57ca6c6a59b2c1cd55686d3ae3c582ba70cc6cca0c
|
|
| MD5 |
e5fced53d69e07016c4ef123a2532566
|
|
| BLAKE2b-256 |
381bfdbe27224fad0300c096e228c237ad195168a4a6cca74733c05ea8b25fc7
|
Provenance
The following attestation bundles were made for confng_py-0.2.2.tar.gz:
Publisher:
publish.yml on SethWen/confng-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
confng_py-0.2.2.tar.gz -
Subject digest:
de6b956a9ff1d75b6e755e57ca6c6a59b2c1cd55686d3ae3c582ba70cc6cca0c - Sigstore transparency entry: 498658322
- Sigstore integration time:
-
Permalink:
SethWen/confng-py@c40d847bdcf5403819c3fe18b0466d9fed5e0cea -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/SethWen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c40d847bdcf5403819c3fe18b0466d9fed5e0cea -
Trigger Event:
release
-
Statement type:
File details
Details for the file confng_py-0.2.2-py3-none-any.whl.
File metadata
- Download URL: confng_py-0.2.2-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08073a3a19d7e5960cda8ec225c8c05c0803e01827f4606df2df3fb56f8b43d0
|
|
| MD5 |
e6a70f5e215d76378772542091d192c3
|
|
| BLAKE2b-256 |
4794ebf64ac465a3265f82d88026005b869f22135f6eacd1778be6cff0c9e7b0
|
Provenance
The following attestation bundles were made for confng_py-0.2.2-py3-none-any.whl:
Publisher:
publish.yml on SethWen/confng-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
confng_py-0.2.2-py3-none-any.whl -
Subject digest:
08073a3a19d7e5960cda8ec225c8c05c0803e01827f4606df2df3fb56f8b43d0 - Sigstore transparency entry: 498658338
- Sigstore integration time:
-
Permalink:
SethWen/confng-py@c40d847bdcf5403819c3fe18b0466d9fed5e0cea -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/SethWen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c40d847bdcf5403819c3fe18b0466d9fed5e0cea -
Trigger Event:
release
-
Statement type: