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.

Related projects

  • ktav-lang/spec — canonical format specification and language-agnostic conformance test suite.
  • ktav-lang/rust — reference Rust implementation. These Python bindings are a thin PyO3 wrapper around that crate.

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.1.tar.gz (42.4 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.1-cp39-abi3-win_arm64.whl (162.8 kB view details)

Uploaded CPython 3.9+Windows ARM64

ktav-0.1.1-cp39-abi3-win_amd64.whl (166.8 kB view details)

Uploaded CPython 3.9+Windows x86-64

ktav-0.1.1-cp39-abi3-musllinux_1_2_x86_64.whl (465.2 kB view details)

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

ktav-0.1.1-cp39-abi3-musllinux_1_2_aarch64.whl (422.6 kB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ ARM64

ktav-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (253.1 kB view details)

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

ktav-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (245.1 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

ktav-0.1.1-cp39-abi3-macosx_11_0_arm64.whl (237.8 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

ktav-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl (247.2 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: ktav-0.1.1.tar.gz
  • Upload date:
  • Size: 42.4 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.1.tar.gz
Algorithm Hash digest
SHA256 5f96c1ccc31c544d9136fa0a6a1e5987aeb86f17ffe3d885f3b6aad02dac156c
MD5 98867fe2a044f0802c33e1244a9ab247
BLAKE2b-256 c68f0006b9b352ea3f61a00ad98d2f83ad08afc7d599156aebe06a045f6b3e69

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ktav-0.1.1-cp39-abi3-win_arm64.whl
  • Upload date:
  • Size: 162.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.1-cp39-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 43d53ca524806d94b8b4b1bdeb0bb0f0d949792af652c472a9e208aa46de4c75
MD5 bb463258a5eb2ff43cd6aa224f7e1036
BLAKE2b-256 76de9d26bea1f976d008656d67688bf299faf2b1f703b9818cbfddd4161c5666

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ktav-0.1.1-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 166.8 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.1-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 97955690debddb0f226f2cae9300750ad8c96ad40c82a8698f29844258d14c2f
MD5 12226b100c5abdee2c2f67ab89900566
BLAKE2b-256 e29b38fbbe1ade36733d07152debdb080ec281bb435560508b2757eb37b41a7a

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ktav-0.1.1-cp39-abi3-musllinux_1_2_x86_64.whl
  • Upload date:
  • Size: 465.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.1-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b4272255a34b64cdb4a97eb5e34460316dbf4aad6cb42eac73d4b853d6214880
MD5 215ec3204ba09a985a5a9e1886ec47f2
BLAKE2b-256 f11e0ddc333749c411deb4f6910928b4260cdcf9d9a39c1a907b2e794f60345c

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ktav-0.1.1-cp39-abi3-musllinux_1_2_aarch64.whl
  • Upload date:
  • Size: 422.6 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.1-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 4e4755016d08041cab4b871ff9126b7e28dbf065baf74adaf26136c6fb730a91
MD5 6e1364534b17d3dc1cc39166add1eca9
BLAKE2b-256 ec6290c2157d55793978927f03e0fc30128f77182ab1699581ab56bfcf41cd2e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ktav-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7059b011a2627bc06be35738b754c5adbce5f31f447cfa0a6930fee61e2e1897
MD5 d05d2e753acd37e8bf5c83d5d4c289bf
BLAKE2b-256 0df1a035128b432bda799b50ae1408d0c7c470b75ce694e92f861bf0491ce1d8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ktav-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c40ba36e39dfa6108d25ebd40fa28941c387e2528af22052af3456b5f78ae392
MD5 85000b37d368c143842139295d074136
BLAKE2b-256 63f954fd5193bd9948930f969812b39f2d8139802224b0eac94faa213dd767cc

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ktav-0.1.1-cp39-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 237.8 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.1-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5bc1084e3918849ea78464654162869269ac8099f964687345f6361542af7be5
MD5 35b74536d88404c1f69407f96bb94b0b
BLAKE2b-256 bceafdbd623bc516c70f4b861529fbe5b272d0218c02a61d18558c4d4b6e6ceb

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ktav-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 247.2 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.1-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ed401e28e5af07a84c3cd4d3a9bc101218dba6c78f313eb8e15b1ee47af11463
MD5 fa7972678b08b667cb150ae03ec08181
BLAKE2b-256 8d42ec37d3d0938a783f0de307ab12cc34ff465f269a99f117ca1d9adf072198

See more details on using hashes here.

Provenance

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