Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/matthiasdiener/constantdict
An immutable dict class for Python.
https://github.com/matthiasdiener/constantdict
dict frozen immutable python
Last synced: 10 days ago
JSON representation
An immutable dict class for Python.
- Host: GitHub
- URL: https://github.com/matthiasdiener/constantdict
- Owner: matthiasdiener
- License: mit
- Created: 2024-01-21T04:30:43.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-03-14T23:22:28.000Z (8 months ago)
- Last Synced: 2024-09-17T03:56:02.018Z (about 2 months ago)
- Topics: dict, frozen, immutable, python
- Language: Python
- Homepage: https://matthiasdiener.github.io/constantdict/
- Size: 278 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![PyPI version](https://badge.fury.io/py/constantdict.svg)](https://badge.fury.io/py/constantdict)
[![Doc Status](https://img.shields.io/github/actions/workflow/status/matthiasdiener/constantdict/doc.yaml?label=docs)](https://matthiasdiener.github.io/constantdict)
[![License](https://img.shields.io/pypi/l/constantdict)](https://github.com/matthiasdiener/constantdict/blob/main/LICENSE)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/constantdict)](https://badge.fury.io/py/constantdict)# 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](https://matthiasdiener.github.io/constantdict/speed.html).
## Usage
Install this package with:
```
$ pip install constantdict
```Usage example:
```python
from constantdict import constantdictcd = 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](https://matthiasdiener.github.io/constantdict),
as well as the examples in the `examples/` directory.## References
### Other packages
- [immutabledict](https://github.com/corenting/immutabledict)
- [immutables](https://github.com/MagicStack/immutables)
- [pyrsistent](https://github.com/tobgu/pyrsistent)
- [frozendict (old)](https://github.com/slezica/python-frozendict)
- [frozendict (new)](https://github.com/Marco-Sulla/python-frozendict)### PEPs
- [PEP 416](https://www.python.org/dev/peps/pep-0416/)
- [PEP 603](https://www.python.org/dev/peps/pep-0603/)## License
MIT License.