Metadata-Version: 2.3
Name: lentezinha
Version: 0.2.0
Summary: Add your description here
Author: Ivan Ramos Pagnossin
Author-email: Ivan Ramos Pagnossin <puchacz.23@proton.me>
Requires-Dist: pydantic>=2.13.4
Requires-Python: >=3.14
Description-Content-Type: text/markdown

# Lentezinha

Tiny Lens for Python: a single 30 KiB module to improve readability. "Lentezinha" means "little lens" in Brazilian Portuguese.

## Motivation

I don't like to do this: `user.get("profile", {}).get("age"))`, where `user` is a nested dictionary. I'd rather say `user.get("profile.age")`.

## Usage

```python
from lentezinha import read, update

user = {"name": "Ana", "profile": {"age": 20}}

read(user, "profile.age")  # == 20
update(user, "profile.age", lambda a: a + 1)  # Updates age to 21
```

You can use a `Lens` instance if you plan to access nested attributes many times:

```python
from lentezinha import Lens
age = Lens("profile.age")

print(age.get(user))  # == 20

age.set(user, 27)  # == 27

age.set(user, lambda a: a + 1)  # == 28
```

It also works with Pydantic:

```python
from lentezinha import Lens
from pydantic import BaseModel

class User(BaseModel):
    profile: dict

user = User(profile={"age": 20})

age = Lens("profile.age")
age.get(user)  # == 20
age.set(user, 27)  # == 27
```

## Installation

```shell
pip install lentezinha
```

## TODO

- Compose lenses
