Metadata-Version: 2.1
Name: pythonwrench
Version: 0.4.5
Summary: Python library with tools for typing, manipulating collections, and more!
Author-email: "Étienne Labbé (Labbeti)" <labbeti.pub@gmail.com>
Maintainer-email: "Étienne Labbé (Labbeti)" <labbeti.pub@gmail.com>
License: MIT License
        
        Copyright (c) 2026 Labbeti
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://pypi.org/project/pythonwrench/
Project-URL: Documentation, https://pythonwrench.readthedocs.io/
Project-URL: Repository, https://github.com/Labbeti/pythonwrench.git
Project-URL: Changelog, https://github.com/Labbeti/pythonwrench/blob/main/CHANGELOG.md
Project-URL: Tracker, https://github.com/Labbeti/pythonwrench/issues
Keywords: python,tools,utilities
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering
Classifier: Operating System :: OS Independent
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX
Requires-Python: <3.15,>=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: typing-extensions>=4.10.0
Provides-Extra: dev

# pythonwrench

<center>

<a href="https://www.python.org/">
    <img alt="Python" src="https://img.shields.io/badge/-Python 3.8+-blue?style=for-the-badge&logo=python&logoColor=white">
</a>
<a href="https://github.com/Labbeti/pythonwrench/actions">
    <img alt="Build" src="https://img.shields.io/github/actions/workflow/status/Labbeti/pythonwrench/test.yaml?branch=main&style=for-the-badge&logo=github">
</a>
<a href='https://pythonwrench.readthedocs.io/en/stable/?badge=stable'>
    <img src='https://readthedocs.org/projects/pythonwrench/badge/?version=stable&style=for-the-badge' alt='Documentation Status' />
</a>

Python library with tools for typing, manipulating collections, and more!

</center>


## Installation

With uv:
```bash
uv add pythonwrench
```

With pip:
```bash
pip install pythonwrench
```

This library has been tested on all Python versions **3.8 - 3.14**, requires only `typing_extensions>=4.10.0`, and runs on **Linux, Mac and Windows** systems.

## Examples

### Typing

Check generic types with `isinstance_generic` :

```python
>>> import pythonwrench as pw
>>>
>>> # Behaves like builtin isinstance() :
>>> pw.isinstance_generic({"a": 1, "b": 2}, dict)
... True
>>> # But works with generic types !
>>> pw.isinstance_generic({"a": 1, "b": 2}, dict[str, int])
... True
>>> pw.isinstance_generic({"a": 1, "b": 2}, dict[str, str])
... False
```

... or check specific methods with protocols classes beginning with `Supports`
```python
>>> import pythonwrench as pw
>>>
>>> isinstance({"a": 1, "b": 2}, pw.SupportsIterLen)
... True
>>> isinstance({"a": 1, "b": 2}, pw.SupportsGetitemLen)
... True
```

Finally, you can also force argument type checking with `check_args_types` function :

```python
>>> import pythonwrench as pw

>>> @pw.check_args_types
>>> def f(a: int, b: str) -> str:
>>>     return a * b

>>> f(1, "a")  # pass check
>>> f(1, 2)  # raises TypeError from decorator
```

### Collections

Provides functions to facilitate iterables processing, like `unzip` :

```python
>>> import pythonwrench as pw
>>>
>>> list_of_tuples = [(1, "a"), (2, "b"), (3, "c"), (4, "d")]
>>> pw.unzip(list_of_tuples)
... [1, 2, 3, 4], ["a", "b", "c", "d"]
>>> pw.flatten(list_of_tuples)
... [1, "a", 2, "b", 3, "c", 4, "d"]
```

... or mathematical functions like `prod` or `argmax` :

```python
>>> import pythonwrench as pw
>>>
>>> values = [3, 1, 6, 4]
>>> pw.prod(values)
... 72
>>> pw.argmax(values)
... 2
>>> pw.is_sorted(values)
... False
```

Easely converts common python structures like list of dicts to dict of lists :

```python
>>> import pythonwrench as pw
>>>
>>> list_of_dicts = [{"a": 1, "b": 2}, {"a": 3, "b": 4}]
>>> pw.list_dict_to_dict_list(list_of_dicts)
... {"a": [1, 3], "b": [2, 4]}
```

... or dict of dicts :
```python
>>> import pythonwrench as pw
>>>
>>> dict_of_dicts = {"a": {"x": 1, "y": 2}, "b": {"x": 3, "y": 4}}
>>> pw.flat_dict_of_dict(dict_of_dicts)
... {"a.x": 1, "a.y": 2, "b.x": 3, "b.y": 4}
```

### Disk caching (memoize)

```python
>>> import pythonwrench as pw
>>>
>>> @pw.disk_cache_decorator
>>> def heavy_processing():
>>>     # Lot of stuff here
>>>     ...
>>>
>>> data1 = heavy_processing()  # first call function is called and the result is stored on disk
>>> data2 = heavy_processing()  # second call result is loaded from disk directly
```

### Semantic versionning parsing

```python
>>> import pythonwrench as pw
>>> version = pw.Version("1.12.2")
>>> version.to_tuple()
... (1, 12, 2)
>>> version = pw.Version("0.5.1-beta+linux")
>>> version.to_tuple()
... (0, 5, 1, "beta", "linux")

>>> Version("1.3.1") < Version("1.4.0")
... True
```

### Serialization

```python
>>> import pythonwrench as pw
>>>
>>> list_of_dicts = [{"a": 1, "b": 2}, {"a": 3, "b": 4}]
>>> pw.dump_csv(list_of_dicts, "data.csv")
>>> pw.dump_json(list_of_dicts, "data.json")
>>> pw.load_json("data.json") == list_of_dicts
... True
```

## Contact
Maintainer:
- [Étienne Labbé](https://labbeti.github.io/) "Labbeti": labbeti.pub@gmail.com
