Skip to main content

Immutable Collections

Project description

https://travis-ci.org/MagicStack/immutables.svg?branch=master https://ci.appveyor.com/api/projects/status/tgbc6tq56u63qqhf?svg=true https://img.shields.io/pypi/v/immutables.svg

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

bench.png

Installation

immutables requires Python 3.5+ and is available on PyPI:

$ pip install immutables

API

immutables.Map is an unordered immutable mapping. Map objects are hashable, comparable, and pickleable.

The Map object implements the collections.abc.Mapping ABC so working with it is very similar to working with Python dicts:

import immutables

map = immutables.Map(a=1, b=2)

print(map['a'])
# will print '1'

print(map.get('z', 100))
# will print '100'

print('z' in map)
# will print 'False'

Since Maps are immutable, there is a special API for mutations that allow apply changes to the Map object and create new (derived) Maps:

map2 = map.set('a', 10)
print(map, map2)
# will print:
#   <immutables.Map({'a': 1, 'b': 2})>
#   <immutables.Map({'a': 10, 'b': 2})>

map3 = map2.delete('b')
print(map, map2, map3)
# will print:
#   <immutables.Map({'a': 1, 'b': 2})>
#   <immutables.Map({'a': 10, 'b': 2})>
#   <immutables.Map({'a': 10})>

Maps also implement APIs for bulk updates: MapMutation objects:

map_mutation = map.mutate()
map_mutation['a'] = 100
del map_mutation['b']
map_mutation.set('y', 'y')

map2 = map_mutation.finish()

print(map, map2)
# will print:
#   <immutables.Map({'a': 1, 'b': 2})>
#   <immutables.Map({'a': 100, 'y': 'y'})>

MapMutation objects are context managers. Here’s the above example rewritten in a more idiomatic way:

with map.mutate() as mm:
    mm['a'] = 100
    del mm['b']
    mm.set('y', 'y')
    map2 = mm.finish()

print(map, map2)
# will print:
#   <immutables.Map({'a': 1, 'b': 2})>
#   <immutables.Map({'a': 100, 'y': 'y'})>

Further development

  • An immutable version of Python set type with efficient add() and discard() operations.

License

Apache 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

