Skip to main content

Python bindings for Ktav — a plain configuration format. No quotes, no commas, dotted keys.

Project description

ktav (Python)

Python bindings for Ktav — a plain configuration format. JSON-shape, no quotes, no commas, dotted keys. Powered by Rust under the hood.

Languages: English · Русский · 简体中文

Specification: this package implements Ktav 0.1. The format is versioned and maintained independently of this package — see ktav-lang/spec for the formal document.


Install

pip install ktav

Wheels are published for every major platform and every supported Python version:

  • Linux (manylinux + musllinux) — x86_64, aarch64
  • macOSx86_64, arm64 (Apple Silicon)
  • Windowsx64, arm64

Python 3.9+ is required. The wheels target the stable ABI (abi3-py39), so a single wheel per platform serves every supported CPython release.

If no prebuilt wheel matches your platform, pip falls back to the source distribution and compiles it locally — you need a Rust toolchain (rustup) and the Python development headers.

Quick start

Parse — read typed fields straight off the dict

import ktav

src = """
service: web
port:i 8080
ratio:f 0.75
tls: true
tags: [
    prod
    eu-west-1
]
db.host: primary.internal
db.timeout:i 30
"""

cfg = ktav.loads(src)

service: str = cfg["service"]
port:    int = cfg["port"]
ratio: float = cfg["ratio"]
tls:    bool = cfg["tls"]
tags: list[str] = cfg["tags"]
db_host:    str = cfg["db"]["host"]
db_timeout: int = cfg["db"]["timeout"]

Walk — dispatch on the runtime type

for k, v in cfg.items():
    if v is None:              kind = "null"
    elif isinstance(v, bool):  kind = f"bool={v}"   # bool first — True is also an int!
    elif isinstance(v, int):   kind = f"int={v}"
    elif isinstance(v, float): kind = f"float={v}"
    elif isinstance(v, str):   kind = f"str={v!r}"
    elif isinstance(v, list):  kind = f"array({len(v)})"
    elif isinstance(v, dict):  kind = f"object({len(v)})"
    print(f"{k} -> {kind}")

Build & render — construct a document in code

doc = {
    "name": "frontend",
    "port": 8443,
    "tls": True,
    "ratio": 0.95,
    "upstreams": [
        {"host": "a.example", "port": 1080},
        {"host": "b.example", "port": 1080},
    ],
    "notes": None,
}
text = ktav.dumps(doc)
# name: frontend
# port:i 8443
# tls: true
# ratio:f 0.95
# upstreams: [
#     { host: a.example  port:i 1080 }
#     { host: b.example  port:i 1080 }
# ]
# notes: null

A complete runnable version lives in examples/basic.py.

Four entry points mirror the standard library json module:

Function Purpose
ktav.loads(s) Parse a Ktav string (or UTF-8 bytes).
ktav.dumps(obj) Serialise a native Python value.
ktav.load(fp) Parse from a file-like object.
ktav.dump(obj, fp) Serialise to a file-like object.

load / dump accept both text-mode and binary-mode files.

Type mapping

Ktav Python
null None
true / false bool
:i <digits> int
:f <number> float
bare scalar str
[ ... ] list
{ ... } dict

Ktav keeps "no magic types" — a bare port: 8080 stays a string at the parser level. Use the typed markers :i / :f when you want numbers, or type-coerce at the application layer.

dict preserves insertion order (Python 3.7+ guarantee), matching the ordered-object semantics of Ktav.

Serialisation is the inverse:

  • Python int:i marker (including arbitrary-precision bigints).
  • Python float:f marker (decimal point always present; NaN / ±Infinity are rejected — Ktav 0.1.0 does not represent them).
  • Python tuple is accepted as an array, for symmetry with list.
  • Non-str keys in a dict raise KtavEncodeError.

Errors

import ktav

try:
    ktav.loads("x: [")
except ktav.KtavDecodeError as e:
    print("decode:", e)

try:
    ktav.dumps({"v": float("nan")})
except ktav.KtavEncodeError as e:
    print("encode:", e)

# Catching the base class catches either.
try:
    ktav.loads("a: 1\na: 2")
except ktav.KtavError:
    ...
