Python implementation of the Twilic wire format and session-aware encoder/decoder.
This package's default encode / decode API targets Twilic v2.
- Dynamic encoding/decoding (
encode,decode) - Schema-aware encoding (
encode_with_schema) - Batch and micro-batch encoding (
encode_batch,SessionEncoder.encode_micro_batch) - Stateful features (base snapshots, state patch, template batch, control stream, trained dictionary)
twilic-python/
src/twilic/ # wire, model, codec, session, protocol, v2
tests/ # spec conformance and interop tests
scripts/ # Rust interop fixtures and smoke checks
docs/
- Python 3.12 or later
- uv for development
pip install twilicOr with uv:
uv add twilicimport twilic
value = twilic.new_map(
twilic.entry("id", twilic.new_u64(1001)),
twilic.entry("name", twilic.new_string("alice")),
)
data = twilic.encode(value)
decoded = twilic.decode(data)
print(twilic.equal(decoded, value))import twilic
enc = twilic.new_session_encoder(twilic.default_session_options())
value = twilic.new_map(
twilic.entry("id", twilic.new_u64(1)),
twilic.entry("role", twilic.new_string("admin")),
)
enc.encode(value)Run checks locally:
uv sync
uv run ruff format --check .
uv run ruff check .
uv run pytestRust client interop smoke check (Python server -> Rust client):
bash scripts/check-rust-client-interop.shPython client interop smoke check (Rust server -> Python client):
bash scripts/check-python-client-interop.shRun both directions:
bash scripts/check-interop.shNote: interop scripts expect ../twilic-rust to exist as a sibling directory.
Documentation is formatted and linted with Prettier and markdownlint (see docs/CONTRIBUTING.md).
- CI workflow:
.github/workflows/ci.yml - Interop workflow:
.github/workflows/interop.yml - Release workflow:
.github/workflows/publish-pypi.yml(tagv*must matchpyproject.tomlversion)
This package mirrors the Twilic wire format spec at twilic/twilic and stays in lockstep with the Rust, Go, and Zig reference implementations.
See docs/SPEC-TEST-TRACEABILITY.md for the spec-section to test mapping.
This project is licensed under the MIT License - see the LICENSE file for details.