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 paths,
so grab(data, key) works on any key flatmonkey produces.
Install
pip install flatmonkey
Quick start
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 afterNpath segments; deeper structure is kept as a value.
CLI
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 for an LLM-consumable reference (decision tree, worked
examples, troubleshooting).
Design tradeoffs
Some behaviours are intentional and might look surprising — see
LIMITATIONS.md for the deliberate design decisions (tuple/int-key
lossiness, one-way list modes, collision handling, nest carry-through).
License
MIT — see LICENSE.
Metadata
Release files for flatmonkey 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| flatmonkey-0.1.0.tar.gz | 32.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| flatmonkey-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 46.5 kB
Release files / flatmonkey-0.1.0.tar.gz
| Download URL | flatmonkey-0.1.0.tar.gz |
|---|---|
| Size | 32.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1f46db03630d2cc59528d0171dac08c8af0667c2ce3de4b0ef520fb2e43862ae
|
|
BLAKE2b-256 checksum How to use checksums |
24fbea158ba835b585cdc903af770a9a6ad51878303e6515a5e2612b8245a7c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / flatmonkey-0.1.0-py3-none-any.whl
| Download URL | flatmonkey-0.1.0-py3-none-any.whl |
|---|---|
| Size | 14.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
60b223f60341dcbe7a42f31b1ddf08b701fcb2b1dd902b838f2e3fbc22d1e376
|
|
BLAKE2b-256 checksum How to use checksums |
75d6ee9344f7f65bf020525adf5a286581004db186741d53d446ff3d83dc460b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for flatmonkey 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.