Python’s frozendict freezes a mapping, not everything it contains
Python 3.15 adds an immutable built-in mapping that can be hashed when its contents allow it. Its shallow freeze, order-independent mapping equality and non-dict type make it useful for stable configuration values, with clear limits.
An immutable mapping reaches the standard library
Python 3.15.0 became the stable release on 9 October 2026 and added frozendict as a built-in mapping type. PEP 814, accepted earlier in the release cycle, describes an immutable object that implements the Mapping interface. This gives code a standard value for a mapping whose top-level key-to-value associations should not be edited after construction. The release date is the feature’s shipping date; this note is published on 30 November. [1] [2] [3]
The distinction is useful at API boundaries. A function that receives a plain dict can replace entries, delete them or call update; a frozendict does not provide those mutation methods. Readers can still iterate over keys and values and use familiar mapping operations. Its immutability applies to this mapping object, so a caller can rely on the associations themselves not being reassigned through that object.
The freeze is shallow, so shared values still matter
Construction from a dictionary copies the key-value entries, but the copy is shallow. Suppose a settings dictionary contains a list of allowed hosts. Creating a frozendict from it prevents a later assignment such as replacing the dictionary’s timeout entry from changing the frozen mapping. Yet the list object stored as allowed_hosts is still the same list. Appending to that list changes what readers see through the frozendict. The wrapper has frozen the associations, not recursively frozen the object graph. [2]
That distinction matters for concurrency and caching. The PEP says an instance can be shared between threads without synchronization once created, provided its values are not modified by other threads. A frozen outer mapping therefore removes one class of race but does not make mutable nested state safe. If a configuration value must be a stable snapshot, use immutable values throughout or copy and validate nested data at the boundary. A read-only top layer is not a deep immutability guarantee.
Hashability is conditional, not automatic
A frozendict can be hashed only when its keys and values are hashable. A mapping whose values are strings or integers can serve as a key in another mapping or as an argument in a cache key. One containing a list cannot: asking for its hash raises TypeError. This is a practical reminder that “immutable container” and “hashable value” are related but separate properties. Hashability depends on every item contributing to the mapping’s value semantics. [2] [3]
For a configuration cache, first decide which settings define the result. Converting an entire settings mapping into a frozen object is only useful if its values are hashable and equality reflects the intended identity. The PEP specifies that equality and hashing do not depend on insertion order, even though iteration preserves that order. That is appropriate for mapping semantics: two mappings with the same pairs compare equal regardless of the order in which those pairs were inserted. It may be wrong if order itself controls a later operation, such as a sequence of middleware or command-line flags. In that case the ordered sequence belongs in the cache key too.
It is a Mapping, but not a dict subtype
frozendict inherits directly from object, rather than from dict, while implementing the standard mapping protocol. That keeps mutable dictionary methods from becoming an escape hatch: even calling a base dict mutation method cannot treat a frozendict as an ordinary dict. The cost is that code with a strict isinstance(value, dict) check, a C extension expecting an exact dictionary, or a mutating API may need adaptation. Prefer an interface check against Mapping when read-only mapping behavior is what the function actually requires. [2]
This is a compatibility decision rather than a cosmetic type substitution. Existing APIs may promise a concrete dict, callers may depend on mutation, and serializers or extensions may have special handling for dictionaries. When returning a frozen value, document whether callers get a general mapping or a concrete dict, and test the integrations that cross that boundary. If an integration requires a mutable copy, create one explicitly with dict(value) where mutation is intended.
Choose the invariant before choosing the container
A useful example is a parsed command configuration. The parser owns a mutable dictionary while applying defaults and resolving overrides. Once validation succeeds, it can expose a frozendict so downstream components cannot silently rewrite top-level options. If one option holds a mutable list or custom object, the owner still needs to decide whether to freeze, copy or document that nested value. If the configuration participates in a cache key, it must also verify that values are hashable and that insertion order is irrelevant to the computation.
Use a normal dict when mutation is part of the design, a read-only mapping view when changes to a backing dictionary should remain visible, and frozendict when the mapping should preserve its own associations and callers need value-like comparison. None of these types validates the meaning of keys, authorizes a request or makes nested state immutable. Python 3.15 supplies a useful primitive; the program still defines the boundary and the invariant that makes the primitive valuable.