Skip to content
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

>> The Strangely Familiar Config Parser <<

Codecov Code style: black MIT license

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"

name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00 # First class dates

  ip = ""
  dc = "eqdc10"

  ip = ""
  dc = "eqdc10"

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

# Get the config dict from the konfik class
config = konfik.config

# Access and print the variables

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=< object at
    'database': {
        'server': '',
        'ports': [8001, 8001, 8002],
        'connection_max': 5000,
        'enabled': True
    'servers': {
        'alpha': {'ip': '', 'dc': 'eqdc10'},
        'beta': {'ip': '', '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
✨ 🍰 ✨