Skip to main content

pyknf

Merge layered JSON and TOML configuration files into a dict. This is the same Rust merge the knf command line runs, called natively.

pip install pyknf    # the module, and the `knf` executable
from knf import deep_merge

config = deep_merge(["base.toml", "prod.json"], override={"server": {"port": 8080}})

Pass interpolate=True to resolve references after all files and the override have been merged:

config = deep_merge(["base.toml", "prod.json"], interpolate=True)

${key.path} reads a value from the final config, including nested keys and array elements such as ${servers[0].host}. A reference that occupies the whole string keeps the value's type: "${server.port}" can become an int, and "${server}" can become a dict. Within other text, it becomes a string: "http://${server.host}:${server.port}/". ${env:NAME} reads the process environment; a whole-string environment reference uses the CLI's JSON-or-string typing rule, while an embedded one inserts raw text. Use $$ for a literal $. Interpolation is off by default, leaving reference strings untouched. Invalid or missing references and cycles raise knf.InterpolationError, a ValueError, with the affected key paths.

Files are merged left to right, exactly like knf base.toml prod.json. Objects merge key by key. Arrays, scalars and None replace wholesale. If you pass override, it is merged last as one more layer, which makes it the Python version of --set. It must be a dict of JSON-like values: None, bool, int (within 64 bits), float, str, list/tuple and nested dicts with str keys, at most 128 levels deep and without cycles. Anything else raises TypeError or ValueError naming the key path, before any file is read.

A file that can't be read raises FileNotFoundError, PermissionError or IsADirectoryError, as open() would. Invalid JSON or TOML raises knf.ParseError, a ValueError like json.JSONDecodeError. TOML datetimes come back as their TOML spelling in a str.

See the project README for the merge semantics in full.

Release files for pyknf 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for pyknf 0.3.2
File
pyknf-0.3.2-cp39-abi3-win_arm64.whl CPython 3.9 abi3 Windows ARM64 Details
pyknf-0.3.2-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
pyknf-0.3.2-cp39-abi3-musllinux_1_2_x86_64.whl CPython 3.9 abi3 Linux musl 1.2+ x86-64 Details
pyknf-0.3.2-cp39-abi3-musllinux_1_2_aarch64.whl CPython 3.9 abi3 Linux musl 1.2+ ARM64 Details
pyknf-0.3.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details
pyknf-0.3.2-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details
pyknf-0.3.2-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details
pyknf-0.3.2-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details

Total release size: 5.6 MB

Release files / pyknf-0.3.2-cp39-abi3-win_arm64.whl

Download URL pyknf-0.3.2-cp39-abi3-win_arm64.whl
Size 589.0 kB
Tags CPython 3.9 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
399cd1064673a1dda737b5e040d6cef990c1826adaebec5c187778f6b073d4e5
BLAKE2b-256 checksum
How to use checksums
f7cda73fa98cb402abea76e7d88658c83d4e5dfa8bbaf74770c898c585bba60a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pyknf-0.3.2-cp39-abi3-win_amd64.whl

Download URL pyknf-0.3.2-cp39-abi3-win_amd64.whl
Size 616.4 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
b45f55a51ead4b17e6d0a2e884260d5e476eaa524985ea6dbb5e978abffaabea
BLAKE2b-256 checksum
How to use checksums
13d46c8e8700d77d1c319cfd6d5b88431f6be80a5b5c04ae73b3c40937ff920b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pyknf-0.3.2-cp39-abi3-musllinux_1_2_x86_64.whl

Download URL pyknf-0.3.2-cp39-abi3-musllinux_1_2_x86_64.whl
Size 918.7 kB
Tags CPython 3.9 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
14ed60dfed44e64c269203fad953e49ec305b61bcefb311f69566f0d826f4792
BLAKE2b-256 checksum
How to use checksums
d3236c839f9379355e1637ca71f349e0f216d7c4668dfb41cf695a6d7743fa74
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pyknf-0.3.2-cp39-abi3-musllinux_1_2_aarch64.whl

Download URL pyknf-0.3.2-cp39-abi3-musllinux_1_2_aarch64.whl
Size 846.7 kB
Tags CPython 3.9 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
12e5b6bcded782a1fbed8d657a577c1e09e243d86a5f78e27466fb4a7fda377e
BLAKE2b-256 checksum
How to use checksums
bff0e0b993547779507b2a59363d98479ad677949e9cc5551609b7abe9cc7b71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pyknf-0.3.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pyknf-0.3.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 703.2 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
52823146b51906e6b86a4e8a29e8a5dbad1da6dc398238cb50ded974d7482771
BLAKE2b-256 checksum
How to use checksums
1b1bc49e478428d91599cc6dd1ed7ee3894260ece212a4be59bcf7147ba0b816
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pyknf-0.3.2-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL pyknf-0.3.2-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 668.2 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
e99819d167a79673ddbbffdfe9b15b3530a813eb45c66cb03013f8389e0d94ca
BLAKE2b-256 checksum
How to use checksums
54134540cdc950fbe8c6c8507645098cc98f5bfdcc0685d9277220ac08d1fc29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pyknf-0.3.2-cp39-abi3-macosx_11_0_arm64.whl

Download URL pyknf-0.3.2-cp39-abi3-macosx_11_0_arm64.whl
Size 644.0 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
a746070e824c6924beb160086b29e95c4769c7cf00153ac86d48e75046ab1343
BLAKE2b-256 checksum
How to use checksums
0aab5e23482e3ab0d727473342b3f073718c8fd649965b06e96e5150d2c8b127
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pyknf-0.3.2-cp39-abi3-macosx_10_12_x86_64.whl

Download URL pyknf-0.3.2-cp39-abi3-macosx_10_12_x86_64.whl
Size 659.9 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
8b2c2db4006f8cb0b0392136da5c433e764a14992bb332e7ae357ab89231e6a6
BLAKE2b-256 checksum
How to use checksums
a801ec979bfea2fd8981bcdb55e371d9f9daa7c396d461350c59939c22465148
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.3.2 This release

8 release files

0.3.1

8 release files

0.3.0

8 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page