Welcome to constantdict’s documentation#

This site covers constantdict’s API documentation. For more information about constantdict, see the Github repository.

Usage#

The constantdict class can be used as a replacement for dict. The API is the same as dict, but without methods that mutate the dictionary.

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 the constantdict raises an AttributeError
try:
    # Similar for pop(), popitem(), clear(), __ior__(), del, and setdefault()
    cd[4] = 12
except AttributeError:
    pass

Some additional methods are provided, see the reference below.

API reference#