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 https://github.com/prashantpq/pyapi.git
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.3

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

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.3
File Size Uploaded Provenance
pyapi_diff-0.0.3.tar.gz 14.2 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 19.1 kB

Release files / pyapi_diff-0.0.3.tar.gz

Download URL pyapi_diff-0.0.3.tar.gz
Size 14.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2f7ef8ca3da826c8a35a5c8af9b09b0e60bc777ef8bebbf96c5852f02b7fa97f
BLAKE2b-256 checksum
How to use checksums
7a164ffc9c22fe446e64142f21f67f248a04d057eb8b7707bf87ae73f14546fd
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.3-py3-none-any.whl

Download URL pyapi_diff-0.0.3-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8ea751a3a2f156c5ef6bd01581fd4722d428e89cd1a717a215b9dd0d0a3c75d6
BLAKE2b-256 checksum
How to use checksums
e20050a584e75b4152e951ad35469020d0b201eda9d5671f4e70d72241c13e28
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.3

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