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

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

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


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.5.tar.gz (31.3 kB view details)

Uploaded Source

Built Distributions

immutables-0.5-cp36-cp36m-win_amd64.whl (38.9 kB view details)

Uploaded CPython 3.6m Windows x86-64

immutables-0.5-cp36-cp36m-win32.whl (35.3 kB view details)

Uploaded CPython 3.6m Windows x86

immutables-0.5-cp36-cp36m-manylinux1_x86_64.whl (70.4 kB view details)

Uploaded CPython 3.6m

immutables-0.5-cp36-cp36m-manylinux1_i686.whl (67.0 kB view details)

Uploaded CPython 3.6m

immutables-0.5-cp36-cp36m-macosx_10_12_x86_64.whl (36.4 kB view details)

Uploaded CPython 3.6m macOS 10.12+ x86-64

immutables-0.5-cp35-cp35m-win_amd64.whl (38.9 kB view details)

Uploaded CPython 3.5m Windows x86-64

immutables-0.5-cp35-cp35m-win32.whl (35.3 kB view details)

Uploaded CPython 3.5m Windows x86

immutables-0.5-cp35-cp35m-manylinux1_x86_64.whl (70.3 kB view details)

Uploaded CPython 3.5m

immutables-0.5-cp35-cp35m-manylinux1_i686.whl (66.8 kB view details)

Uploaded CPython 3.5m

immutables-0.5-cp35-cp35m-macosx_10_12_x86_64.whl (36.4 kB view details)

Uploaded CPython 3.5m macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: immutables-0.5.tar.gz
  • Upload date:
  • Size: 31.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for immutables-0.5.tar.gz
Algorithm Hash digest
SHA256 57d17742fccec4c0466ab658053fab1a327df42241e7b1cab28e5b85e7066ac1
MD5 af4f5dca3611b30978dec1d5a5f3c4a9
BLAKE2b-256 4272bea586a8c04ee8c5a5aa9be9bfdc93e9f1df1b7fdb321b25b77497fa843d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for immutables-0.5-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 8a3d2fc0d9db57188f28d3e6cefe45e9905292965895a7a391be6ededa626811
MD5 b1c5b934829e552b7fabb257f95b6675
BLAKE2b-256 34ef7989f05630656c1b39d12f03501c41a020a79d1b55db58fb323719a5e0fd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for immutables-0.5-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 95da22e2d16b47dbd3464ae447b94f8d74866bce045be216dd1691f2f1838a94
MD5 323bbd3338ea9738e188bf7186b11e4d
BLAKE2b-256 3dc9411e177b2cab5c0844085fb6ba5fe1bbde41cefc1a6cf0344e0ab489d90a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for immutables-0.5-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 4d29f0e6a880a20f94c9efd4672212c3276fa303621a4bdf2a5e4ba7f27cba84
MD5 e41c141c91834a67756b9dfa8b450ad5
BLAKE2b-256 dcc31c48ff2f34779caec070417e0ceb4dd2403e1976a0b4bbd8a2a1b20ca899

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for immutables-0.5-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 5180319a7aebc9319e63e7ea663830d46566b84bed91cbcdb50e247d65fbda07
MD5 534a427ae46a0552f18c43532650c0f0
BLAKE2b-256 24029a96cf59395517772a66af7ea273276397f05734f80fc1c1644635e9ec79

See more details on using hashes here.

File details

Details for the file immutables-0.5-cp36-cp36m-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for immutables-0.5-cp36-cp36m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 1614177d08408176a7b12313d6efefad41c3ba17e56cbeb404bb74f83cfdeaac
MD5 dc15c2560e46bc46f637184016096cdb
BLAKE2b-256 1af94d0485239c6b82528672008d197d51925cacb7cd89b458f7844ac328bb43

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for immutables-0.5-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 75e2e4e9441938690821adc1ab00829a174f696aef1c52ae6aba767219d1e84f
MD5 92cfa8f4a0a8bb978d24d9b80fac8343
BLAKE2b-256 0d0dc5957234c7a7568b92104a27ce4fe80562570efe6a40043e91fe12047e8e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for immutables-0.5-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 9c8e0267a4d35032ccc670e5ab52aba2693ded330c4c1f2a4870b4a7c86b65af
MD5 4a0c8b71ee747581c1afb066a0d8cd0d
BLAKE2b-256 8a146d4c53fe569c06bccd1e31f91e2a526fa008bc9700a6696e93d94be539fe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for immutables-0.5-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 812fd1124fca2f56a3a7f376f34ac44719f131d82b6001323aef84faa8be7f00
MD5 78c26b0de3d3ebf7d62a300b7b59cace
BLAKE2b-256 6a25bf53caefbe2549ed787442787b9469121824f1598d5b2437d680f9c133ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for immutables-0.5-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 da1c24d6ab6b38604444b4b767b3bf6074dfa3f7d15d8192a3a4935f61f00bd6
MD5 a139c77f1961e146e1ae1e6e4e92fb3b
BLAKE2b-256 71917587974acd0009bf9f8a10a7c905c078311a87e67c1010d238638680d6d5

See more details on using hashes here.

File details

Details for the file immutables-0.5-cp35-cp35m-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for immutables-0.5-cp35-cp35m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 18cd84d5ff10ffd42db163d4aad88128d86c2939335b068852f8f399594521ee
MD5 9218cc09833b5b5eb77c47872341df46
BLAKE2b-256 6f44a8955d887a20ade4c8a2e2577ca5741132a15bc6fe4f289b310465614325

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