Exception Raised by Base
KtavError (base) Exception
KtavDecodeError loads / load KtavError
KtavEncodeError dumps / dump KtavError

Philosophy

Ktav is intentionally small. Its five design principles (from spec/CONTRIBUTING.md):

  1. Locality — a line's meaning does not depend on another line.
  2. One sentence — any new rule fits in one sentence of the spec.
  3. No whitespace sensitivity (line breaks aside).
  4. No magic types — the format never decides "8080" means a number.
  5. Explicit over clever:: is verbose on purpose.

The Python bindings honour this: they add no schema inference, no auto-casting, no defaulting. If you want typing, you do it at the boundary with your own tool — pydantic, dataclasses, attrs — against the native Python structures this library returns.

Other Ktav implementations

  • spec — specification + conformance suite
  • rust — reference Rust crate (cargo add ktav); these Python bindings are a thin PyO3 wrapper around it
  • csharp — C# / .NET (dotnet add package Ktav)
  • golang — Go (go get github.com/ktav-lang/golang)
  • java — Java / JVM (io.github.ktav-lang:ktav on Maven Central)
  • js — JS / TS (npm install @ktav-lang/ktav)
  • php — PHP (composer require ktav-lang/ktav)

Versioning

This package follows Semantic Versioning with the pre-1.0 convention that a MINOR bump is breaking. The package version and the ktav crate version move together. ktav.__spec_version__ reports the Ktav format version this binding supports.

Development

See CONTRIBUTING.md for the dev setup, test layout, and the contribution workflow.

Support the project

The author has many ideas that could be broadly useful to IT worldwide — not limited to Ktav. Realizing them requires funding. If you'd like to help, please reach out at phpcraftdream@gmail.com.

License

