Skip to main content

andvari

Deterministic diff of two versions of a JSON Schema, and Pydantic models from one.

andvari diff lists what changed between two versions of a schema, with a severity for each change. andvari models writes Pydantic v2 models for a schema.

Andvari was a dwarf who lived beneath a waterfall, often in the shape of a pike, and kept a hoard of gold. Loki caught him in a net and took all of it, down to the last ring. Andvari could not stop him, so he laid a curse on the ring: it would be the death of whoever owned it.

After Reginsmál and the Prose Edda.

Purpose

Use it for a schema that someone else publishes and may change without notice. Keep a copy of the schema in your repository. In CI, fetch the current schema and run andvari against the copy: any difference fails the build and prints what changed. To accept a change, replace the copy, regenerate the models, fix what no longer fits and commit.

Both commands are deterministic. They use no network and no clock, so the output depends only on the input files.

Usage

Run andvari diff <old.json> <new.json>:

$ cat old.json
{
  "type": "object",
  "required": ["id"],
  "properties": {
    "id": {"type": "integer"},
    "status": {"enum": ["open", "closed"]},
    "note": {"type": "string", "maxLength": 200}
  }
}
$ cat new.json
{
  "type": "object",
  "required": ["id", "owner"],
  "properties": {
    "id": {"type": "number", "description": "Record id"},
    "status": {"enum": ["open", "closed", "archived"]},
    "note": {"type": "string", "maxLength": 100},
    "owner": {"type": "string"}
  }
}
$ andvari diff old.json new.json
old  26b8ae66c96141b28fa168da316f2953dee395b30c3ff7539884218f2dcb8591
new  87d61a59f8abf565a1c13296cb1bb8e50d8793f9a65a6cd79182aa8ad5d813f0
breaking  /note  maxLength  maxLength changed
breaking  /owner  -  required property added
warning  /status  enum  enum loosened
compatible  /id  type  type loosened
annotation  /id  description  description added
5 changes: 2 breaking, 1 warning, 1 compatible, 1 annotation

The fingerprints are the SHA-256 of each schema's canonical JSON (sorted keys, no whitespace), so key order and formatting do not count as changes.

Exit code Meaning
0 diff: same fingerprint, prints unchanged. models: file written
1 The schemas differ
2 Unreadable file, invalid JSON, schema not an object, or a $ref that cannot be inlined (diff); the generator failed (models); wrong arguments

Run andvari models <schema.json> <out.py> [--class-name NAME] to write Pydantic v2 models. The same schema and class name always give the same file; remote $refs are not fetched.

$ cat schema.json
{
  "type": "object",
  "required": ["id"],
  "properties": {
    "id": {"type": "integer"},
    "status": {"enum": ["open", "closed"]}
  }
}
$ andvari models schema.json models.py --class-name Record
$ cat models.py
# generated by andvari from a JSON Schema; do not edit

from __future__ import annotations

from enum import Enum

from pydantic import BaseModel


class Status(Enum):
    open = 'open'
    closed = 'closed'


class Record(BaseModel):
    id: int
    status: Status | None = None

Severity

Change Severity
Path removed breaking
Path added breaking if required or array items, otherwise warning
title, description, examples, $comment, default annotation
required breaking when it becomes true, compatible when false
type compatible when widened (number covers integer) or removed, otherwise breaking
enum breaking when added or a value is gone, warning when values are only added, compatible when removed
minimum, minLength, minItems, ... and the max set breaking when added or tightened, compatible when loosened or removed; a non-numeric value is breaking
Any other keyword breaking when added, removed or changed

What is compared

Local $refs (#/...) are inlined first; a remote or unresolvable $ref is an error. A $ref with sibling keywords becomes allOf: [target, siblings] when the two share a keyword, otherwise the siblings are merged into the target. properties and items are followed and each node gets a path (/, /owner, /tags/*). Every other keyword on a node is compared as a whole value.

Limits

  • It compares what the schemas say. It does not decide which data is valid.
  • A change inside a combinator or conditional (oneOf, anyOf, allOf, if, ...) is reported as "changed", whatever its effect.
  • Generated models can be looser than the schema, because the generator cannot express every constraint.
  • A change to a definition nothing references changes the fingerprint but lists no change; the command still exits 1.

Python

from andvari import diff, fingerprint

old = {"type": "object", "properties": {"id": {"type": "integer"}}}
new = {"type": "object", "properties": {"id": {"type": "string"}}}

print(fingerprint(old) == fingerprint(new))
for change in diff(old, new):
    print(change.severity, change.path, change.keyword, change.reason)

Setup and tests

uv sync
uv run pytest

Metadata

Release files for andvari 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 andvari 0.1.0
File Size Uploaded Provenance Actions
andvari-0.1.0.tar.gz 11.2 kB Without provenance Details for andvari-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 23.9 kB

Release files / andvari-0.1.0.tar.gz

Download URL andvari-0.1.0.tar.gz
Size 11.2 kB
Tags Source
SHA-256 checksum
How to use checksums
32292ce8603a4af177e4f3e3bc88ea45399ef06f29300897e13730cbd169a8f8
BLAKE2b-256 checksum
How to use checksums
ecd58b34e241f19e5129c66523308f3d6749dec237bf7047ed4ec1b7023650bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.12 {"installer":{"name":"uv","version":"0.13.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

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

Download URL andvari-0.1.0-py3-none-any.whl
Size 12.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1fbfe6891281fe3bf3cba3c975b7ccab452111b1a4838971f03d9eeef4ebb5b0
BLAKE2b-256 checksum
How to use checksums
39093c7daddd97a72857af13219d9f6059cf56a03b47d12a3057825185f75273
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.12 {"installer":{"name":"uv","version":"0.13.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for andvari 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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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 No 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