Metadata-Version: 2.4
Name: lflatten
Version: 0.1.0
Summary: Literal flatten(or unflatten) for data structures
Author-email: Daniel <danielmenezes0822@gmail.com>
License: MIT License
        
        Copyright (c) 2026 dani
        
        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://github.com/oDaniel728/lflatten
Project-URL: Repository, https://github.com/oDaniel728/lflatten
Keywords: python,lib,flatten,lflatten,unflatten,compress
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# `lflatten`

Biblioteca Python **simples, tipada e reversível** para **flatten** e **unflatten** de estruturas aninhadas (`dict` e `list`).

O foco do projeto é:
- simplicidade
- previsibilidade
- round-trip garantido (`unflatten(flatten(x)) == x`)
- suporte a **separador customizável**
- suporte a **escape de separador nas chaves**
- tipagem estática clara

---

## Instalação

Projeto local / em desenvolvimento:

```bash
pip install -e .
````

Ou, se publicado futuramente:

```bash
pip install lflatten
```

---

## Uso básico

> [Documentação](docs/index.md)

### Flatten

```python
from py_simple_flatten import flatten

data = {
    "foo": {
        "bar": 10
    }
}

flatten(data)
```

Resultado:

```python
{
    "foo.bar": 10
}
```

---

### Unflatten

```python
from py_simple_flatten import unflatten

flat = {
    "foo.bar": 10
}

unflatten(flat)
```

Resultado:

```python
{
    "foo": {
        "bar": 10
    }
}
```

---

## Separador customizado (`sep`)

### Exemplo com `sep=":"`

```python
data = {
    "foo:bar": {
        "baz": 10
    }
}

flatten(data, sep=":")
```

Resultado:

```python
{
    "foo\\:bar:baz": 10
}
```

E o round-trip funciona corretamente:

```python
unflatten(
    {"foo\\:bar:baz": 10},
    sep=":"
)
```

Resultado:

```python
{
    "foo:bar": {
        "baz": 10
    }
}
```

---

## Escape de separador

* O separador dentro da chave é **automaticamente escapado**
* `:` → `\:`
* `.` → `\.`
* `\` → `\\`

Isso garante que o `unflatten` reconstrua a estrutura original **sem ambiguidade**.

---

## Listas

Listas são suportadas e reconstruídas corretamente:

```python
data = {
    "a": [1, {"b": 2}]
}

flatten(data)
```

Resultado:

```python
{
    "a.0": 1,
    "a.1.b": 2
}
```

---

## `ignore_none`

Ignora valores `None` durante o flatten:

```python
flatten(
    {"a": None, "b": 1},
    ignore_none=True
)
```

Resultado:

```python
{
    "b": 1
}
```

---

## Tipos

Tipos principais (simplificados):

```python
Flatten = dict[str, Any]
Iter = dict | list
```

A API é compatível com `mypy` / `pyright`.

---

## Garantias do projeto

* ✅ Flatten profundo (`dict` + `list`)
* ✅ Unflatten reversível
* ✅ Separador customizável
* ✅ Escape seguro de chaves
* ✅ Tipagem estática
* ✅ Sem dependências externas

---

## Quando usar

* Serialização de estruturas complexas
* Logs
* Armazenamento chave-valor
* Normalização de dados
* Conversão para DataFrame / CSV

---

## Licença

MIT

---

## Status

Projeto pequeno, estável e intencionalmente minimalista.
Contribuições são bem-vindas se mantiverem o foco em simplicidade e previsibilidade.

