Encoding, section decoding, schema helpers, and a command-line interface.
From this directory:
python -m pip install -e .For development:
python -m pip install -e ".[dev]"
python -m pytestThe codec has no third-party runtime dependencies. Pytest is a development dependency; Hatchling builds the package.
from compact import (
decode_stream, encode_bitfield, encode_small_ints,
encode_text, stream, to_base64url,
)
code = to_base64url(stream([
encode_text("NODE-A7F3"),
encode_small_ints([5, 2, 1], width=3),
encode_bitfield([True, False, True, True]),
]))
assert code == "A_oE8QnJ6IilqCboxmjHUUuw"
name, choices, flags = decode_stream(code)
assert name.as_text() == "NODE-A7F3"
assert choices.as_ints() == (5, 2, 1)
assert flags.as_bitfield() == (True, False, True, True)python -m compact encode --text "hi"
python -m compact encode --ints 3,1,4,1,5
python -m compact decode BEhcQ0NIInstalling the package also exposes the equivalent compact command.
The encode command groups repeated options by section type: text, fixed
bits, dynamic chunks, and integers, in that order. Use the Python API
when section order differs from that grouping.
python examples/settings_token.py
python examples/device_beacon.pysettings_token.py maps application choices and flags into a short text
token and recovers the settings. device_beacon.py combines an identifier,
positive counters, and health flags.
The examples demonstrate schema mapping, not complete input validation. See the input contract and wire specification.