25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

158 lines
4.3 KiB

  1. Metadata-Version: 2.1
  2. Name: immutables
  3. Version: 0.16
  4. Summary: Immutable Collections
  5. Home-page: https://github.com/MagicStack/immutables
  6. Author: MagicStack Inc
  7. Author-email: hello@magic.io
  8. License: Apache License, Version 2.0
  9. Platform: UNKNOWN
  10. Classifier: License :: OSI Approved :: Apache Software License
  11. Classifier: Intended Audience :: Developers
  12. Classifier: Programming Language :: Python :: 3 :: Only
  13. Classifier: Programming Language :: Python :: 3.6
  14. Classifier: Programming Language :: Python :: 3.7
  15. Classifier: Programming Language :: Python :: 3.8
  16. Classifier: Programming Language :: Python :: 3.9
  17. Classifier: Programming Language :: Python :: 3.10
  18. Classifier: Operating System :: POSIX
  19. Classifier: Operating System :: MacOS :: MacOS X
  20. Classifier: Operating System :: Microsoft :: Windows
  21. Provides: immutables
  22. Requires-Python: >=3.6
  23. License-File: LICENSE
  24. License-File: LICENSE-APACHE
  25. License-File: NOTICE
  26. Requires-Dist: typing-extensions (>=3.7.4.3) ; python_version < "3.8"
  27. Provides-Extra: test
  28. Requires-Dist: flake8 (~=3.8.4) ; extra == 'test'
  29. Requires-Dist: pycodestyle (~=2.6.0) ; extra == 'test'
  30. Requires-Dist: mypy (>=0.910) ; extra == 'test'
  31. Requires-Dist: pytest (~=6.2.4) ; extra == 'test'
  32. immutables
  33. ==========
  34. .. image:: https://github.com/MagicStack/immutables/workflows/Tests/badge.svg?branch=master
  35. :target: https://github.com/MagicStack/immutables/actions?query=workflow%3ATests+branch%3Amaster+event%3Apush
  36. .. image:: https://img.shields.io/pypi/v/immutables.svg
  37. :target: https://pypi.python.org/pypi/immutables
  38. An immutable mapping type for Python.
  39. The underlying datastructure is a Hash Array Mapped Trie (HAMT)
  40. used in Clojure, Scala, Haskell, and other functional languages.
  41. This implementation is used in CPython 3.7 in the ``contextvars``
  42. module (see `PEP 550 <https://www.python.org/dev/peps/pep-0550/>`_ and
  43. `PEP 567 <https://www.python.org/dev/peps/pep-0567/>`_ for more details).
  44. Immutable mappings based on HAMT have O(log N) performance for both
  45. ``set()`` and ``get()`` operations, which is essentially O(1) for
  46. relatively small mappings.
  47. Below is a visualization of a simple get/set benchmark comparing
  48. HAMT to an immutable mapping implemented with a Python dict
  49. copy-on-write approach (the benchmark code is available
  50. `here <https://gist.github.com/1st1/292e3f0bbe43bd65ff3256f80aa2637d>`_):
  51. .. image:: bench.png
  52. Installation
  53. ------------
  54. ``immutables`` requires Python 3.6+ and is available on PyPI::
  55. $ pip install immutables
  56. API
  57. ---
  58. ``immutables.Map`` is an unordered immutable mapping. ``Map`` objects
  59. are hashable, comparable, and pickleable.
  60. The ``Map`` object implements the ``collections.abc.Mapping`` ABC
  61. so working with it is very similar to working with Python dicts:
  62. .. code-block:: python
  63. import immutables
  64. map = immutables.Map(a=1, b=2)
  65. print(map['a'])
  66. # will print '1'
  67. print(map.get('z', 100))
  68. # will print '100'
  69. print('z' in map)
  70. # will print 'False'
  71. Since Maps are immutable, there is a special API for mutations that
  72. allow apply changes to the Map object and create new (derived) Maps:
  73. .. code-block:: python
  74. map2 = map.set('a', 10)
  75. print(map, map2)
  76. # will print:
  77. # <immutables.Map({'a': 1, 'b': 2})>
  78. # <immutables.Map({'a': 10, 'b': 2})>
  79. map3 = map2.delete('b')
  80. print(map, map2, map3)
  81. # will print:
  82. # <immutables.Map({'a': 1, 'b': 2})>
  83. # <immutables.Map({'a': 10, 'b': 2})>
  84. # <immutables.Map({'a': 10})>
  85. Maps also implement APIs for bulk updates: ``MapMutation`` objects:
  86. .. code-block:: python
  87. map_mutation = map.mutate()
  88. map_mutation['a'] = 100
  89. del map_mutation['b']
  90. map_mutation.set('y', 'y')
  91. map2 = map_mutation.finish()
  92. print(map, map2)
  93. # will print:
  94. # <immutables.Map({'a': 1, 'b': 2})>
  95. # <immutables.Map({'a': 100, 'y': 'y'})>
  96. ``MapMutation`` objects are context managers. Here's the above example
  97. rewritten in a more idiomatic way:
  98. .. code-block:: python
  99. with map.mutate() as mm:
  100. mm['a'] = 100
  101. del mm['b']
  102. mm.set('y', 'y')
  103. map2 = mm.finish()
  104. print(map, map2)
  105. # will print:
  106. # <immutables.Map({'a': 1, 'b': 2})>
  107. # <immutables.Map({'a': 100, 'y': 'y'})>
  108. Further development
  109. -------------------
  110. * An immutable version of Python ``set`` type with efficient
  111. ``add()`` and ``discard()`` operations.
  112. License
  113. -------
  114. Apache 2.0