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.1.2.tar.gz (44.5 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.1.2-cp39-abi3-win_arm64.whl (165.8 kB view details)

Uploaded CPython 3.9+Windows ARM64

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

Uploaded CPython 3.9+Windows x86-64

ktav-0.1.2-cp39-abi3-musllinux_1_2_x86_64.whl (468.2 kB view details)

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

ktav-0.1.2-cp39-abi3-musllinux_1_2_aarch64.whl (424.1 kB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ ARM64

ktav-0.1.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (256.1 kB view details)

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

ktav-0.1.2-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (246.8 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

ktav-0.1.2-cp39-abi3-macosx_11_0_arm64.whl (239.9 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

ktav-0.1.2-cp39-abi3-macosx_10_12_x86_64.whl (249.1 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for ktav-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7c09ef61a9ec50e37e8303ea96639fd6e83a4b35a09aba26606ca9eb08c40165
MD5 6e3cd712ee1cabf0183ed8f7aefb86df
BLAKE2b-256 487a4d5171b27c8d473aff0ad91cbdfd90a61fd36cfffbba4a35b3001dffac16

See more details on using hashes here.

Provenance

The following attestation bundles were made for ktav-0.1.2.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.1.2-cp39-abi3-win_arm64.whl.

File metadata

  • Download URL: ktav-0.1.2-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.1.2-cp39-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 25de454a34c1218928a2a6cf9d1d7592a1b0783633b3dee52ec1e717ac814ff0
MD5 094cf30e43f431573b0be485208b409c
BLAKE2b-256 ff899d80fac87650a7258f2690267fdc82e1b9607d59e4e52d42c8232629203b

See more details on using hashes here.

Provenance

The following attestation bundles were made for ktav-0.1.2-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.1.2-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: ktav-0.1.2-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.1.2-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 fbd7be25d2c5a5d5dde08f94ce1e93c6f42e4043c0500318bba77bece7246420
MD5 ccccff2190bfdd07fd0478f77b8df41b
BLAKE2b-256 1efa958ab9fcd2cc5a2378f39b5c6972f5107d728146896fc7880994fce23836

See more details on using hashes here.

Provenance

The following attestation bundles were made for ktav-0.1.2-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.1.2-cp39-abi3-musllinux_1_2_x86_64.whl.

File metadata

  • Download URL: ktav-0.1.2-cp39-abi3-musllinux_1_2_x86_64.whl
  • Upload date:
  • Size: 468.2 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.1.2-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 abddec47462aa7aee21698dacfcb7b903369811b563ee414c0dbe0c77658f201
MD5 a53d2beae05d9b8c92af405922a47d56
BLAKE2b-256 b5ffb2ef954074905bdfb4b95c3698060a529d8b2724d9ae2536dce703644028

See more details on using hashes here.

Provenance

The following attestation bundles were made for ktav-0.1.2-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.1.2-cp39-abi3-musllinux_1_2_aarch64.whl.

File metadata

  • Download URL: ktav-0.1.2-cp39-abi3-musllinux_1_2_aarch64.whl
  • Upload date:
  • Size: 424.1 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.1.2-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 10d3bed865a7ffdd996e64ca7390acca57479f0d0953ac51b8477d1d2175c5cc
MD5 258ac9b3d630e35581e7c09726d561a0
BLAKE2b-256 6bf8dee68d845122028dbb6ca9cf8efaae920406e138e1ccd808b7a0688313a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for ktav-0.1.2-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.1.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ktav-0.1.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8ee9a5c2668982d73d12589ab5b15dfe9206818cd233d81b9f9e2715064382e2
MD5 0312dfe56a1796c9387cfb3bad230404
BLAKE2b-256 e48cfc135798b1ba86d4818f71f2bc96eef3666a7befb243331699ab578739d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for ktav-0.1.2-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.1.2-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for ktav-0.1.2-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 efeab189d9cae87e081ee3d55cedd9640e4209ca4ae4f4695bcee62a7cfc0a90
MD5 469e2fd0ed5edcda23805b2c2faa4a0e
BLAKE2b-256 6cdc205a738bf493cdee0edbeece05f9cb0350a6041a2e1ebbbed9faef508c9f

See more details on using hashes here.

Provenance

The following attestation bundles were made for ktav-0.1.2-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.1.2-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: ktav-0.1.2-cp39-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 239.9 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.1.2-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7e1755f6cb4dea2f266d41d5b5a9d18d8198e81f5a17f47519080427823d1160
MD5 7575cd8f028da689a35f6a4e7d5268a5
BLAKE2b-256 2e907a001fa6cd3bb9b36d0b06f57f3e4c5bfcb4ea112deb2e9c164e8add8ca1

See more details on using hashes here.

Provenance

The following attestation bundles were made for ktav-0.1.2-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.1.2-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

  • Download URL: ktav-0.1.2-cp39-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 249.1 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.1.2-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 206d7c6f4908d9e65328e325ed64018ad9892c237a89f4a016a2a4edce0cb311
MD5 052e4496574aaabed033de91dd941c7c
BLAKE2b-256 ffa3cd5378a091393225e081617a4d768ff4038745be36a178491087603f4e70

See more details on using hashes here.

Provenance

The following attestation bundles were made for ktav-0.1.2-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