Skip to main content

An immutable dict class.

Project description

PyPI version Doc Status License PyPI - Downloads

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

Please also see the documentation, as well as the examples in the examples/ directory.

References

Other packages

PEPs

License

MIT License.

Project details


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

constantdict-2024.2-py3-none-any.whl (5.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page