constantdict
An immutable dict class.
What it is and what it does
constantdict is a lightweight immutable dictionary implementation that sits on top of Python's built-in dict. It prevents accidental in-place modifications by raising AttributeError on attempts to mutate (like setting items, popping, or clearing), while remaining fully hashable with cached hashes and comparable to regular dicts. The class is designed to be faster than some alternative immutable dictionary libraries.
You use it when you need a dict-like object that can serve as a dictionary key, be safely shared across code without fear of mutation, or benefit from cached hashing. It supports both functional-style operations (returning new immutable copies via setdefault, update, delete) and bulk mutation via a mutate()/finish() pattern for performance when making multiple changes at once.
Use it for:
- Use as dictionary keys in sets or as dict keys where regular dicts cannot be used due to mutability.
- Share configuration or lookup tables across functions without risk of accidental modification.
- Cache immutable snapshots of data where hash stability and equality checks matter.
- Bulk-update immutable structures efficiently via mutate()/finish() when creating many variants.
- Replace frozendict or other immutable dict implementations when performance is a concern.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides an immutable dictionary class that wraps Python's built-in dict, preventing in-place modifications while remaining hashable and comparable to regular dicts.
Yes, if you need an immutable, hashable dict and want a lightweight, permissively licensed option. Install with caution given aging maintenance (last commit 2025-07-21, no recent releases), but the package is stable, has no known vulnerabilities, and low install friction. Best for projects where immutable dicts are a core requirement rather than an occasional convenience.
Install
constantdict on PyPI
pip
pip install constantdictuv
uv add constantdictpoetry
poetry add constantdictInstalling constantdict
Before you install
Low install friction with only two lightweight runtime dependencies (importlib-metadata and typing-extensions). Maintenance status is aging—last commit was 2025-07-21, with no releases in the past 389 days, though the repository remains active and unarchived.
License in practice
MIT License permits unrestricted use, modification, and distribution with minimal restrictions, making it suitable for both open-source and proprietary projects.
Quickstart
pip install constantdict
from constantdict import constantdict
cd = constantdict({1: 2})
print(hash(cd)) # hashable and cached
cd_new = cd.setdefault(10, 5) # returns mutated copy
Requires Python 3.7 or later.
Verify before relying
- Performance comparison claims against other immutable dict implementations need independent verification.
- Actual use adoption and community feedback beyond download statistics are not evident from the fact sheet.
Package facts
| License | MIT License Copyright (c) 2024 University of Illinois Board of Trustees Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation… (full text in the JSON record) (permissive) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — importlib-metadata, typing-extensions |
| Maintenance | aging — 389 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 74,056/month — #14,882 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: constantdict-2025.3-py3-none-any.whl
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
itypesProvides immutable container types (Dict and…
permissive · top 5,000 on PyPI
zictProvides mutable mapping tools and data…
permissive · top 5,000 on PyPI
immutablesProvides an immutable mapping type backed by a…
permissive · top 5,000 on PyPI
frozendictProvides an immutable, hashable dictionary…
copyleft · top 5,000 on PyPI
pyrsistentPyrsistent provides immutable, persistent data…
permissive · top 1,000 on PyPI
jaraco.collectionsProvides specialized collection classes that…
permissive · top 5,000 on PyPI
rpds-pyProvides Python bindings to Rust's persistent…
permissive · top 100 on PyPI
ml-collectionsProvides dict-like configuration data…
permissive · top 5,000 on PyPI
recordtyperecordtype creates mutable record classes with…
permissive · top 15,000 on PyPI