A token-efficient, repair-tolerant interchange format for LLM I/O — pure-Python encode/decode/fix/validate.
Project description
raif-format (Python)
Pure-Python implementation of RAIF — a token-efficient, repair-tolerant interchange format for LLM input/output. Stdlib only, no runtime dependencies, fully typed (PEP 561).
This package mirrors the canonical TypeScript reference byte-for-byte; parity is pinned by a shared conformance corpus.
- Spec & monorepo: https://github.com/skrrt-sh/raif-standard
- JavaScript/TypeScript package:
raif-formaton npm
Install
pip install raif-format # or: uv add raif-format
Installs the raif-format distribution; the import package is raif.
Usage
from raif import encode, decode, decode_lenient, fix, validate, parse_schema
# JSON object -> canonical RAIF (byte-identical to the TS encoder)
encode({"to": "a@b.com", "subject": "hi"})
# 'subject=hi\nto=a@b.com'
# Generation profile (what models are trained to emit)
encode({"items": [{"id": 1}, {"id": 2}]}, {"profile": "generation"})
# RAIF -> JSON (with repair reporting)
decode("a=1\nb=hi")
# {'ok': True, 'value': {'a': 1, 'b': 'hi'}, 'repairs': []}
# Per-leaf recovery — never raises, surfaces truncation
decode_lenient("<raif>\ncity=Oslo\nlat")
# {'value': {'city': 'Oslo'}, 'errors': [...], 'repairs': [...], 'truncated': True}
# Canonicalize (decode -> re-encode); idempotent
fix("```\na=1\n```")
# {'ok': True, 'canonical': 'a=1', 'repairs': [...]}
# Read-only canonicality check
validate("a=1")
# {'ok': True}
# Optional schema-typed decode
schema = parse_schema("priority:n\nnote:s?")
decode("priority=2\nnote=hi", schema)
API
| Function | Returns |
|---|---|
encode(obj, opts=None) |
str (canonical RAIF) |
decode(text, schema=None) |
{"ok", "value"|"error", "repairs"} |
decode_lenient(text, schema=None) |
{"value", "errors", "repairs", "truncated"} |
fix(text, schema=None) |
{"ok", "canonical"|"error", "repairs"} |
validate(text, schema=None) |
{"ok"} or {"ok": False, "errors"} |
parse_schema(decl) |
RaifSchema |
opts is {"profile": "canonical" | "generation", "markers": bool}.
License
Apache-2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file raif_format-0.5.0.tar.gz.
File metadata
- Download URL: raif_format-0.5.0.tar.gz
- Upload date:
- Size: 47.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42cbbcaff6cd0771344edc1068b606acf85ffb2438a98e8eee3cfc5c7b8d9312
|
|
| MD5 |
daefd9efe7e29d7f6aaa6e5e87e70f09
|
|
| BLAKE2b-256 |
a98f18c79cc1b3a056c06dc19e3edb9829ec67ce4fd27746c8169b83028a0e19
|
Provenance
The following attestation bundles were made for raif_format-0.5.0.tar.gz:
Publisher:
py-release.yml on skrrt-sh/raif-standard
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
raif_format-0.5.0.tar.gz -
Subject digest:
42cbbcaff6cd0771344edc1068b606acf85ffb2438a98e8eee3cfc5c7b8d9312 - Sigstore transparency entry: 1816208038
- Sigstore integration time:
-
Permalink:
skrrt-sh/raif-standard@051a98bafae5aefde5c600e08f54a2443f1f26d0 -
Branch / Tag:
refs/tags/py-v0.5.0 - Owner: https://github.com/skrrt-sh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
py-release.yml@051a98bafae5aefde5c600e08f54a2443f1f26d0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file raif_format-0.5.0-py3-none-any.whl.
File metadata
- Download URL: raif_format-0.5.0-py3-none-any.whl
- Upload date:
- Size: 28.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3bae3c1498dcb0817af2a21d90ec3a6a5328fdb0b2e1d4550c4748091cca0d2c
|
|
| MD5 |
bdc28d435355ecffc7c9605c6ca3f664
|
|
| BLAKE2b-256 |
f49875ff5f902fbca652871002baacc1653cff247a792be2a7d6c79c88732d68
|
Provenance
The following attestation bundles were made for raif_format-0.5.0-py3-none-any.whl:
Publisher:
py-release.yml on skrrt-sh/raif-standard
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
raif_format-0.5.0-py3-none-any.whl -
Subject digest:
3bae3c1498dcb0817af2a21d90ec3a6a5328fdb0b2e1d4550c4748091cca0d2c - Sigstore transparency entry: 1816208188
- Sigstore integration time:
-
Permalink:
skrrt-sh/raif-standard@051a98bafae5aefde5c600e08f54a2443f1f26d0 -
Branch / Tag:
refs/tags/py-v0.5.0 - Owner: https://github.com/skrrt-sh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
py-release.yml@051a98bafae5aefde5c600e08f54a2443f1f26d0 -
Trigger Event:
push
-
Statement type: