Skip to main content

Utility to diff classes

Project description

classdiff - Python Class Difffer

This is a small library to diff (data) classes. Different from most existing diff tools that produce data structures that show adds, removes or changes, this tool is intended to use for printing a dataclass and higlight the diff with different color coding, similar to the output of Terraform or Pulumi.

Usage

Just pass your classes to the diff function to get back a representation of the diff.

Given the following two classes:

one = SomeResource(
    name="my-data",
    price=2.3,
    quantity=4,
    dangerous=True,
    other=OtherClass(name="OA"),
    not_changed=OtherClass(name="Same"),
)

two = SomeResource(
    name="my-data",
    price=3.3,
    quantity=4,
    dangerous=False,
    other=OtherClass(name="OB"),
    not_changed=OtherClass(name="Same"),
)

Passing them to classdiff.diff in combinations of (one, None), (one, two) and (None, two) and printing the lines in the returned value, the following will be printed. Note that each element in the returned list is of type DiffInfo which implements __repr__ to print with proper prefix and color.

screenshot

Development

All code is formatted and analyzed with black and ruff. Tests are run with pytest.

 poetry run black .
› poetry run ruff check .
› poetry run mypy .
› poetry run pytest tests/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

classdiff-0.1.1.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

classdiff-0.1.1-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file classdiff-0.1.1.tar.gz.

File metadata

  • Download URL: classdiff-0.1.1.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.9 Darwin/22.4.0

File hashes

Hashes for classdiff-0.1.1.tar.gz
Algorithm Hash digest
SHA256 12b8ad54ed85568b6ed5d7e36069d74526f6fe776e69edfaa5ba6ba4e856b94f
MD5 04b46f5948f2552d2ff507c72e153a68
BLAKE2b-256 ce5df80b2031c451cf24f4c2cfa1e7747875c8bc0745ffbf87debcd4891e0a93

See more details on using hashes here.

File details

Details for the file classdiff-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: classdiff-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.9 Darwin/22.4.0

File hashes

Hashes for classdiff-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5c9deaa1be2c1c19e1bb1f4cd2100e50976b5efeb33e44621d0de016a58b5921
MD5 86e62f148bf9551ce8643feb688afb3c
BLAKE2b-256 07fcb16ad1f36c03133ed472813dd4c505fc432bc14c4abe6fae4bf99bcb4824

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page