frozendict in Python 3.15 – Immutable Hashable Dictionaries
Python 3.15 introduces frozendict as a built-in type (PEP 814). It behaves like frozenset does for sets — immutable, hashable, and safe to use as dictionary keys or in sets.
TL;DR
frozendictis immutable and hashable- Supports union operators | and |=
- Can be used in type hints and as dict keys
- Perfect for configuration, caching, and functional-style code
Basic Usage
fd = frozendict({"host": "localhost", "port": 5432})
print(hash(fd))
# fd["port"] = 5433 # TypeError
config_cache = {fd: "cached_value"}
Best Practices
- Use instead of tuple(dict.items()) for cleaner hashable mappings
- Great for default configurations that should never change
- Combine with dataclasses or Pydantic for frozen models
Conclusion
frozendict fills a long-standing gap in Python’s built-in types. In 2026 it will become a standard tool for safer, more functional code.