skillfed

flatdict

Python module for interacting with nested dicts as a single level dict with delimited keys.

flatdict v4.1.0 1.5M downloads/30d#3,811 on PyPI116
Permissive license BSD-3-Clause Active released

What it is and what it does

FlatDict provides two dict subclasses—FlatDict and FlatterDict—that present nested dictionaries as a single flat level while preserving access to the original structure. When you wrap a nested dict, keys are automatically flattened using a delimiter (colon by default), so a path like `{'foo': {'bar': 'baz'}}` becomes accessible as `{'foo:bar': 'baz'}`. You can read and write using either the composite key or the nested path interchangeably.

FlatterDict extends this to sequences: lists and tuples are also flattened by converting indices to keys, so `{'list': ['a', 'b', 'c']}` becomes `{'list:0': 'a', 'list:1': 'b', 'list:2': 'c'}`. This is useful when you need to work with deeply nested or mixed structures as a flat key-value store—common in configuration handling, data transformation, or API response normalization.

Use it for:

  • Normalize deeply nested JSON or config objects into a flat key-value store for easier iteration or lookup.
  • Convert API responses with nested structures into a single-level dict for database storage or serialization.
  • Flatten configuration hierarchies to pass as environment variables or command-line arguments.
  • Transform nested data structures into a format suitable for CSV export or tabular processing.
  • Simplify access patterns in code that needs to work with both flat and nested representations simultaneously.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Flattens nested dictionaries into single-level dicts with delimited composite keys, and optionally flattens lists and tuples by index.

Yes. This is a stable, well-maintained utility with zero dependencies, no known vulnerabilities, and a permissive license. Install it if you regularly work with nested dicts and need a lightweight, transparent way to flatten them. The low friction and broad Python version support make it a safe, practical choice.

Install

flatdict on PyPI

pip

pip install flatdict

uv

uv add flatdict

poetry

poetry add flatdict

Installing flatdict

Before you install

Low friction: pure Python wheel with no runtime dependencies. Active maintenance with a recent release (2026-02-15) and a commit history through 2026-06-12. Supports Python 3.10 through 3.14 and PyPy.

License in practice

BSD-3-Clause (permissive): you can use, modify, and distribute this package freely in proprietary or open-source projects with minimal restrictions, provided you include the license notice.

Quickstart

pip install flatdict

import flatdict

value = flatdict.FlatDict({'foo': {'bar': 'baz'}})
print(value['foo:bar'])  # 'baz'
print(value['foo']['bar'])  # 'baz'

Package facts

License BSD-3-Clause (permissive)
Python support supports the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance actively maintained — 180 days since the last release
Last repo commit
First released
Downloads 1,527,366/month — #3,811 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: flatdict-4.1.0-py3-none-any.whl

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseOperating System :: POSIXProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software Development :: Libraries

Tags

flatten nested dictionariesdict flattening librarycomposite key mappingnested dict accessdelimited key dictionaryflatten lists to dictsingle-level dict wrapper
data-structuredict-utility

More Libraries packages