immutables-0.10.tar.gz (37.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

immutables-0.10-cp37-cp37m-win_amd64.whl (52.5 kB view details)

Uploaded CPython 3.7mWindows x86-64

immutables-0.10-cp37-cp37m-win32.whl (47.8 kB view details)

Uploaded CPython 3.7mWindows x86

immutables-0.10-cp37-cp37m-manylinux1_x86_64.whl (92.7 kB view details)

Uploaded CPython 3.7m

immutables-0.10-cp37-cp37m-manylinux1_i686.whl (88.1 kB view details)

Uploaded CPython 3.7m

immutables-0.10-cp37-cp37m-macosx_10_13_x86_64.whl (49.6 kB view details)

Uploaded CPython 3.7mmacOS 10.13+ x86-64

immutables-0.10-cp36-cp36m-win_amd64.whl (52.5 kB view details)

Uploaded CPython 3.6mWindows x86-64

immutables-0.10-cp36-cp36m-win32.whl (47.8 kB view details)

Uploaded CPython 3.6mWindows x86

immutables-0.10-cp36-cp36m-manylinux1_x86_64.whl (91.8 kB view details)

Uploaded CPython 3.6m

immutables-0.10-cp36-cp36m-manylinux1_i686.whl (87.1 kB view details)

Uploaded CPython 3.6m

immutables-0.10-cp36-cp36m-macosx_10_13_x86_64.whl (49.6 kB view details)

Uploaded CPython 3.6mmacOS 10.13+ x86-64

immutables-0.10-cp35-cp35m-win_amd64.whl (52.5 kB view details)

Uploaded CPython 3.5mWindows x86-64

immutables-0.10-cp35-cp35m-win32.whl (47.8 kB view details)

Uploaded CPython 3.5mWindows x86

immutables-0.10-cp35-cp35m-manylinux1_x86_64.whl (91.7 kB view details)

Uploaded CPython 3.5m

immutables-0.10-cp35-cp35m-manylinux1_i686.whl (87.0 kB view details)

Uploaded CPython 3.5m

immutables-0.10-cp35-cp35m-macosx_10_13_x86_64.whl (49.6 kB view details)

Uploaded CPython 3.5mmacOS 10.13+ x86-64

File details

Details for the file immutables-0.10.tar.gz.

File metadata

  • Download URL: immutables-0.10.tar.gz
  • Upload date:
  • Size: 37.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.3

File hashes

Hashes for immutables-0.10.tar.gz
Algorithm Hash digest
SHA256 e661bebe9428942ebdb569b718d8c7895ec939858d307655844e2a7994ad2a9e
MD5 a7c1e773c3b8b61391cf98f979a1938b
BLAKE2b-256 1f850aa900ebf435c547d7e09211e15d75dba9b598be697ba6083fd3675ad377

See more details on using hashes here.

File details

Details for the file immutables-0.10-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: immutables-0.10-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 52.5 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.3

File hashes

Hashes for immutables-0.10-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 e2d1cfded4d2c98ae53f5fe6f776297f4d47c6dcb0c26afaca7bbf9e34f9bce3
MD5 bf5feb2cd791f029a612473fdef97ca0
BLAKE2b-256 79a03c1b758e3f3d8943fc0598b0f335c84bc8cfc6597f4cd10472315c2ee771

See more details on using hashes here.

File details

Details for the file immutables-0.10-cp37-cp37m-win32.whl.

File metadata

  • Download URL: immutables-0.10-cp37-cp37m-win32.whl
  • Upload date:
  • Size: 47.8 kB
  • Tags: CPython 3.7m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.3

File hashes

Hashes for immutables-0.10-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 13a71433acf53a1fd2ae9a4da0d4abf90f8e8dcd3bf3b611f38a3270d978e826
MD5 ca36ecc737281ba0e614c57b83850045
BLAKE2b-256 a9ccf29b2259d26f5fa5429b300dad0d1e6433f6bb54d7bc2b7821157fc963ae

See more details on using hashes here.

File details

Details for the file immutables-0.10-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: immutables-0.10-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 92.7 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.3

File hashes

Hashes for immutables-0.10-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 82df8ce7c085c830b2bb4a0e35634e398779265e17a3b673ddfb8a5c5df3bf0a
MD5 3d6af03d3fa56b72e4d310fa1b3f5bcc
BLAKE2b-256 e587b2235e71dc5aa40bcc6697bb4babd1c0e47b421b4460ed898aa308e0779f

See more details on using hashes here.

File details

Details for the file immutables-0.10-cp37-cp37m-manylinux1_i686.whl.

File metadata

  • Download URL: immutables-0.10-cp37-cp37m-manylinux1_i686.whl
  • Upload date:
  • Size: 88.1 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.3

File hashes

Hashes for immutables-0.10-cp37-cp37m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 e10d57d925a60ab0c7ab32f7e0699f07a4cc6f11e157d94da3b039b8b298eefc
MD5 150e1681e7fc36e96922f0730b64e823
BLAKE2b-256 76cb201ef6cdf5667d92869327ff5fafe94e11d45568127a335a7c7b480bac64

See more details on using hashes here.

File details

Details for the file immutables-0.10-cp37-cp37m-macosx_10_13_x86_64.whl.

File metadata

  • Download URL: immutables-0.10-cp37-cp37m-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 49.6 kB
  • Tags: CPython 3.7m, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.3

File hashes

Hashes for immutables-0.10-cp37-cp37m-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 e18ce8595628ba260c210855bdddee95d05d6935df631bfff4df0f96df748bd3
MD5 ea7cae5dbd1e119a6f729be82e0fe378
BLAKE2b-256 f96a17ba6a0c1c34cb76e98cd86fdd62d47674c57bf0c43a14402df5a4972e69

See more details on using hashes here.

File details

Details for the file immutables-0.10-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: immutables-0.10-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 52.5 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.3

File hashes

Hashes for immutables-0.10-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 c4bb8b9215cfe0fd7e8ff4032f6529f508747312d1631a4e0b6504b5dad2b1f0
MD5 df804d619288366c94d0d5413d910bec
BLAKE2b-256 cb4f544527e0d3c5e89ce57245957dd9446cec68ebbcb1df8ef05d2e34ca2246

See more details on using hashes here.

File details

Details for the file immutables-0.10-cp36-cp36m-win32.whl.

File metadata

  • Download URL: immutables-0.10-cp36-cp36m-win32.whl
  • Upload date:
  • Size: 47.8 kB
  • Tags: CPython 3.6m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.3

File hashes

Hashes for immutables-0.10-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 afec2eb7d8a672ba275cd259aa14714588f0a43eced332649d1a66599f001cd4
MD5 4a13532f415b039d70955d68d8516578
BLAKE2b-256 10d81efe0efbe78614c3a839704530d0c256be497dd95df30049c8039a90191a

See more details on using hashes here.

File details

Details for the file immutables-0.10-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: immutables-0.10-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 91.8 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.3

File hashes

Hashes for immutables-0.10-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 93048131591c4a1b8d0dbb056e87f35892fdd23269bb30bad146200533d44a62
MD5 6fa9965b7a0dc3220523fbacb82aef76
BLAKE2b-256 ab0cbec4ecf85319c66b4aad2f28d805a93d097769fe6134ae5bc65bc40a4099

See more details on using hashes here.

File details

Details for the file immutables-0.10-cp36-cp36m-manylinux1_i686.whl.

File metadata

  • Download URL: immutables-0.10-cp36-cp36m-manylinux1_i686.whl
  • Upload date:
  • Size: 87.1 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.3

File hashes

Hashes for immutables-0.10-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 68f98f74160f2f1510031a99b7c01bf5bdb6a7f6ff372e39f2d8c6fcac281b4f
MD5 3f76995b11a5372d0f401968f55e7b69
BLAKE2b-256 43c96ddb7fba93ea37ff8160f035706ea699ea8cddb4e5e4adc407b876d61f8b

See more details on using hashes here.

File details

Details for the file immutables-0.10-cp36-cp36m-macosx_10_13_x86_64.whl.

File metadata

  • Download URL: immutables-0.10-cp36-cp36m-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 49.6 kB
  • Tags: CPython 3.6m, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.3

File hashes

Hashes for immutables-0.10-cp36-cp36m-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 d931c809de87e72a3e596e53ccd4b15006d6bed0f24518a783ec8df365a0d1cd
MD5 6806184ce62013b213e932bcb4f4ac10
BLAKE2b-256 096a038556cb8fe83ad3ed77cd485884612aa62de3f734a6362a57439730a888

See more details on using hashes here.

File details

Details for the file immutables-0.10-cp35-cp35m-win_amd64.whl.

File metadata

  • Download URL: immutables-0.10-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 52.5 kB
  • Tags: CPython 3.5m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.3

File hashes

Hashes for immutables-0.10-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 5a2ed3506ca0973e44770f03caa70615fcfb91799fabe17306764891f47b665d
MD5 65377ed8ec645e0297e7f81a2e1e8ac9
BLAKE2b-256 4e679127e4916f0fd2c54320a28f9e78607e5801f78d2bb73227edd4e9ad2f71

See more details on using hashes here.

File details

Details for the file immutables-0.10-cp35-cp35m-win32.whl.

File metadata

  • Download URL: immutables-0.10-cp35-cp35m-win32.whl
  • Upload date:
  • Size: 47.8 kB
  • Tags: CPython 3.5m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.3

File hashes

Hashes for immutables-0.10-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 1c2ac1eaf64457418ea8b2c30c3f4e6b432f3e592e15227bdd0572dc7771c9b1
MD5 0106d95dcb962868944dba15500f6dbb
BLAKE2b-256 cae15034d12972c9d71fe49e9c6eb38daafc4976f1eec751aec4693c9d8a58db

See more details on using hashes here.

File details

Details for the file immutables-0.10-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

  • Download URL: immutables-0.10-cp35-cp35m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 91.7 kB
  • Tags: CPython 3.5m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.3

File hashes

Hashes for immutables-0.10-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 d92125c81ca1c9e65f080888e6fe79d27ab31e6213001be1914c43ddde422025
MD5 e8896279dcf88bfc223d7be88a4ca2bc
BLAKE2b-256 f40664ac32e52a1639822519581917a6744907131c57bf54d738e2ffbae23151

See more details on using hashes here.

File details

Details for the file immutables-0.10-cp35-cp35m-manylinux1_i686.whl.

File metadata

  • Download URL: immutables-0.10-cp35-cp35m-manylinux1_i686.whl
  • Upload date:
  • Size: 87.0 kB
  • Tags: CPython 3.5m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.3

File hashes

Hashes for immutables-0.10-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 bf98c8c4f65e1156084067b9aeb3e78a3e2a33961719a711090e56e87b817acf
MD5 fd0644a101fe54f24ba01cb8bae07a4d
BLAKE2b-256 4a88d379156818a151430b5a9a8b39ea4d9978cfcc08d4c52ab50009080dccb0

See more details on using hashes here.

File details

Details for the file immutables-0.10-cp35-cp35m-macosx_10_13_x86_64.whl.

File metadata

  • Download URL: immutables-0.10-cp35-cp35m-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 49.6 kB
  • Tags: CPython 3.5m, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.3

File hashes

Hashes for immutables-0.10-cp35-cp35m-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 68361f05ae4cb3bce1f09c4c9eada9ae6cf3fbe33a3a2d5403cfb050b9e485e9
MD5 f185b47750b946de196099de7b6030cb
BLAKE2b-256 9582020bf210a10d947f6f89a1e21c24ca54ae39ed3247e7f8799b212a1c2115

See more details on using hashes here.

Supported by

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