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

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.1

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.1
File Size Uploaded Provenance
pyapi_diff-0.0.1.tar.gz 14.1 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 18.9 kB

Release files / pyapi_diff-0.0.1.tar.gz

Download URL pyapi_diff-0.0.1.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9ab4e8c8fe50eec2345318d282f45aedff1715ff653989e10f612723943def50
BLAKE2b-256 checksum
How to use checksums
7478e4b356921915706907ef4739ea5746aaa134cd084d2d14f0d3fe654355b4
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.1-py3-none-any.whl

Download URL pyapi_diff-0.0.1-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0b5f359ab15deb75deceac87963e7d5a7ba0870937daa8b098807b6af728e8b0
BLAKE2b-256 checksum
How to use checksums
44e65840fd53e270467dab1782dc53c3325c4edbc072c07fa96d3f1e90333083
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.1

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