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.0.tar.gz (45.2 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.0-cp39-abi3-win_arm64.whl (166.3 kB view details)

Uploaded CPython 3.9+Windows ARM64

ktav-0.3.0-cp39-abi3-win_amd64.whl (169.9 kB view details)

Uploaded CPython 3.9+Windows x86-64

ktav-0.3.0-cp39-abi3-musllinux_1_2_x86_64.whl (469.5 kB view details)

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

ktav-0.3.0-cp39-abi3-musllinux_1_2_aarch64.whl (425.7 kB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ ARM64

ktav-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (257.6 kB view details)

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

ktav-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (248.6 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

ktav-0.3.0-cp39-abi3-macosx_11_0_arm64.whl (241.5 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

ktav-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl (250.3 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: ktav-0.3.0.tar.gz
  • Upload date:
  • Size: 45.2 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.0.tar.gz
Algorithm Hash digest
SHA256 956ceb90e23bdb276d9e36b8695f078e7ae55970ca55afcb6e0e2f7486e3b722
MD5 a46159a25bfeaab6504a4b13ed13e79e
BLAKE2b-256 9cdceb2c6b05ededc078887d4a37f42699add7c9166f35241eeb0e8619b6e587

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ktav-0.3.0-cp39-abi3-win_arm64.whl
  • Upload date:
  • Size: 166.3 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.0-cp39-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 c11340249b3679b2cb6098c24e4790cebdefd85e2525d75c521fa50eef0116d1
MD5 327f847a37a89d8b6505587cf7d182ab
BLAKE2b-256 c04e997cc2f2ce9441112501c38a6a39859f4dd74985ebd74ccc0c57c15d8bdb

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ktav-0.3.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 169.9 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.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a9d4c77e175a7376b3994c11454854bb790b214e9fcbb1d826d1a0a752dd352c
MD5 f9bcb383355cf3a8255851d596a0a112
BLAKE2b-256 0a2abeb0684c066a83ab28adc63243a9b685e729b493c8029740de444b9996c4

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ktav-0.3.0-cp39-abi3-musllinux_1_2_x86_64.whl
  • Upload date:
  • Size: 469.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.0-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d620568128e84091d4dd5d1947aa60c144c34290da319b5f8d9b603c871e58eb
MD5 e1f81ac042e114562693bb8f97e3503f
BLAKE2b-256 84aafdbb7b819ef0d41e593f90994695473563812021c1a8efec5519e97348cd

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ktav-0.3.0-cp39-abi3-musllinux_1_2_aarch64.whl
  • Upload date:
  • Size: 425.7 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.0-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 87b63e95abd912e4f5db543f5f7d10dc46a8f93bb5875b6a121488abc7671c98
MD5 120f9b2ad1c00bceb84da632f8438080
BLAKE2b-256 7516b95a75e23590080dfb6e6155408dace97ceda8612fb5721c20e90785c690

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ktav-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d3709114cfe7926c68d9efb9bb298f677ac795676ca7fd9d3258b57ccfc130e1
MD5 a6770a25d24b30178cfbf1009e03920d
BLAKE2b-256 e0ff08ab1648a17b1a5ebacc51a36fc4e0b4602ea9719c17231f81ab1cead568

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ktav-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 cba40c66510199737cd92d10109e5dc04234078d7bc0e3da5f269a325fa7d2a4
MD5 1fe366dca2d546364bb9d30f6645fadc
BLAKE2b-256 a591f7a2c85193c2837f0ef1eb41f956965d64a8795a6f12041e344bdc3ced41

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ktav-0.3.0-cp39-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 241.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.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 05a8ac76a8a6f90ada6d2b8a591f59a538a324d8333d2ac81d95831d8d8008db
MD5 39c7bcd8960d6c829a734dd02c0f8986
BLAKE2b-256 9ae6144cbc038e98fbb56db034399127701dd18b36b51306f5d35a57fc1c18c3

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ktav-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 250.3 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.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 700c4293f50f6923bf22fda20b675ce896a1913d8294fd00514743f092a36d5c
MD5 1012b6efb6fa61f01ab1e8d586570008
BLAKE2b-256 6df99bab1d9da1933ce31bf5745764f00e16a36c29dd1f9de0fd60a6279d56cf

See more details on using hashes here.

Provenance

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