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

import ktav

text = """
port:i 8080

upstreams: [
    {
        host: a.example
        port:i 1080
    }
    {
        host: b.example
        port:i 1080
    }
]
"""

cfg = ktav.loads(text)
# {'port': 8080, 'upstreams': [
#     {'host': 'a.example', 'port': 1080},
#     {'host': 'b.example', 'port': 1080},
# ]}

back = ktav.dumps(cfg)
assert ktav.loads(back) == cfg

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

Uploaded CPython 3.9+Windows ARM64

ktav-0.1.0-cp39-abi3-win_amd64.whl (166.2 kB view details)

Uploaded CPython 3.9+Windows x86-64

ktav-0.1.0-cp39-abi3-musllinux_1_2_x86_64.whl (464.7 kB view details)

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

ktav-0.1.0-cp39-abi3-musllinux_1_2_aarch64.whl (422.0 kB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ ARM64

ktav-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (252.5 kB view details)

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

ktav-0.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (244.6 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

ktav-0.1.0-cp39-abi3-macosx_11_0_arm64.whl (237.3 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

ktav-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl (246.7 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: ktav-0.1.0.tar.gz
  • Upload date:
  • Size: 36.8 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.0.tar.gz
Algorithm Hash digest
SHA256 05d1b353abbfa64f5071d9168c8daeae8e5f62871499baee6c3325412436e04d
MD5 80001c029730129705075baaa01be680
BLAKE2b-256 c78e775d55b0b9789c379c10e59174be67548d91854a862080b0750558471878

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ktav-0.1.0-cp39-abi3-win_arm64.whl
  • Upload date:
  • Size: 162.2 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.0-cp39-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 4657f6c1bc80dabc0c5d504606815b9da12953b45cb8a711c6273d5d0c692a91
MD5 b6aac828594e4ed58ea124543c650621
BLAKE2b-256 422def81d6a77b561a6de838189b48107bfb80eb5bb607f0b78d78bffb7034b1

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ktav-0.1.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 166.2 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.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 225c701c122d8571f683779db88ba71e7a3ac4dee5f33c0978344edb67ccc369
MD5 4f55474fab601ecd318f0c4d4712d553
BLAKE2b-256 897d4f2e6d188556435b7eb7133f979d7c66c1ce498dc7f5902e281cb4038758

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ktav-0.1.0-cp39-abi3-musllinux_1_2_x86_64.whl
  • Upload date:
  • Size: 464.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.1.0-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 38d64b1660e29fc389798cfb6c64f2c927505044e9aa69c1419fc90d54e53d3e
MD5 ff78e7a470ded5bb7630f7b9c7d05482
BLAKE2b-256 b50582fe408a09ef51ce4988c090d66de701b33cab57dd79664c7bbb297a3a31

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ktav-0.1.0-cp39-abi3-musllinux_1_2_aarch64.whl
  • Upload date:
  • Size: 422.0 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.0-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 b5878fb1cc4ca19ccbd77baa3c4287174c631252d2fb51d1894ece32a7463bf8
MD5 caa12513c829a9b472161a0b1d2bd5b3
BLAKE2b-256 0d45cf8f3a70b6923fae3ed5130278fc218fdbb5b71a0e1f20790a1a56627823

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ktav-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fc81c7a4e955761812368ea6982ea5edf2ea3891e51e8da68e05238da309536a
MD5 3f4d110cd0cf6571d9aa5e0a14cf5db8
BLAKE2b-256 7374095633c61a014ced59529ae0c4f44caa2b6c711483502e2cb91daca0ae44

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ktav-0.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 dd177b861190b16b292dead8c72483dbb61c165432bef37a2b90c7101ac4aa2a
MD5 f9daf2b54b2477171bc6c8431e52e03d
BLAKE2b-256 9c5d688c2ba10da9e692d8e20cf218158e6cd5f3193374bb21651d43338fe3c9

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ktav-0.1.0-cp39-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 237.3 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.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ddf2eef57e8980cefce0ec86a052aaea26d660d1285bec47ffbe5ed5afd4b313
MD5 7479a2f1dfe3bd521f0772d7f4139c04
BLAKE2b-256 ed6f12b4e7862a5836cc9b4bce3b82e67d05032eebfdef8eead34debca942f39

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: ktav-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 246.7 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.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 40e612822af13b2a7fd4d32d7fe8f5712fef9aafd4f5807d148b067b11f9de9c
MD5 6b451c9d3e2ea09fa9f3334ec24c0c37
BLAKE2b-256 586400c9d45212adbd42a97880a33ae1cf1b90ecd47566f3020ee55cbd5124d7

See more details on using hashes here.

Provenance

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