Coola: Object Equality Checker

1.1.3 · active · verified Mon Apr 13

Coola is a Python library designed for robustly checking equality between two complex or nested Python objects. It provides a flexible mechanism to compare various data structures, going beyond Python's default `==` operator for deep and custom comparisons. The library is actively maintained with frequent minor releases, ensuring ongoing development and improvements.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `objects_are_equal` to perform deep comparisons on nested dictionaries and lists. It shows both identical and differing structures, highlighting the library's ability to handle complex objects.

from coola.equality import objects_are_equal

obj1 = {'a': 1, 'b': [2, {'c': 3}], 'd': {'e': 4}}
obj2 = {'d': {'e': 4}, 'b': [2, {'c': 3}], 'a': 1}
obj3 = {'a': 1, 'b': [2, {'c': 99}], 'd': {'e': 4}}

# Deep comparison of two equal nested objects (order-independent for dicts)
print(f"obj1 == obj2: {objects_are_equal(obj1, obj2)}")

# Deep comparison of two different nested objects
print(f"obj1 == obj3: {objects_are_equal(obj1, obj3)}")

# Comparison with a custom tolerance for floats (example for potential feature)
float_obj1 = {'x': 1.000000001}
float_obj2 = {'x': 1.000000002}
# For demonstration, assume a tolerance parameter, actual API might vary
# print(f"float_obj1 == float_obj2 with tolerance: {objects_are_equal(float_obj1, float_obj2, atol=1e-8)}")

view raw JSON →