{"id":13392877,"url":"https://github.com/MagicStack/immutables","last_synced_at":"2025-03-13T19:31:09.441Z","repository":{"id":31292240,"uuid":"127474402","full_name":"MagicStack/immutables","owner":"MagicStack","description":"A high-performance immutable mapping type for Python.","archived":false,"fork":false,"pushed_at":"2024-10-10T00:53:54.000Z","size":362,"stargazers_count":1130,"open_issues_count":10,"forks_count":57,"subscribers_count":22,"default_branch":"master","last_synced_at":"2024-10-29T15:00:39.894Z","etag":null,"topics":["frozen","hamt","immutable","immutable-collections","immutable-datastructures","python","python3"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MagicStack.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-30T21:24:52.000Z","updated_at":"2024-10-26T08:43:14.000Z","dependencies_parsed_at":"2024-06-18T10:45:08.508Z","dependency_job_id":"f9acc090-81c5-485c-aa66-b59cf2b3687a","html_url":"https://github.com/MagicStack/immutables","commit_stats":{"total_commits":115,"total_committers":15,"mean_commits":7.666666666666667,"dds":0.5913043478260869,"last_synced_commit":"7071a24df78a006c982f2f86868e8466fd1cd210"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MagicStack%2Fimmutables","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MagicStack%2Fimmutables/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MagicStack%2Fimmutables/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MagicStack%2Fimmutables/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MagicStack","download_url":"https://codeload.github.com/MagicStack/immutables/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243469124,"owners_count":20295692,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["frozen","hamt","immutable","immutable-collections","immutable-datastructures","python","python3"],"created_at":"2024-07-30T17:00:38.562Z","updated_at":"2025-03-13T19:31:09.414Z","avatar_url":"https://github.com/MagicStack.png","language":"C","readme":"immutables\n==========\n\n.. image:: https://github.com/MagicStack/immutables/workflows/Tests/badge.svg?branch=master\n    :target: https://github.com/MagicStack/immutables/actions?query=workflow%3ATests+branch%3Amaster+event%3Apush\n\n.. image:: https://img.shields.io/pypi/v/immutables.svg\n    :target: https://pypi.python.org/pypi/immutables\n\nAn immutable mapping type for Python.\n\nThe underlying datastructure is a Hash Array Mapped Trie (HAMT)\nused in Clojure, Scala, Haskell, and other functional languages.\nThis implementation is used in CPython 3.7 in the ``contextvars``\nmodule (see `PEP 550 \u003chttps://www.python.org/dev/peps/pep-0550/\u003e`_ and\n`PEP 567 \u003chttps://www.python.org/dev/peps/pep-0567/\u003e`_ for more details).\n\nImmutable mappings based on HAMT have O(log N) performance for both\n``set()`` and ``get()`` operations, which is essentially O(1) for\nrelatively small mappings.\n\nBelow is a visualization of a simple get/set benchmark comparing\nHAMT to an immutable mapping implemented with a Python dict\ncopy-on-write approach (the benchmark code is available\n`here \u003chttps://gist.github.com/1st1/292e3f0bbe43bd65ff3256f80aa2637d\u003e`_):\n\n.. image:: bench.png\n\n\nInstallation\n------------\n\n``immutables`` requires Python 3.6+ and is available on PyPI::\n\n    $ pip install immutables\n\n\nAPI\n---\n\n``immutables.Map`` is an unordered immutable mapping.  ``Map`` objects\nare hashable, comparable, and pickleable.\n\nThe ``Map`` object implements the ``collections.abc.Mapping`` ABC\nso working with it is very similar to working with Python dicts:\n\n.. code-block:: python\n\n    import immutables\n\n    map = immutables.Map(a=1, b=2)\n\n    print(map['a'])\n    # will print '1'\n\n    print(map.get('z', 100))\n    # will print '100'\n\n    print('z' in map)\n    # will print 'False'\n\nSince Maps are immutable, there is a special API for mutations that\nallow apply changes to the Map object and create new (derived) Maps:\n\n.. code-block:: python\n\n    map2 = map.set('a', 10)\n    print(map, map2)\n    # will print:\n    #   \u003cimmutables.Map({'a': 1, 'b': 2})\u003e\n    #   \u003cimmutables.Map({'a': 10, 'b': 2})\u003e\n\n    map3 = map2.delete('b')\n    print(map, map2, map3)\n    # will print:\n    #   \u003cimmutables.Map({'a': 1, 'b': 2})\u003e\n    #   \u003cimmutables.Map({'a': 10, 'b': 2})\u003e\n    #   \u003cimmutables.Map({'a': 10})\u003e\n\nMaps also implement APIs for bulk updates: ``MapMutation`` objects:\n\n.. code-block:: python\n\n    map_mutation = map.mutate()\n    map_mutation['a'] = 100\n    del map_mutation['b']\n    map_mutation.set('y', 'y')\n\n    map2 = map_mutation.finish()\n\n    print(map, map2)\n    # will print:\n    #   \u003cimmutables.Map({'a': 1, 'b': 2})\u003e\n    #   \u003cimmutables.Map({'a': 100, 'y': 'y'})\u003e\n\n``MapMutation`` objects are context managers.  Here's the above example\nrewritten in a more idiomatic way:\n\n.. code-block:: python\n\n    with map.mutate() as mm:\n        mm['a'] = 100\n        del mm['b']\n        mm.set('y', 'y')\n        map2 = mm.finish()\n\n    print(map, map2)\n    # will print:\n    #   \u003cimmutables.Map({'a': 1, 'b': 2})\u003e\n    #   \u003cimmutables.Map({'a': 100, 'y': 'y'})\u003e\n\n\nFurther development\n-------------------\n\n* An immutable version of Python ``set`` type with efficient\n  ``add()`` and ``discard()`` operations.\n\n\nLicense\n-------\n\nApache 2.0\n","funding_links":[],"categories":["Uncategorized","C","Data Processing","Topics Index","Data Structures","Awesome Functional Python"],"sub_categories":["Uncategorized","Data Representation","QoL Libraries","Libraries"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMagicStack%2Fimmutables","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMagicStack%2Fimmutables","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMagicStack%2Fimmutables/lists"}