Immutable Collections
Project description
An immutable mapping type for Python.
The underlying datastructure is a Hash Array Mapped Trie (HAMT) used in Clojure, Scala, Haskell, and other functional languages. This implementation is used in CPython 3.7 in the contextvars module (see PEP 550 and PEP 567 for more details).
Immutable mappings based on HAMT have O(log N) performance for both set() and get() operations, which is essentially O(1) for relatively small mappings.
Below is a visualization of a simple get/set benchmark comparing HAMT to an immutable mapping implemented with a Python dict copy-on-write approach (the benchmark code is available here):
Installation
immutables requires Python 3.5+ and is available on PyPI:
$ pip install immutables
immutables.Map
The Map object implements collections.abc.Mapping ABC so working with it is very similar to working with Python dicts.
The only exception are its Map.set() and Map.delete() methods which return a new instance of Map:
m1 = Map() # an empty Map
m2 = m1.set('key1', 'val1') # m2 has a 'key1' key, m1 is still empty
m3 = m2.set('key2', 'val2')
m3 = m3.delete('key1') # m3 has only a 'key2' key
Further development
An immutable version of Python set type with efficient add() and discard() operations.
Add support for efficient Map.update() operation, allow to pass a set of key/values to Map(), and add support for pickling.
License
Apache 2.0
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 Distribution
Built Distributions
File details
Details for the file immutables-0.6.tar.gz
.
File metadata
- Download URL: immutables-0.6.tar.gz
- Upload date:
- Size: 31.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63023fa0cceedc62e0d1535cd4ca7a1f6df3120a6d8e5c34e89037402a6fd809 |
|
MD5 | a9ecd67d715fe3b93b33ea2e2f7e59f1 |
|
BLAKE2b-256 | dc22e8c6a0b77657612b21f45519b3c08067793371e62bf027af84d49ac9d3e9 |
File details
Details for the file immutables-0.6-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: immutables-0.6-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 38.9 kB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ae88fbfe1d04f4e5859c924e97313edf70e72b4f19871bf329b96a67ede9ba0 |
|
MD5 | b6b24b714db99189b13bbce26085fb86 |
|
BLAKE2b-256 | 60cf926dca5174ce2ab425308269a9cf626761aaa7aaa4b4c17b812d7cf6eec1 |
File details
Details for the file immutables-0.6-cp36-cp36m-win32.whl
.
File metadata
- Download URL: immutables-0.6-cp36-cp36m-win32.whl
- Upload date:
- Size: 35.3 kB
- Tags: CPython 3.6m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc36a0a8749881eebd753f696b081bd51145e4d77291d671d2e2f622e5b65d2f |
|
MD5 | 0a2e8a081fffe0424067eb8997c26f83 |
|
BLAKE2b-256 | 018718c643628a2cccd382635ebdff5bbf28b1f775bff54fc334d0516f504156 |
File details
Details for the file immutables-0.6-cp36-cp36m-manylinux1_x86_64.whl
.
File metadata
- Download URL: immutables-0.6-cp36-cp36m-manylinux1_x86_64.whl
- Upload date:
- Size: 70.5 kB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c090687d7e623d4eca22962635b5e1a1ee2d6f9a9aca2f3fb5a184a1ffef1f2 |
|
MD5 | 87479066ed7c33c4ead1adc352b7e7e3 |
|
BLAKE2b-256 | 938514400a6cadf89d9cb369b3b7013baa766ea2a9fabe50d7a711ed8a6cc5d9 |
File details
Details for the file immutables-0.6-cp36-cp36m-manylinux1_i686.whl
.
File metadata
- Download URL: immutables-0.6-cp36-cp36m-manylinux1_i686.whl
- Upload date:
- Size: 67.0 kB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35af186bfac5b62522fdf2cab11120d7b0547f405aa399b6a1e443cf5f5e318c |
|
MD5 | e10c1463c21ce4b62c9e293ca622357b |
|
BLAKE2b-256 | d360f8fdd8e11b513f7fd30352fdc2aaee2519e5d5bb5f08ad4bd6ce55937cf9 |
File details
Details for the file immutables-0.6-cp36-cp36m-macosx_10_12_x86_64.whl
.
File metadata
- Download URL: immutables-0.6-cp36-cp36m-macosx_10_12_x86_64.whl
- Upload date:
- Size: 36.4 kB
- Tags: CPython 3.6m, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 228e38dc7a810ba4ff88909908ac47f840e5dc6c4c0da6b25009c626a9ae771c |
|
MD5 | ffdb0b61e4347e03479dd121de02e5bc |
|
BLAKE2b-256 | 0d8006d3f1fe1139087713aace4bfcaf080519def9a82da22b95de1858650200 |
File details
Details for the file immutables-0.6-cp35-cp35m-win_amd64.whl
.
File metadata
- Download URL: immutables-0.6-cp35-cp35m-win_amd64.whl
- Upload date:
- Size: 38.9 kB
- Tags: CPython 3.5m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9fc6a236018d99af6453ead945a6bb55f98d14b1801a2c229dd993edc753a00 |
|
MD5 | e763aac85f29855252e95f3f13ba77ac |
|
BLAKE2b-256 | 9519c75c55e9373a728b6f6ad6a16b8649fa3a5bfaef000472cc85f70f96634e |
File details
Details for the file immutables-0.6-cp35-cp35m-win32.whl
.
File metadata
- Download URL: immutables-0.6-cp35-cp35m-win32.whl
- Upload date:
- Size: 35.3 kB
- Tags: CPython 3.5m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d32b61c222cba1dd11f0faff67c7fb6204ef1982454e1b5b001d4b79966ef17 |
|
MD5 | 290ae95892818252f502b5783b14c836 |
|
BLAKE2b-256 | 106ff32776c857683e3ea58e30bafc8f26a5d88705eb9b613d2dd0d580a67860 |
File details
Details for the file immutables-0.6-cp35-cp35m-manylinux1_x86_64.whl
.
File metadata
- Download URL: immutables-0.6-cp35-cp35m-manylinux1_x86_64.whl
- Upload date:
- Size: 70.3 kB
- Tags: CPython 3.5m
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6bf5857f42a96331fd0929c357dc0b36a72f339f3b6acaf870b149c96b141f69 |
|
MD5 | 96ed360e04dd339ebaec066f8cc9a3c3 |
|
BLAKE2b-256 | 1d9be66aafdc9dc6cbb0f3aab83d2ce804056fcc1574d2b15497de616ed4d534 |
File details
Details for the file immutables-0.6-cp35-cp35m-manylinux1_i686.whl
.
File metadata
- Download URL: immutables-0.6-cp35-cp35m-manylinux1_i686.whl
- Upload date:
- Size: 66.8 kB
- Tags: CPython 3.5m
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e4f4513254ef11e0230a558ee0dcb4551b914993c330005d15338da595d3750 |
|
MD5 | e09fe97082be34144000e281bae8c0c0 |
|
BLAKE2b-256 | fa0ce0d2cd55feed0d05b24df2f66055b10b51abd4be901bfdaa230643570b51 |
File details
Details for the file immutables-0.6-cp35-cp35m-macosx_10_12_x86_64.whl
.
File metadata
- Download URL: immutables-0.6-cp35-cp35m-macosx_10_12_x86_64.whl
- Upload date:
- Size: 36.4 kB
- Tags: CPython 3.5m, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7bb1590024a032c7a57f79faf8c8ff5e91340662550d2980e0177f67e66e9c9c |
|
MD5 | 270529c7acc3730f1d8ee63ecef84387 |
|
BLAKE2b-256 | c4c2f83d7bc53e95941338f925d6f6933f2459e15acfc763871fe00e0526655b |