MIT. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ktav-0.2.0.tar.gz (44.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

ktav-0.2.0-cp39-abi3-win_arm64.whl (165.8 kB view details)

Uploaded CPython 3.9+Windows ARM64

ktav-0.2.0-cp39-abi3-win_amd64.whl (169.5 kB view details)

Uploaded CPython 3.9+Windows x86-64

ktav-0.2.0-cp39-abi3-musllinux_1_2_x86_64.whl (469.3 kB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ x86-64

ktav-0.2.0-cp39-abi3-musllinux_1_2_aarch64.whl (425.3 kB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ ARM64

ktav-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (257.3 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

ktav-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (248.0 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

ktav-0.2.0-cp39-abi3-macosx_11_0_arm64.whl (241.1 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

ktav-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl (250.0 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file ktav-0.2.0.tar.gz.

File metadata

  • Download URL: ktav-0.2.0.tar.gz
  • Upload date:
  • Size: 44.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ktav-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3ff34e4d9b6b117cf9f23a8f98e9636ab72df8281b985bc6d60581be9b073ac9
MD5 ec74ed8c00f8ad7636b8e5c6ee68e9af
BLAKE2b-256 f888271da3b30ef0dc513e6eb0e02e647ae56220ed73ce4bb0d3c4001d1bbd34

See more details on using hashes here.

Provenance

The following attestation bundles were made for ktav-0.2.0.tar.gz:

Publisher: release.yml on ktav-lang/python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ktav-0.2.0-cp39-abi3-win_arm64.whl.

File metadata

  • Download URL: ktav-0.2.0-cp39-abi3-win_arm64.whl
  • Upload date:
  • Size: 165.8 kB
  • Tags: CPython 3.9+, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ktav-0.2.0-cp39-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 99274a5555d0b8c95f1066a854aa88f205646fd7d0bc9c7857c235c0adc17f02
MD5 bdd8a89a60547a782e4af3d00b05528c
BLAKE2b-256 e907d4741ccd70cd235b9dd7132f38ef2b5c3ca6126ea76899e854c2c2fbe70b

See more details on using hashes here.

Provenance

The following attestation bundles were made for ktav-0.2.0-cp39-abi3-win_arm64.whl:

Publisher: release.yml on ktav-lang/python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ktav-0.2.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: ktav-0.2.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 169.5 kB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ktav-0.2.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 59ab63edacc5d60eab3e16fb6f7249a97b7f03b578f5e95bc84b1f5996bb761d
MD5 2dca78d6e1cd53398b49b9a85ef64c61
BLAKE2b-256 67424a18f78aa181e87d3fd6f3f39023a4991bcbf1e546bbf1121c59978d2835

See more details on using hashes here.

Provenance

The following attestation bundles were made for ktav-0.2.0-cp39-abi3-win_amd64.whl:

Publisher: release.yml on ktav-lang/python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ktav-0.2.0-cp39-abi3-musllinux_1_2_x86_64.whl.

File metadata

  • Download URL: ktav-0.2.0-cp39-abi3-musllinux_1_2_x86_64.whl
  • Upload date:
  • Size: 469.3 kB
  • Tags: CPython 3.9+, musllinux: musl 1.2+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ktav-0.2.0-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f01f02300072bbf8e0e253df05e20dc042a4c94fd96f723ff261f9116720ae95
MD5 c76bf53678c8cad6241d4718e7dc883a
BLAKE2b-256 37c3dbeea1176e1a025dfaa04563d288a5d2353bb8018c5b24174c33c30f5c57

See more details on using hashes here.

Provenance

The following attestation bundles were made for ktav-0.2.0-cp39-abi3-musllinux_1_2_x86_64.whl:

Publisher: release.yml on ktav-lang/python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ktav-0.2.0-cp39-abi3-musllinux_1_2_aarch64.whl.

File metadata

  • Download URL: ktav-0.2.0-cp39-abi3-musllinux_1_2_aarch64.whl
  • Upload date:
  • Size: 425.3 kB
  • Tags: CPython 3.9+, musllinux: musl 1.2+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ktav-0.2.0-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 96b438626d2773a39be332d41fa904bc76d0fc687a4c6fc4c588932efea56a05
MD5 ce725eb77355e79cfe81a39e4c7c4d29
BLAKE2b-256 396edae9a6e88433c31284c8085a352c795a67f9813a1d0f06f82aefc7a408c3

See more details on using hashes here.

Provenance

The following attestation bundles were made for ktav-0.2.0-cp39-abi3-musllinux_1_2_aarch64.whl:

Publisher: release.yml on ktav-lang/python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ktav-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ktav-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d832c5a9e8638c45ede26590cf91b49cdf32277f78ce42910f92329d64b65419
MD5 d0c9b2112f30bd696bb1397363b3973e
BLAKE2b-256 aff52877467dbcc039f55c855686621551943ddf81cd5d38636092d47e7ea74c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ktav-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on ktav-lang/python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ktav-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for ktav-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 fb08bc58eac844ae662169a0e7744628f1b8dea10034af8cc6d529ed9453e0d6
MD5 d01258420e903e8254581349c75df183
BLAKE2b-256 860e853fe84dd5eb62efbaa0a60c4ca143ba48649e9dec5965d67e26db233b7f

See more details on using hashes here.

Provenance

The following attestation bundles were made for ktav-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on ktav-lang/python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ktav-0.2.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: ktav-0.2.0-cp39-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 241.1 kB
  • Tags: CPython 3.9+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ktav-0.2.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 53a8ab1092c17ae7687e4aa0c8ca977d7d65f001345e4cbf2bfd5fed7fdd5ccf
MD5 1e0f5dcfe01e0ea993a79202171f3e0b
BLAKE2b-256 c4da680f9e16e3f547a1a275cd276a7cd8aae13b8cb6c3524fba36d6168b1414

See more details on using hashes here.

Provenance

The following attestation bundles were made for ktav-0.2.0-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on ktav-lang/python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ktav-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

  • Download URL: ktav-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 250.0 kB
  • Tags: CPython 3.9+, macOS 10.12+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ktav-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 153650314b385c4d89c31cbc9954d62fe9ca9b1190bd8fa7c8feac0b4c6de24d
MD5 c4b9c7de6a029594293557308b56328e
BLAKE2b-256 e9a37e7f5ebc571471b770c86db0d1a8d823693ea495d9fc0f0cc696e9633b13

See more details on using hashes here.

Provenance

The following attestation bundles were made for ktav-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on ktav-lang/python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page