Skip to main content

kvsig for Python

Keyed, content-derived ids for LLM chat conversations. This is the reference implementation of the kvsig specification (kvsig/1, draft 0.1): pure Python, no third-party dependencies, typed.

A gateway or router that sees a stream of stateless chat requests can use it to tell which conversation each request belongs to, which prefix it shares with an earlier request, and whether the system prompt or the tools changed, the same way in OpenAI Chat Completions, OpenAI Responses and Anthropic Messages.

Install

pip install kvsig

Python 3.10 or later.

Quickstart

from kvsig import Key, canonicalize, ids

key = Key.generate(epoch=1)  # one per deployment; keep it secret and keep it
body = {
    "model": "m",
    "messages": [
        {"role": "system", "content": "You answer geography questions."},
        {"role": "user", "content": "What is the capital of France?"},
        {"role": "assistant", "content": "Paris."},
        {"role": "user", "content": "And Spain?"},
    ],
}

canon = canonicalize(body, "openai.chat")  # None means "this request gets no ids"
if canon is not None:
    i = ids(canon, key)
    i.conv  # conversation id: stable across turns, reminders, dates and tool changes
    i.nodes[-1]  # id of the whole prefix, like a git commit
    i.sys, i.tools  # the two halves of the head: which one changed?

The same conversation sent as "anthropic.messages" or "openai.responses" gives the same ids. Hostile or oversized input never raises; it gives None.

To check your install against the published test vectors, use the published test key (epoch 0) on the vector openai.chat/conv-base:

import json
from kvsig import TEST_KEY, canonicalize, ids

v = json.load(open("vectors/v1/openai.chat/conv-base.json"))
i = ids(canonicalize(v["input"], v["dialect"]), TEST_KEY)
assert i.conv == v["expect"]["keys"]["0"]["conv"]  # "00fdd9bdfb7d14a82cb5d7d4d70ac60046"

What 0.1 guarantees

  • For the spec label kvsig/1 and the loose profile loose/1 (the default), canonical bytes and ids are pinned by the vectors/v1 test vectors. No later release changes them; a change ships under a new label or profile version instead.
  • LOOSE_V2 (loose/2, decision 0005) is included but experimental: it is not covered by the vectors yet and its ids may change until its decision is accepted.
  • The full policy is in the specification.

Learn more

Development

From python/ in a checkout:

uv run --with pytest pytest -q
uv run --with ruff ruff check . && uv run --with ruff ruff format --check .
python ../conformance/run.py -- python ../conformance/adapters/python_adapter.py

Licence

Apache-2.0. The specification text is licensed separately under CC BY 4.0; see NOTICE.

Metadata

Release files for kvsig 0.1.0

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

Source distribution (sdist)

Source distribution for kvsig 0.1.0
File Size Uploaded Provenance Actions
kvsig-0.1.0.tar.gz 37.7 kB With provenance Details for kvsig-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 68.4 kB

Release files / kvsig-0.1.0.tar.gz

Download URL kvsig-0.1.0.tar.gz
Size 37.7 kB
Tags Source
SHA-256 checksum
How to use checksums
bf445aefd08d6cce08b3ad6fcc5cc6e06529a293ef3192cca071818e5cf853ec
BLAKE2b-256 checksum
How to use checksums
25e2ae51eb02d5f03701b6c188f19a99c16303e2845078d80fc001aa47ad1532
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 22, 2026.

Transparency log

Release files / kvsig-0.1.0-py3-none-any.whl

Download URL kvsig-0.1.0-py3-none-any.whl
Size 30.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5c53db48245bcdcf810aa5afd7b21d8d70a1258d7da9de2cd488cb6af360473d
BLAKE2b-256 checksum
How to use checksums
7710475764265277b989162d80f085298c74b296d867bcf80a32ec1e7ea2f0c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 22, 2026.

Transparency log

Security for kvsig 0.1.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for kvsig-0.1.0.tar.gz

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 Nov 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

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