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.3.1.tar.gz (48.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.3.1-cp39-abi3-win_arm64.whl (170.5 kB view details)

Uploaded CPython 3.9+Windows ARM64

ktav-0.3.1-cp39-abi3-win_amd64.whl (174.6 kB view details)

Uploaded CPython 3.9+Windows x86-64

ktav-0.3.1-cp39-abi3-musllinux_1_2_x86_64.whl (473.5 kB view details)

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

ktav-0.3.1-cp39-abi3-musllinux_1_2_aarch64.whl (429.6 kB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ ARM64

ktav-0.3.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (261.8 kB view details)

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

ktav-0.3.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (252.3 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

ktav-0.3.1-cp39-abi3-macosx_11_0_arm64.whl (245.5 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

ktav-0.3.1-cp39-abi3-macosx_10_12_x86_64.whl (254.9 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: ktav-0.3.1.tar.gz
  • Upload date:
  • Size: 48.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.3.1.tar.gz
Algorithm Hash digest
SHA256 5f765266cdf51113622b24f673a91154b0a55859fb2642808d9bc9528b66972d
MD5 2b48f527a16704c35fb49ce78e08e959
BLAKE2b-256 6846b38653089df044f68d3b527007a11c7a9d0c5cd22b003d00ab7bfd0b3a66

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ktav-0.3.1-cp39-abi3-win_arm64.whl
  • Upload date:
  • Size: 170.5 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.3.1-cp39-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 ffabfc3bdb10d6a754769c4c4d88917816209902e28aea9ddf9207124e40d0b2
MD5 a30d4532a62358ec872ea23ce73f1e20
BLAKE2b-256 4b74ad3d32d91b327a46ebe9282c3142671437d1ef5f87c9c3cf23c94dafecb0

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ktav-0.3.1-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 174.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.3.1-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 660db9b0a610194e25ca135e6d7cfb7e305a5155fff19db0fdd7e7b805e6e21f
MD5 d86e285689804dc535849c5b7267561c
BLAKE2b-256 abf12dc61fa8073909a7d5c0337239df582bfb7974bfe3f39ad46bc8f29c5288

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ktav-0.3.1-cp39-abi3-musllinux_1_2_x86_64.whl
  • Upload date:
  • Size: 473.5 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.3.1-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e020c115ae6661c76629474b4ab42ddc0b157ee164ec108f749f00aa810cf87a
MD5 8ca3c85a470200df1456b6c597253fa2
BLAKE2b-256 3cb18e10df1e3020acaa44e44ac0f0ee10d571859dca3a8ae6f1fdb01238d87f

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ktav-0.3.1-cp39-abi3-musllinux_1_2_aarch64.whl
  • Upload date:
  • Size: 429.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.3.1-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 afee55874ea7a98300836c725cfed4df22b876ec7423749cc4d14ec8e13dcfbb
MD5 60f91a1840f85310570b59790cd65c06
BLAKE2b-256 ae004f3d6796af9c656589ae6c48fafacf43182d08ef3e266cc17b753a7bdfc6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ktav-0.3.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6a3ba328144041d969c637715783131fab7f5598c65a0bf872a7aa802aa7bc51
MD5 838d3cc5f3bc14d82c312f5a4ae771d7
BLAKE2b-256 7e9370a41bcf7eb57fe99e704ffa572a2bf44ccb2a3a6af5b289fcb78336263a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ktav-0.3.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 09360b07820e94f33779de2eb1c637d0dcb4117f96f6a7c687b81602af003a23
MD5 c9a7139a083ee2ed2bad20f888a1f0f7
BLAKE2b-256 9214f1476faac31163eae84a73d82accfc9f1f8a6df7dccb332589b476bbaa0c

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ktav-0.3.1-cp39-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 245.5 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.3.1-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0aa9797e14eb66f28095db7b1b018e0242b8a749bcfb7545d9470de6a19d9ce0
MD5 257e2d34cf00f4225e4d37be52e12f99
BLAKE2b-256 65659a5e57ac02a933a6630a4ad78281fda2ebebd9d5894a1429205fa5acd170

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ktav-0.3.1-cp39-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 254.9 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.3.1-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ee083beeab0909012b2f7ac151c4ab380426c2b9c6af0154aba83abbde65d91a
MD5 1e55c5426c2017b9c25b518b0c4e3f6a
BLAKE2b-256 a9eed8ffecf7946efd348832c98e738342c4740c1830ec9e6f44e3c8ad36aa2e

See more details on using hashes here.

Provenance

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