Skip to main content

pairl (Python)

PyPI Python License

Reference implementation of PAIRL — a compact, human-readable, machine-parseable message format for agent-to-agent communication. This package parses PAIRL, validates it (rules V1–V12), canonicalizes and SHA-256–hashes it, and renders it back to human-readable text. Pure standard library, no runtime dependencies.

PAIRL v1.6

This release tracks spec v1.6 in lockstep. v1.6 adds no new grammar — the extractive-quote and marked-condensate carriage forms for #req/#rpt live inside ordinary quoted strings and kvpairs, so this parser handles v1.6 bodies unchanged (two v1.6 cases are part of the conformance corpus). The new rules V13–V15 are delivery-/encoder-side and out of message-parser scope by design (SPEC §12a, §3.1/V15).

Why PAIRL?

Agents exchanging context in natural language burn tokens and let facts drift; raw JSON is rigid and verbose. PAIRL separates a lossy intent channel (tone, length, speech act) from a lossless fact channel (names, numbers, evidence) and references large content instead of copying it.

Natural language JSON PAIRL
Token cost high medium–high low (≈40–90% less)
Facts preserved losslessly ✗ (drift) ✓ ✓ (dedicated channel)
Tone/intent without verbosity verbose ✗ ✓ (compact intents)
Validatable on the wire ✗ schema ✓ (V1–V12)
Speaker/turn attribution in one body ✗ manual ✓ (turn markers)
Repeated records compacted ✗ ✗ ✓ (columnar blocks)
Content-addressable (stable hash) ✗ canonical JSON ✓ (§9 + SHA-256)
Human-renderable ✓ poor ✓ (renderer)

Protocol architecture

A PAIRL message is a header block (@v, @id, @ts, threading, budget, …) followed by a blank line and body records:

  • Intents — req{t=topic,s=f,l=2} — the lossy channel: speech act + style.
  • Lossless records — #fact, #ref, #evid, #rule — exact data, treated as ground truth (never paraphrased).
  • Economic records — #cost, #quota — native budget/usage tracking.
  • Tool records — #call, #ret, #think, #edit — compact tool-use chains.
  • Turn markers (v1.3) — #u1/#a2 — attribute records to a speaker when a whole conversation is compressed into one body.
  • Columnar blocks (v1.5) — #evid[claim,src,conf] + positional rows — declare a repeated key schema once instead of per record (~40% fewer tokens, lossless).

Canonicalization & hashing (§9). Columnar blocks expand to #type key=value records before hashing, so a message produces the same SHA-256 whether sent in columnar or key=value form — enabling content-addressing, dedup, and caching.

Install

pip install pairl

Library

import pairl

msg = pairl.parse(open("message.pairl").read())

res = pairl.validate(msg)            # rules V1–V12
print(res.valid, res.errors, res.warnings)

print(pairl.compute_hash(msg))       # canonical SHA-256 (columnar-invariant)
print(pairl.render(msg))             # faithful human-readable rendering

CLI

python -m pairl validate [--strict] message.pairl   # exit 0 ok / 1 invalid
python -m pairl render   message.pairl
python -m pairl hash     message.pairl
python -m pairl canon    message.pairl

Test

cd impl/python && python -m unittest discover -s tests

Licensed under Apache-2.0.

Metadata

Release files for pairl 1.6.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pairl 1.6.2
File Size Uploaded
pairl-1.6.2.tar.gz 15.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pairl 1.6.2
File Interpreter ABI Platform
pairl-1.6.2-py3-none-any.whl Python 3 none any Details

Total release size: 32.8 kB

Release files / pairl-1.6.2.tar.gz

Download URL pairl-1.6.2.tar.gz
Size 15.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5cea0625394370403dcd4fbf47793c6d373ad5d2a9e2e1cd257967981597ac37
BLAKE2b-256 checksum
How to use checksums
88fa263d0c854438d785c6550fab12b81d0bb510a53a00b9bc01547df8b15492
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 18, 2026.

Transparency log

Release files / pairl-1.6.2-py3-none-any.whl

Download URL pairl-1.6.2-py3-none-any.whl
Size 16.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
11606e13db5f8fe4951ec6d5eec4cd75506e66f452a284269389a8521bd64f2d
BLAKE2b-256 checksum
How to use checksums
9ea5ce4f3f05e9c6cb057283ba8d93c2f28061ca323075b872e2888748d4c541
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 18, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.6.2 This release

2 release files

1.6.0

2 release files

1.5.2

2 release files

1.5.1

2 release files

1.5.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page