frozendict
A simple immutable dictionary
What it is and what it does
frozendict is an immutable dictionary that behaves like a standard Python dict but cannot be modified after creation. It supports hashing (when all values are hashable) and pickling, making it suitable for use as dictionary keys or in sets. The package provides both a frozendict class with a dict-compatible API minus mutation methods, plus a deepfreeze utility that recursively converts nested mutable structures into their immutable equivalents.
The implementation guarantees true immutability—internal variables cannot be changed and are themselves immutable objects. It supports standard dict operations like get(), keys(), values(), items(), and fromkeys(), plus immutable variants like set() and delete() that return new frozendict instances. The | operator merges a frozendict with a regular dict, producing a new frozendict. An optional C extension is available for performance, but a pure Python fallback ensures broad compatibility.
Use it for:
- Use as dictionary keys or set members when you need hashable, immutable mappings for caching or memoization.
- Freeze nested data structures (lists, dicts, sets, custom objects) into immutable equivalents with deepfreeze().
- Define configuration or constant data that must not be accidentally modified during program execution.
- Serialize and deserialize immutable data structures via pickle while preserving hashability and immutability guarantees.
- Build functional-style code where data transformations return new frozendict instances rather than mutating state.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides an immutable, hashable dictionary implementation with a dict-like API, supporting operations like set(), delete(), and merge via the | operator while guaranteeing immutability.
Yes. frozendict is actively maintained, has zero known vulnerabilities, imposes no runtime dependencies, and solves a genuine need for immutable, hashable dictionaries in Python. The LGPL v3 copyleft license is a consideration if you're building proprietary software, but poses no barrier to use in open-source or internal projects. Install it if you need immutable mappings for hashing, thread safety, or functional programming patterns.
Install
frozendict on PyPI
pip
pip install frozendictuv
uv add frozendictpoetry
poetry add frozendictInstalling frozendict
Before you install
Low friction: pure Python wheel available, no runtime dependencies, and actively maintained with recent releases. Optional C extension available for performance but not required.
License in practice
Licensed under LGPL v3 (copyleft): derivative works and modifications must be distributed under the same license, and source code must be made available to users who receive the software.
Quickstart
pip install frozendict
from frozendict import frozendict
fd = frozendict({'a': 1, 'b': 2})
print(hash(fd)) # hashable if all values are hashable
fd_new = fd.set('c', 3) # returns new frozendict
All values must be hashable if you intend to hash the frozendict itself; attempting to hash a frozendict with unhashable values raises TypeError.
Verify before relying
- Performance comparison specifics: description mentions benchmarks but excerpt does not include actual numbers or scenarios.
- C extension performance impact: whether the optional C extension provides meaningful speedup for typical workloads is not quantified.
- deepfreeze recursion limits: maximum nesting depth or object graph size before hitting Python's recursion limit is not specified.
Package facts
| License | LGPL v3 (copyleft) |
| Python support | supports the current Python release (>=3.6) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 276 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 17,608,249/month — #1,108 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: frozendict-2.4.7-py3-none-any.whl
Keywords: immutable, hashable, picklable, frozendict, dict, dictionary, map, Mapping, MappingProxyType, developers, stable, utility
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
immutabledictProvides an immutable dictionary wrapper that…
permissive · top 1,000 on PyPI
immutablesProvides an immutable mapping type backed by a…
permissive · top 5,000 on PyPI
constantdictProvides an immutable dictionary class that…
permissive · top 15,000 on PyPI
zictProvides mutable mapping tools and data…
permissive · top 5,000 on PyPI
itypesProvides immutable container types (Dict and…
permissive · top 5,000 on PyPI
jaraco.collectionsProvides specialized collection classes that…
permissive · top 5,000 on PyPI
multisetProvides a mutable and immutable multiset data…
permissive · top 15,000 on PyPI
optionaldictA dict subclass that automatically omits None…
permissive · top 15,000 on PyPI
pyrsistentPyrsistent provides immutable, persistent data…
permissive · top 1,000 on PyPI