Skip to main content

deepcompare

PyPI Test Status Codecov

deepcompare is a library to deeply compare data structures with each other. It can check if two data structures contain the same data, or if a data structure is a subset of another data structure. The library supports Sequence (e.g. list or tuple) and Mapping (e.g. dict) types for the deep comparison.

Installation

With a correctly configured pipenv toolchain:

pipenv install python-deepcompare

You may also use classic pip to install the package:

pip install python-deepcompare

Getting started

How it works

  • As a default, the comparison treats all Sequence and all Mapping types the same (e.g. (1, 2, 3) is equal to [1, 2, 3]). To enable strict type checks, use the strict keyword argument.
  • The partial_compare method checks if the data structure given as the second parameter is a subset of the data structure given as the first parameter.
    • For Mapping types this means, that all keys of the second data structure are also keys on the first data structure, and the values of the keys are also equal (e.g. {'a': 1, 'b': 2} is a subset of {'a': 1, 'b': 2, 'c': 3}, but {'a': 1, 'b': 2, 'd': 4} is not).
    • For Sequence types this means, that all values of the second data structure are also values of the first data structure, and the values are in the same order (e.g. [1, 3, 5] is a subset of [1, 2, 3, 4, 5], but [1, 5, 3] is not).

Usage

import deepcompare

# test if two data structures are equal, but the types to not need to match exactly
deepcompare.compare(
    {'key1': (1, 2, 3), 'key2': {'key3': [4, 5, 6]}},
    {'key1': [1, 2, 3], 'key2': {'key3': (4, 5, 6)}},
)  # returns: True

# test if two data structures are equal, and make sure the types match exactly
deepcompare.compare(
    {'key1': (1, 2, 3), 'key2': {'key3': [4, 5, 6]}},
    {'key1': [1, 2, 3], 'key2': {'key3': (4, 5, 6)}},
    strict=True,
)  # returns: False

# test if the second data structure is contained within the first, but
# the types to not need to match exactly
deepcompare.partial_compare(
    {'key1': (1, 2, 3), 'key2': {'key3': [4, 5, 6]}, 'key4': True},
    {'key1': [1, 2], 'key2': {'key3': (4, 6)}},
)  # returns: True

# test if the second data structure is contained within the first, and
# make sure the types match exactly
deepcompare.partial_compare(
    {'key1': (1, 2, 3), 'key2': {'key3': [4, 5, 6]}, 'key4': True},
    {'key1': [1, 2], 'key2': {'key3': (4, 6)}},
    strict=True,
)  # returns: False

List of developers

Download files

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

Source Distribution

python_deepcompare-2.2.0.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_deepcompare-2.2.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file python_deepcompare-2.2.0.tar.gz.

File metadata

  • Download URL: python_deepcompare-2.2.0.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.7

File hashes

Hashes for python_deepcompare-2.2.0.tar.gz
Algorithm Hash digest
SHA256 facd3267f1f945b78079de9167e2b94d5c7d2e3fed8dac987c73d83f9eadc396
MD5 611133e655d55df06c0c02efd5f8caef
BLAKE2b-256 5c57c43cbbb54bb6220b6d2589e05da598ce6adc7975c7aa473ed0b2181a1540

See more details on using hashes here.

File details

Details for the file python_deepcompare-2.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_deepcompare-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 318835c5decbe8cc565b1c7c815f502037c61e2a84655717ab189906b3299a88
MD5 e8c86a2b11690eece8740ccfe643c529
BLAKE2b-256 b8f2801cca7c62e19c576124cdc172e77ca30382ec443dcc3eede62538359b65

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2.2.0 This release

2 files

2.1.0

2 files

1.0.1

2 files

1.0.0

2 files

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