Recursive subset comparison for complex nested Python data structures
Project description
deepset - Recursive Subset Comparison for Python
deepset provides recursive subset comparison for complex nested Python data structures. It implements intuitive subset/superset semantics for sets, lists, dictionaries, and tuples, allowing you to express relationships like "this nested structure is contained within that one" naturally.
Features
- 🔍 Recursive comparison of deeply nested data structures
- 📊 Subset semantics for sets, lists, dictionaries, and tuples
- 🔗 Automatic conversion of regular Python objects for comparison
- 🚫 Zero dependencies - uses only Python standard library
- ✅ Comprehensive test suite with 100% coverage
Quick Start
from deepset import deepset
# Set subset comparison
assert deepset({1, 2}) <= deepset({1, 2, 3})
# Nested structure comparison
assert deepset({('a', frozenset({2}))}) <= deepset({('a', frozenset({2, 3}))})
# List sequential matching (order matters, intervening items allowed)
assert deepset([1, 3]) <= deepset([1, 2, 3, 4])
# Dictionary key-value subset
assert deepset({'a': 1}) <= deepset({'a': 1, 'b': 2})
# Mixed nested structures
data1 = {'sets': {frozenset({1, 2})}, 'lists': [[1, 2]]}
data2 = {'sets': {frozenset({1, 2, 3})}, 'lists': [[1, 2, 3]]}
assert deepset(data1) <= deepset(data2)
Installation
pip install deepset
Comparison Semantics
Sets and Frozensets
Traditional subset comparison with recursive element matching:
# Simple subset
deepset({1, 2}) <= deepset({1, 2, 3}) # True
# Nested sets - recursive comparison
deepset({frozenset({1, 2})}) <= deepset({frozenset({1, 2, 3})}) # True
Lists and Tuples
Sequential subset matching where items from the first must appear in order in the second, but the second can have intervening items:
# Sequential matching with intervening items
deepset([1, 3]) <= deepset([1, 2, 3, 4]) # True
deepset([1, 3]) <= deepset([3, 1]) # False (wrong order)
# Nested lists
deepset([[1, 2]]) <= deepset([[1, 2, 3]]) # True
Dictionaries
Key subset with recursive value comparison:
# Key subset + value comparison
deepset({'a': 1}) <= deepset({'a': 1, 'b': 2}) # True
deepset({'a': [1, 2]}) <= deepset({'a': [1, 2, 3]}) # True
deepset({'a': 1, 'c': 1}) <= deepset({'a': 1, 'b': 2}) # False (missing key 'c')
Operators
All standard comparison operators are supported:
deepset({1, 2}) < deepset({1, 2, 3}) # True (strict subset)
deepset({1, 2}) <= deepset({1, 2}) # True (subset or equal)
deepset({1, 2}) == deepset({1, 2}) # True (equal)
deepset({1, 2, 3}) >= deepset({1, 2}) # True (superset or equal)
deepset({1, 2, 3}) > deepset({1, 2}) # True (strict superset)
Development
# Clone repository
git clone https://github.com/perry-kundert/python-deepset.git
cd python-deepset
# Use Nix supplied Python, Virtual Env
make nix-venv # Provides dev environment shell
make nix-venv-test # Runs Makefile 'test' target in Nix dev venv
# Install development dependencies
make install-dev
# Run tests
make test
# Check code style
make style_check
# Build package
make build
License
MIT License. See LICENSE file for details.
Author
Perry Kundert perry@dominionrnd.com
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file deepset-0.1.0.tar.gz.
File metadata
- Download URL: deepset-0.1.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d1d288be0bc84699686a35fafe9a42f9b24ff7aad14b0eeb11d55d44c549b0c
|
|
| MD5 |
36124756fb063b875355275da7f09427
|
|
| BLAKE2b-256 |
2e92c9d41a9b2c87174c799c3bf8092258d6a950bb38687b846f6bfff93afc82
|
Provenance
The following attestation bundles were made for deepset-0.1.0.tar.gz:
Publisher:
release.yml on pjkundert/python-deepset
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
deepset-0.1.0.tar.gz -
Subject digest:
8d1d288be0bc84699686a35fafe9a42f9b24ff7aad14b0eeb11d55d44c549b0c - Sigstore transparency entry: 314861594
- Sigstore integration time:
-
Permalink:
pjkundert/python-deepset@00fa16ef452d326159b0c6c99c07f3b82358b417 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/pjkundert
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@00fa16ef452d326159b0c6c99c07f3b82358b417 -
Trigger Event:
push
-
Statement type:
File details
Details for the file deepset-0.1.0-py3-none-any.whl.
File metadata
- Download URL: deepset-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e3529e30d86285ddb67317a9c6906a4610b7b23b7fc3febf0400e261981121c
|
|
| MD5 |
0a871ee3ab95a1d67d5282ee3c32ad26
|
|
| BLAKE2b-256 |
4634d129839c9afa88a92827f9565565f488ca067cb259079a1ca7e26057d635
|
Provenance
The following attestation bundles were made for deepset-0.1.0-py3-none-any.whl:
Publisher:
release.yml on pjkundert/python-deepset
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
deepset-0.1.0-py3-none-any.whl -
Subject digest:
0e3529e30d86285ddb67317a9c6906a4610b7b23b7fc3febf0400e261981121c - Sigstore transparency entry: 314861602
- Sigstore integration time:
-
Permalink:
pjkundert/python-deepset@00fa16ef452d326159b0c6c99c07f3b82358b417 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/pjkundert
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@00fa16ef452d326159b0c6c99c07f3b82358b417 -
Trigger Event:
push
-
Statement type: