flatten-dict
A flexible utility for flattening and unflattening dict-like objects in Python.
What it is and what it does
flatten-dict provides two core functions: `flatten()` transforms nested dict-like objects into a single-level dictionary with composite keys, and `unflatten()` reverses the process. The package supports multiple key-joining strategies—tuples, filesystem paths, underscores, dots, or custom callables—letting you choose how nested keys combine. You can also enumerate sequences (lists) as indexed keys, preserve or discard empty containers, limit flattening depth, and invert keys and values.
The package is useful when you need to serialize hierarchical data into flat form for storage, comparison, or API transmission, or when you need to reconstruct nested structures from flat representations. It has no external dependencies and works across modern Python versions.
Use it for:
- Convert nested configuration objects into flat key-value pairs for environment variable mapping or flat file storage.
- Flatten API responses or JSON payloads to extract all leaf values with their full key paths.
- Transform flat dictionaries back into nested structures for hierarchical data reconstruction.
- Enumerate list indices as keys to treat sequences uniformly with nested dicts during flattening.
- Customize key joining with domain-specific delimiters or logic via callable reducers.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Converts nested dictionaries into flat key-value pairs and back, with customizable key-joining strategies like tuples, paths, underscores, or dots.
Yes. The package is lightweight, dependency-free, actively maintained, has no known vulnerabilities, and solves a common data-transformation problem with a clean API. Install it if you regularly work with nested dictionaries or need flexible dict flattening/unflattening.
Install
flatten-dict on PyPI
pip
pip install flatten-dictuv
uv add flatten-dictpoetry
poetry add flatten-dictInstalling flatten-dict
Before you install
Low friction: pure Python wheel with no runtime dependencies and active maintenance (last commit 2026-08-06, release 108 days ago). Supports Python 3.10–3.14.
License in practice
MIT license (permissive); you can use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.
Quickstart
from flatten_dict import flatten, unflatten
nested = {'a': '0', 'b': {'a': '1.0', 'b': '1.1'}}
flat = flatten(nested, reducer='dot')
# {'a': '0', 'b.a': '1.0', 'b.b': '1.1'}
reconstructed = unflatten(flat, splitter='dot')
# {'a': '0', 'b': {'a': '1.0', 'b': '1.1'}}
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (<4.0,>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 108 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 4,136,768/month — #2,373 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: flatten_dict-0.5.0-py3-none-any.whl
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
flatten-jsonConverts nested JSON objects into flat…
permissive · top 5,000 on PyPI
json-flattenConverts nested JSON objects into flat…
permissive · top 15,000 on PyPI
optreeOpTree provides optimized utilities for…
permissive · top 5,000 on PyPI
flatdictFlattens nested dictionaries into single-level…
permissive · top 5,000 on PyPI
json-tools-rsFlattens and unflattens nested JSON structures…
permissive · top 15,000 on PyPI
deflate-dictFlattens nested dictionaries into single-level…
permissive · top 15,000 on PyPI
json-flattenerConverts nested JSON/YAML objects into flat…
permissive · top 15,000 on PyPI
zictProvides mutable mapping tools and data…
permissive · top 5,000 on PyPI
etuplesProvides S-expression emulation using…
permissive · top 5,000 on PyPI
multidictMultidict is a dict-like container that allows…
permissive · top 100 on PyPI