Skip to main content

pyapi

A lightweight Python library to detect structural changes in JSON data.

pyapi compares two JSON-compatible data structures and identifies changes in their structure and data types, without reporting ordinary value changes.

It is useful for detecting changes in API response structures, checking compatibility between API versions, and identifying unexpected changes in JSON data.

Features

  • Key Addition Detection — Identifies keys present in the new structure but missing from the old structure.
  • Key Removal Detection — Identifies keys present in the old structure but missing from the new structure.
  • Type Change Detection — Detects when a value's data type changes between two structures.
  • Nested Structure Comparison — Detects structural changes within nested JSON objects.
  • Value-Agnostic Comparison — Ignores changes to values when their data types remain the same.
  • Readable Change Paths — Reports the location of each detected change using JSON-style paths.

Installation

pip install pyapi-diff

Quick Start

from pyapi import json_compare

old = {
  "id": 101,
  "name": "abc",
  "age": 55,
  "address": {
    "city": "san francisco",
    "pincode": 12345
  },
  "skills": ["Python", "SQL"]
}

new = {
  "id": "101",
  "name": "xyz",
  "contact": 1234567890,
  "address": {
    "city": "Seattle",
    "pincode": 1234
  },
  "skills": ["Python", "SQL"]
}

json_compare(old, new)

Output

key_removed: $.age (old = 55, new = None)
key_added: $.contact (old = None, new = 1234567890)
type_changed: $.id (old = 'number', new = 'string')

Detected Change Types

Change Type Description
key_added A key exists in the new structure but not in the old structure.
key_removed A key exists in the old structure but not in the new structure.
type_changed A value's data type differs between the old and new structures.

How It Works

pyapi compares an old JSON-compatible structure against a new one and reports structural differences.

For example, consider these two objects:

Old structure

{
  "user": {
    "id": 101,
    "name": "Alice"
  }
}

New structure

{
  "user": {
    "id": "101",
    "name": "Bob",
    "email": "alice@example.com"
  }
}

The detected changes include:

  • type_changed at $.user.id, because id changes from a number to a string.
  • key_added at $.user.email, because email is newly introduced.

The change from "Alice" to "Bob" is ignored because the value remains a string.

Use Cases

  • API Response Comparison: Identify structural changes between responses from different API versions.
  • Breaking Change Detection: Find removed keys or changed data types that could break API consumers.
  • Regression Testing: Detect unexpected changes in JSON response structures during development.
  • Data Validation: Check whether incoming JSON data maintains the expected structure.
  • Configuration Comparison: Identify added or removed settings and changes in their data types.

Requirements

  • Python 3.10 or later

Development

Clone the repository:

git clone YOUR_REPOSITORY_URL
cd pyapi

Install dependencies using uv:

uv sync

Run the example or test script:

uv run python tests/test1.py

Project Status

pyapi is currently in its initial release, 0.0.1.

The current focus is on detecting JSON structural and data type changes. Additional functionality may be introduced in future releases.

Contributing

Contributions, bug reports, and feature suggestions are welcome.

Feel free to open an issue or submit a pull request in the project's GitHub repository.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Metadata

Release files for pyapi-diff 0.0.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 pyapi-diff 0.0.2
File Size Uploaded Provenance
pyapi_diff-0.0.2.tar.gz 14.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pyapi-diff 0.0.2
File Interpreter ABI Platform
pyapi_diff-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 19.0 kB

Release files / pyapi_diff-0.0.2.tar.gz

Download URL pyapi_diff-0.0.2.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0f4313b25db5f624c17686b1cfe6be2cf30a8562a88a068e2bb6b7be424ea9d1
BLAKE2b-256 checksum
How to use checksums
94447329871d1c2f26994c48a6ac2d74e5ab7196234a2a60b882f9a4ec287ada
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / pyapi_diff-0.0.2-py3-none-any.whl

Download URL pyapi_diff-0.0.2-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fcf4404be42d830a7602484d2c44e8245c433badb07f0f5897ecd979d3d77dc9
BLAKE2b-256 checksum
How to use checksums
82dba7c87ef8acdd295c0585a19b57cf9fbbb5ce495e158f0032294f6f5869b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for pyapi-diff 0.0.2

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.

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