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 details)

Uploaded Python 3

File details

Details for the file constantdict-2024.2-py3-none-any.whl.

File metadata

File hashes

Hashes for constantdict-2024.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ff649ca4d96d59522d347e4ceaea9781f8c603515c95efea8f02556053f129bd
MD5 c048f5c049596721982bc8b537ea2c19
BLAKE2b-256 6e1f49c370d4944c1ec9fd302dbff29f7aa08cf24f02f61bd51f47c9cde31668

See more details on using hashes here.

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