Metadata-Version: 2.5
Name: pyrule
Version: 0.0.2
Summary: Order-preserving, type-aware deduplication for mixed lists.
Project-URL: Homepage, https://github.com/lqxnjk/pyrule
Author: lqxnjk
License: MIT
License-File: LICENSE
Keywords: dedupe,hashable,list,records,unique
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# pyrule

Deduplicate a list while keeping the first occurrence and its position — with
the one detail `set()` gets wrong: **types are preserved**.

## Install

```console
pip install pyrule
```

## The problem

```python
list(set([1, 1.0, True]))     # -> [1]        three rows silently become one
dedupe([1, 1.0, True])        # -> [1, 1.0, True]
```

In Python `1 == 1.0 == True`, so naive deduplication loses records. For data
coming out of CSV, JSON or a database, those are three different values.

## Usage

```python
from pyrule import dedupe, dedupe_key

dedupe(["b", "a", "b"])                  # ['b', 'a']  order kept
dedupe([{"a": 1}, {"a": 1}, {"a": 2}])   # two dicts kept
dedupe_key(1), dedupe_key(1.0)           # ('int', '1'), ('float', '1.0')
```

## Rules

| Input | Key |
| --- | --- |
| `str` / `int` / `float` / `bool` / `None` | `(type name, repr)` |
| anything else | canonical JSON, else `repr` |

Order is always preserved and the returned items are the originals, not copies.

## License

MIT
