Metadata-Version: 2.4
Name: flatmonkey
Version: 0.1.0
Summary: Round-trip-safe structural reshaping between nested and flat data: flatten, unflatten, and nest flat rows.
Author-email: GoodBoy <pythonic@rexbytes.com>
License: MIT License
        
        Copyright (c) 2026 RexBytes
        
        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/rexbytes/flatmonkey
Project-URL: Issues, https://github.com/rexbytes/flatmonkey/issues
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.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: grabmonkey<2,>=1.1
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: hypothesis>=6.0; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Requires-Dist: mypy; extra == "dev"
Dynamic: license-file

# flatmonkey

Round-trip-safe structural reshaping between nested and flat data — flatten nested
dicts/JSON into `{path: value}`, unflatten back, and nest flat rows into nested
records. A lightweight, round-tripping alternative to `pandas.json_normalize`.

Flattened keys are valid [grabmonkey](https://pypi.org/project/grabmonkey/) paths,
so `grab(data, key)` works on any key flatmonkey produces.

## Install

```bash
pip install flatmonkey
```

## Quick start

```python
from flatmonkey import flatten, unflatten, flatten_all, nest

d = {"user": {"name": "Ada", "roles": ["admin", "dev"]}}
flat = flatten(d)
# {'user.name': 'Ada', 'user.roles[0]': 'admin', 'user.roles[1]': 'dev'}

unflatten(flat) == d          # True — the round trip holds

# Batch:
flatten_all([{"a": {"b": 1}}, {"a": {"b": 2}}])
# [{'a.b': 1}, {'a.b': 2}]

# Nest flat rows into nested records:
nest(
    [{"order_id": 1, "product": "x", "qty": 2},
     {"order_id": 1, "product": "y", "qty": 1}],
    group_by=["order_id"],
    nest_fields={"items": ["product", "qty"]},
)
# [{'order_id': 1, 'items': [{'product': 'x', 'qty': 2}, {'product': 'y', 'qty': 1}]}]
```

## Options

- `sep="/"` — choose a separator your dict keys do not contain (any single char
  except `[` / `]`).
- `list_handling="index" | "stringify" | "omit" | "keep"` — how list values are
  rendered. Only the default `"index"` round-trips.
- `max_depth=N` — stop flattening after `N` path segments; deeper structure is kept
  as a value.

## CLI

```bash
flatmonkey flatten data.json -o flat.json
flatmonkey unflatten flat.json
flatmonkey nest rows.json --group-by order_id --nest items=product,qty
cat data.json | flatmonkey flatten -        # '-' reads stdin / writes stdout
```

## Using with AI assistants

See [`SKILL.md`](SKILL.md) for an LLM-consumable reference (decision tree, worked
examples, troubleshooting).

## Design tradeoffs

Some behaviours are intentional and might look surprising — see
[`LIMITATIONS.md`](LIMITATIONS.md) for the deliberate design decisions (tuple/int-key
lossiness, one-way list modes, collision handling, nest carry-through).

## License

MIT — see [`LICENSE`](LICENSE).
