>> The Strangely Familiar Config Parser <<
Konfik is a simple configuration parser that helps you access your config variables using dot (.) notation. This lets you to do this —
foo_bar_bazz = config.FOO.BAR.BAZZ
— instead of this —
foo_bar_bazz = config["FOO"]["BAR"]["BAZZ"]
Konfik currently supports TOML, YAML, DOTENV and JSON configuration formats.
⚙️ Installation
Install Konfik via pip:
pip install konfik
💡 Usage
Let's see how you can parse a TOML config file and access the configuration variables. For demonstration, we'll be using the following config.toml file:
# Contents of `config.toml`
title = "TOML Example"
[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00 # First class dates
[servers]
[servers.alpha]
ip = "10.0.0.1"
dc = "eqdc10"
[servers.beta]
ip = "10.0.0.2"
dc = "eqdc10"
[clients]
data = [ ["gamma", "delta"], [1, 2] ]
Load the above config file and access the variables using dot notation:
from pathlib import Path
from konfik import Konfik
# Define the config path
BASE_DIR = Path(__file__).parent
CONFIG_PATH_TOML = BASE_DIR / "config.toml"
# Initialize the konfik class
konfik = Konfik(config_path=CONFIG_PATH_TOML)
# Print the config file as a Python dict
konfik.show_config()
# Get the config dict from the konfik class
config = konfik.config
# Access and print the variables
print(config.title)
print(config.owner)
print(config.owner.dob)
print(config.database.ports)
print(config.servers.alpha.ip)
print(config.clients)
The .show_config() method will print your entire config file as a colorized Python dictionary object like this:
{
'title': 'TOML Example',
'owner': {
'name': 'Tom Preston-Werner',
'dob': datetime.datetime(1979, 5, 27, 7, 32, tzinfo=<toml.tz.TomlTz object at
0x7f2dfca308b0>)
},
'database': {
'server': '192.168.1.1',
'ports': [8001, 8001, 8002],
'connection_max': 5000,
'enabled': True
},
'servers': {
'alpha': {'ip': '10.0.0.1', 'dc': 'eqdc10'},
'beta': {'ip': '10.0.0.2', 'dc': 'eqdc10'}
},
'clients': {'data': [['gamma', 'delta'], [1, 2]]}
}
Konfik also exposes a few command-line options for you to introspect your config file and variables. Run:
konfik --help
This will reveal the options associated with the CLI tool:
Konfik -- The strangely familiar config parser ⚙️
usage: konfik [-h] [--path PATH] [--show] [--show-literal] [--var VAR] [--version]
optional arguments:
-h, --help show this help message and exit
--path PATH add config file path
--show print config as a dict
--show-literal print config file content literally
--var VAR print config variable
--version print konfik-cli version number
To inspect the value of a specific variable in a ./config.toml file you can run:
konfik --path=config.toml --var=servers.alpha.ip
Metadata
Release files for konfik 2.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| konfik-2.0.5.tar.gz | 7.2 kB | Without provenance | Details for konfik-2.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| konfik-2.0.5-py3-none-any.whl | Python 3 | none | any | Details for konfik-2.0.5-py3-none-any.whl |
Total release size: 14.6 kB
Release files / konfik-2.0.5.tar.gz
| Download URL | konfik-2.0.5.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
de16511d895df3ff541e1bf85fe64a690b3c40db302e6243a971b30fcc4dec65
|
|
BLAKE2b-256 checksum How to use checksums |
9b10edf569e06bf747126715b3c0b02ff8883cea86d54b6bf1e9e995e4c52fd0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.9.1 Linux/5.8.0-7630-generic
|
Release files / konfik-2.0.5-py3-none-any.whl
| Download URL | konfik-2.0.5-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
76d1a33b2ea1c5271ce3502d96a974aabb566fb02e8975e4b1b24263116ef7e5
|
|
BLAKE2b-256 checksum How to use checksums |
a979ec3378a4be513818a00279e403892271778d18847f9f0778f472ae91785a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.9.1 Linux/5.8.0-7630-generic
|
Security for konfik 2.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.