An immutable dict class.
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file constantdict-2025.2-py3-none-any.whl.
File metadata
- Download URL: constantdict-2025.2-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db01aca6c73fa62b8ef550c5d348617b5945e3af1e652e42de4ee719d8e3074c
|
|
| MD5 |
ad5f1755ba84a1eb226b85818f541d14
|
|
| BLAKE2b-256 |
4ca550d8f2c62809a285412cada730f18c440d92f3e92dc974e3f6e10d373755
|