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:

  • Intentsreq{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

Links

Licensed under Apache-2.0.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pairl-1.6.2.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pairl-1.6.2-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file pairl-1.6.2.tar.gz.

File metadata

  • Download URL: pairl-1.6.2.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pairl-1.6.2.tar.gz
Algorithm Hash digest
SHA256 5cea0625394370403dcd4fbf47793c6d373ad5d2a9e2e1cd257967981597ac37
MD5 fc18106e776ba45879da685434ac64be
BLAKE2b-256 88fa263d0c854438d785c6550fab12b81d0bb510a53a00b9bc01547df8b15492

See more details on using hashes here.

Provenance

The following attestation bundles were made for pairl-1.6.2.tar.gz:

Publisher: release.yml on dwehrmann/PAIRL

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pairl-1.6.2-py3-none-any.whl.

File metadata

  • Download URL: pairl-1.6.2-py3-none-any.whl
  • Upload date:
  • Size: 16.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pairl-1.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 11606e13db5f8fe4951ec6d5eec4cd75506e66f452a284269389a8521bd64f2d
MD5 6848494602c9788c17894163768a4e3a
BLAKE2b-256 9ea5ce4f3f05e9c6cb057283ba8d93c2f28061ca323075b872e2888748d4c541

See more details on using hashes here.

Provenance

The following attestation bundles were made for pairl-1.6.2-py3-none-any.whl:

Publisher: release.yml on dwehrmann/PAIRL

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.6.2 This release

2 files

1.6.0

2 files

1.5.2

2 files

1.5.1

2 files

1.5.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page