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 OR Apache-2.0. See LICENSE-MIT and LICENSE-APACHE.

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.5.0.tar.gz (54.3 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.5.0-cp39-abi3-win_arm64.whl (201.7 kB view details)

Uploaded CPython 3.9+Windows ARM64

ktav-0.5.0-cp39-abi3-win_amd64.whl (207.6 kB view details)

Uploaded CPython 3.9+Windows x86-64

ktav-0.5.0-cp39-abi3-musllinux_1_2_x86_64.whl (505.7 kB view details)

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

ktav-0.5.0-cp39-abi3-musllinux_1_2_aarch64.whl (459.4 kB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ ARM64

ktav-0.5.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (294.3 kB view details)

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

ktav-0.5.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (282.3 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

ktav-0.5.0-cp39-abi3-macosx_11_0_arm64.whl (274.4 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

ktav-0.5.0-cp39-abi3-macosx_10_12_x86_64.whl (286.1 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for ktav-0.5.0.tar.gz
Algorithm Hash digest
SHA256 2c6ae05db52716d379afeec945d1cf910fc5ad193345221d862a5b5a35a23dc3
MD5 453c7836a4b7971afefc51de4bb5513c
BLAKE2b-256 da78bf686f47afd409c6634f383387e9605303b975978a0d8e9aa2bdb81c687a

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ktav-0.5.0-cp39-abi3-win_arm64.whl
  • Upload date:
  • Size: 201.7 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.5.0-cp39-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 16c23665f04b70b95314fd637aac1b03982c35511a52e4cce2e588386edbc226
MD5 8b6eb3903343a2ebce04b7efe5e20210
BLAKE2b-256 045e087fb0cd1590468ce6158bc5fc166a480698a57b6ed20ce56494d70c22a2

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ktav-0.5.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 207.6 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.5.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 cf2d6d42fb15ea79b5ed644586c8ae1103e2b24272fd986803164a062b1388b4
MD5 d276b2e4f517234449397d5651da236d
BLAKE2b-256 059f93f224c0911aed871e5be37d1d402bb585c108ba96e97a7a138b56e3f285

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ktav-0.5.0-cp39-abi3-musllinux_1_2_x86_64.whl
  • Upload date:
  • Size: 505.7 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.5.0-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 fb9ebd351d539582e42de36d9d442c762e6c966f1d9bbd25d3315ab46cf51cd6
MD5 a4477b067db64b9209ecc92995c4bfa7
BLAKE2b-256 03a6498605f87eb7277d89a288b0d94f8303705f6830e799bfd6b2aeb0ea25ca

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ktav-0.5.0-cp39-abi3-musllinux_1_2_aarch64.whl
  • Upload date:
  • Size: 459.4 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.5.0-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 63026c96851d87a53b4da937e8c3fc7718b30eff2f100d1cecd9d97f9e18cd56
MD5 0f5d9652af3f80b17b72fa8255f82d56
BLAKE2b-256 1491bd14253ef0da9cca90c7216e5976fbc6a16002e7ea4599c680b7af28556d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ktav-0.5.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8327306bb46eb25fd5e025f31ed04b19b16bf64034db719b9ea506ad138019ea
MD5 c8f377853a5620f948b37788748e422a
BLAKE2b-256 ed0e5fa89d9a29fc457fbc3e8e1593b7418ccee23f5b29bf82a172a148f30445

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ktav-0.5.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b6b775d4175e32f200528b2c092a10e78b398123406f016a8f56db092998cfc0
MD5 316c349bc8d95c6e1e13e5d7ca685500
BLAKE2b-256 df97d4c0871cc96978779335f58897668e1305ad1c5ceea1d78e97dcf54a5677

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ktav-0.5.0-cp39-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 274.4 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.5.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0ccc99265b9166d1eff8f162523c4170a1df7bf9200b6648943906cc991f43bf
MD5 b56aca355f80e651b4a9b969dd95cf36
BLAKE2b-256 9ff8a9ab2f82f69369113ce72ed000580c96e732fe3d628c3029424bde6526f5

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ktav-0.5.0-cp39-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 286.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.5.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 feb2d5b6fbff954baee4f5c94bd5544e58f24373b1f289a317308e1bd14bb81f
MD5 1c16f4387179f640a987abdb46c14d57
BLAKE2b-256 48283b7a5097ccb4da038b6b1751b86a3e46c6118ea2e383eb4d4a7c109ac215

See more details on using hashes here.

Provenance

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