Skip to main content

Recursive subset comparison for complex nested Python data structures

Project description

deepset - Recursive Subset Comparison for Python

PyPI version Python versions License

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

deepset-0.1.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

deepset-0.1.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

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

Hashes for deepset-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8d1d288be0bc84699686a35fafe9a42f9b24ff7aad14b0eeb11d55d44c549b0c
MD5 36124756fb063b875355275da7f09427
BLAKE2b-256 2e92c9d41a9b2c87174c799c3bf8092258d6a950bb38687b846f6bfff93afc82

See more details on using hashes here.

Provenance

The following attestation bundles were made for deepset-0.1.0.tar.gz:

Publisher: release.yml on pjkundert/python-deepset

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for deepset-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0e3529e30d86285ddb67317a9c6906a4610b7b23b7fc3febf0400e261981121c
MD5 0a871ee3ab95a1d67d5282ee3c32ad26
BLAKE2b-256 4634d129839c9afa88a92827f9565565f488ca067cb259079a1ca7e26057d635

See more details on using hashes here.

Provenance

The following attestation bundles were made for deepset-0.1.0-py3-none-any.whl:

Publisher: release.yml on pjkundert/python-deepset

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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