constantdict
An immutable dictionary class for Python, implemented as a thin layer around Python's builtin dict class. It is often faster than other immutable dictionary implementations.
Usage
Install this package with:
$ pip install constantdict
Usage example:
from constantdict import constantdict
cd = constantdict({1: 2})
# constantdicts compare equal to dicts with the same items
assert cd == {1: 2}
# constantdicts are hashable, and their hashes are cached
print(hash(cd), cd)
# Attempting to modify a constantdict in-place raises an AttributeError
try:
# Similar for pop(), popitem(), clear(), and del
cd[4] = 12
except AttributeError:
pass
# Some methods return a mutated copy of a constantdict
cd_new = cd.setdefault(10, 5)
assert cd_new == {1: 2, 10: 5}
# Similar for set(), update(), delete(), discard()
# Performing multiple mutations can be faster via mutate()/finish()
cd_mut = cd.mutate() # cd_mut is a mutable copy of cd
cd_mut[42] = 0
del cd_mut[1]
cd_new2 = cd_mut.finish() # cd_new2 is an immutable version of cd_mut
assert cd_new2 == {42: 0}
Please also see the documentation,
as well as the examples in the examples/ directory.
References
Other packages
PEPs
Discussions
License
MIT License.
Metadata
Release files for constantdict 2025.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| constantdict-2025.3-py3-none-any.whl | Python 3 | none | any | Details |
Release files / constantdict-2025.3-py3-none-any.whl
| Download URL | constantdict-2025.3-py3-none-any.whl |
|---|---|
| Size | 7.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a53d66e9604538e269f3168a9a0af3c6a091242d7df0c088fccd5d6a95eb6a24
|
|
BLAKE2b-256 checksum How to use checksums |
2da69fe84f63f266fb2727da85a5c9bae0a81a63d2a981cc961cb7b947a5829c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.9
|
Security for constantdict 2025.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.