METADATA 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. Metadata-Version: 2.0
  2. Name: pyrsistent
  3. Version: 0.16.0
  4. Summary: Persistent/Functional/Immutable data structures
  5. Home-page: http://github.com/tobgu/pyrsistent/
  6. Author: Tobias Gustafsson
  7. Author-email: tobias.l.gustafsson@gmail.com
  8. License: MIT
  9. Platform: UNKNOWN
  10. Classifier: Intended Audience :: Developers
  11. Classifier: License :: OSI Approved :: MIT License
  12. Classifier: Operating System :: OS Independent
  13. Classifier: Programming Language :: Python :: 3.5
  14. Classifier: Programming Language :: Python :: 3.6
  15. Classifier: Programming Language :: Python :: 3.7
  16. Classifier: Programming Language :: Python :: Implementation :: PyPy
  17. Requires-Dist: six
  18. Pyrsistent
  19. ==========
  20. .. image:: https://travis-ci.org/tobgu/pyrsistent.png?branch=master
  21. :target: https://travis-ci.org/tobgu/pyrsistent
  22. .. image:: https://badge.fury.io/py/pyrsistent.svg
  23. :target: https://badge.fury.io/py/pyrsistent
  24. .. image:: https://coveralls.io/repos/tobgu/pyrsistent/badge.svg?branch=master&service=github
  25. :target: https://coveralls.io/github/tobgu/pyrsistent?branch=master
  26. .. _Pyrthon: https://www.github.com/tobgu/pyrthon/
  27. Pyrsistent is a number of persistent collections (by some referred to as functional data structures). Persistent in
  28. the sense that they are immutable.
  29. All methods on a data structure that would normally mutate it instead return a new copy of the structure containing the
  30. requested updates. The original structure is left untouched.
  31. This will simplify the reasoning about what a program does since no hidden side effects ever can take place to these
  32. data structures. You can rest assured that the object you hold a reference to will remain the same throughout its
  33. lifetime and need not worry that somewhere five stack levels below you in the darkest corner of your application
  34. someone has decided to remove that element that you expected to be there.
  35. Pyrsistent is influenced by persistent data structures such as those found in the standard library of Clojure. The
  36. data structures are designed to share common elements through path copying.
  37. It aims at taking these concepts and make them as pythonic as possible so that they can be easily integrated into any python
  38. program without hassle.
  39. If you want to go all in on persistent data structures and use literal syntax to define them in your code rather
  40. than function calls check out Pyrthon_.
  41. Examples
  42. --------
  43. .. _Sequence: collections_
  44. .. _Hashable: collections_
  45. .. _Mapping: collections_
  46. .. _Mappings: collections_
  47. .. _Set: collections_
  48. .. _collections: https://docs.python.org/3/library/collections.abc.html
  49. .. _documentation: http://pyrsistent.readthedocs.org/
  50. The collection types and key features currently implemented are:
  51. * PVector_, similar to a python list
  52. * PMap_, similar to dict
  53. * PSet_, similar to set
  54. * PRecord_, a PMap on steroids with fixed fields, optional type and invariant checking and much more
  55. * PClass_, a Python class fixed fields, optional type and invariant checking and much more
  56. * `Checked collections`_, PVector, PMap and PSet with optional type and invariance checks and more
  57. * PBag, similar to collections.Counter
  58. * PList, a classic singly linked list
  59. * PDeque, similar to collections.deque
  60. * Immutable object type (immutable) built on the named tuple
  61. * freeze_ and thaw_ functions to convert between pythons standard collections and pyrsistent collections.
  62. * Flexible transformations_ of arbitrarily complex structures built from PMaps and PVectors.
  63. Below are examples of common usage patterns for some of the structures and features. More information and
  64. full documentation for all data structures is available in the documentation_.
  65. .. _PVector:
  66. PVector
  67. ~~~~~~~
  68. With full support for the Sequence_ protocol PVector is meant as a drop in replacement to the built in list from a readers
  69. point of view. Write operations of course differ since no in place mutation is done but naming should be in line
  70. with corresponding operations on the built in list.
  71. Support for the Hashable_ protocol also means that it can be used as key in Mappings_.
  72. Appends are amortized O(1). Random access and insert is log32(n) where n is the size of the vector.
  73. .. code:: python
  74. >>> from pyrsistent import v, pvector
  75. # No mutation of vectors once created, instead they
  76. # are "evolved" leaving the original untouched
  77. >>> v1 = v(1, 2, 3)
  78. >>> v2 = v1.append(4)
  79. >>> v3 = v2.set(1, 5)
  80. >>> v1
  81. pvector([1, 2, 3])
  82. >>> v2
  83. pvector([1, 2, 3, 4])
  84. >>> v3
  85. pvector([1, 5, 3, 4])
  86. # Random access and slicing
  87. >>> v3[1]
  88. 5
  89. >>> v3[1:3]
  90. pvector([5, 3])
  91. # Iteration
  92. >>> list(x + 1 for x in v3)
  93. [2, 6, 4, 5]
  94. >>> pvector(2 * x for x in range(3))
  95. pvector([0, 2, 4])
  96. .. _PMap:
  97. PMap
  98. ~~~~
  99. With full support for the Mapping_ protocol PMap is meant as a drop in replacement to the built in dict from a readers point
  100. of view. Support for the Hashable_ protocol also means that it can be used as key in other Mappings_.
  101. Random access and insert is log32(n) where n is the size of the map.
  102. .. code:: python
  103. >>> from pyrsistent import m, pmap, v
  104. # No mutation of maps once created, instead they are
  105. # "evolved" leaving the original untouched
  106. >>> m1 = m(a=1, b=2)
  107. >>> m2 = m1.set('c', 3)
  108. >>> m3 = m2.set('a', 5)
  109. >>> m1
  110. pmap({'a': 1, 'b': 2})
  111. >>> m2
  112. pmap({'a': 1, 'c': 3, 'b': 2})
  113. >>> m3
  114. pmap({'a': 5, 'c': 3, 'b': 2})
  115. >>> m3['a']
  116. 5
  117. # Evolution of nested persistent structures
  118. >>> m4 = m(a=5, b=6, c=v(1, 2))
  119. >>> m4.transform(('c', 1), 17)
  120. pmap({'a': 5, 'c': pvector([1, 17]), 'b': 6})
  121. >>> m5 = m(a=1, b=2)
  122. # Evolve by merging with other mappings
  123. >>> m5.update(m(a=2, c=3), {'a': 17, 'd': 35})
  124. pmap({'a': 17, 'c': 3, 'b': 2, 'd': 35})
  125. >>> pmap({'x': 1, 'y': 2}) + pmap({'y': 3, 'z': 4})
  126. pmap({'y': 3, 'x': 1, 'z': 4})
  127. # Dict-like methods to convert to list and iterate
  128. >>> m3.items()
  129. pvector([('a', 5), ('c', 3), ('b', 2)])
  130. >>> list(m3)
  131. ['a', 'c', 'b']
  132. .. _PSet:
  133. PSet
  134. ~~~~
  135. With full support for the Set_ protocol PSet is meant as a drop in replacement to the built in set from a readers point
  136. of view. Support for the Hashable_ protocol also means that it can be used as key in Mappings_.
  137. Random access and insert is log32(n) where n is the size of the set.
  138. .. code:: python
  139. >>> from pyrsistent import s
  140. # No mutation of sets once created, you know the story...
  141. >>> s1 = s(1, 2, 3, 2)
  142. >>> s2 = s1.add(4)
  143. >>> s3 = s1.remove(1)
  144. >>> s1
  145. pset([1, 2, 3])
  146. >>> s2
  147. pset([1, 2, 3, 4])
  148. >>> s3
  149. pset([2, 3])
  150. # Full support for set operations
  151. >>> s1 | s(3, 4, 5)
  152. pset([1, 2, 3, 4, 5])
  153. >>> s1 & s(3, 4, 5)
  154. pset([3])
  155. >>> s1 < s2
  156. True
  157. >>> s1 < s(3, 4, 5)
  158. False
  159. .. _PRecord:
  160. PRecord
  161. ~~~~~~~
  162. A PRecord is a PMap with a fixed set of specified fields. Records are declared as python classes inheriting
  163. from PRecord. Because it is a PMap it has full support for all Mapping methods such as iteration and element
  164. access using subscript notation.
  165. .. code:: python
  166. >>> from pyrsistent import PRecord, field
  167. >>> class ARecord(PRecord):
  168. ... x = field()
  169. ...
  170. >>> r = ARecord(x=3)
  171. >>> r
  172. ARecord(x=3)
  173. >>> r.x
  174. 3
  175. >>> r.set(x=2)
  176. ARecord(x=2)
  177. >>> r.set(y=2)
  178. Traceback (most recent call last):
  179. AttributeError: 'y' is not among the specified fields for ARecord
  180. Type information
  181. ****************
  182. It is possible to add type information to the record to enforce type checks. Multiple allowed types can be specified
  183. by providing an iterable of types.
  184. .. code:: python
  185. >>> class BRecord(PRecord):
  186. ... x = field(type=int)
  187. ... y = field(type=(int, type(None)))
  188. ...
  189. >>> BRecord(x=3, y=None)
  190. BRecord(y=None, x=3)
  191. >>> BRecord(x=3.0)
  192. Traceback (most recent call last):
  193. PTypeError: Invalid type for field BRecord.x, was float
  194. Custom types (classes) that are iterable should be wrapped in a tuple to prevent their
  195. members being added to the set of valid types. Although Enums in particular are now
  196. supported without wrapping, see #83 for more information.
  197. Mandatory fields
  198. ****************
  199. Fields are not mandatory by default but can be specified as such. If fields are missing an
  200. *InvariantException* will be thrown which contains information about the missing fields.
  201. .. code:: python
  202. >>> from pyrsistent import InvariantException
  203. >>> class CRecord(PRecord):
  204. ... x = field(mandatory=True)
  205. ...
  206. >>> r = CRecord(x=3)
  207. >>> try:
  208. ... r.discard('x')
  209. ... except InvariantException as e:
  210. ... print(e.missing_fields)
  211. ...
  212. ('CRecord.x',)
  213. Invariants
  214. **********
  215. It is possible to add invariants that must hold when evolving the record. Invariants can be
  216. specified on both field and record level. If invariants fail an *InvariantException* will be
  217. thrown which contains information about the failing invariants. An invariant function should
  218. return a tuple consisting of a boolean that tells if the invariant holds or not and an object
  219. describing the invariant. This object can later be used to identify which invariant that failed.
  220. The global invariant function is only executed if all field invariants hold.
  221. Global invariants are inherited to subclasses.
  222. .. code:: python
  223. >>> class RestrictedVector(PRecord):
  224. ... __invariant__ = lambda r: (r.y >= r.x, 'x larger than y')
  225. ... x = field(invariant=lambda x: (x > 0, 'x negative'))
  226. ... y = field(invariant=lambda y: (y > 0, 'y negative'))
  227. ...
  228. >>> r = RestrictedVector(y=3, x=2)
  229. >>> try:
  230. ... r.set(x=-1, y=-2)
  231. ... except InvariantException as e:
  232. ... print(e.invariant_errors)
  233. ...
  234. ('y negative', 'x negative')
  235. >>> try:
  236. ... r.set(x=2, y=1)
  237. ... except InvariantException as e:
  238. ... print(e.invariant_errors)
  239. ...
  240. ('x larger than y',)
  241. Invariants may also contain multiple assertions. For those cases the invariant function should
  242. return a tuple of invariant tuples as described above. This structure is reflected in the
  243. invariant_errors attribute of the exception which will contain tuples with data from all failed
  244. invariants. Eg:
  245. .. code:: python
  246. >>> class EvenX(PRecord):
  247. ... x = field(invariant=lambda x: ((x > 0, 'x negative'), (x % 2 == 0, 'x odd')))
  248. ...
  249. >>> try:
  250. ... EvenX(x=-1)
  251. ... except InvariantException as e:
  252. ... print(e.invariant_errors)
  253. ...
  254. (('x negative', 'x odd'),)
  255. Factories
  256. *********
  257. It's possible to specify factory functions for fields. The factory function receives whatever
  258. is supplied as field value and the actual returned by the factory is assigned to the field
  259. given that any type and invariant checks hold.
  260. PRecords have a default factory specified as a static function on the class, create(). It takes
  261. a *Mapping* as argument and returns an instance of the specific record.
  262. If a record has fields of type PRecord the create() method of that record will
  263. be called to create the "sub record" if no factory has explicitly been specified to override
  264. this behaviour.
  265. .. code:: python
  266. >>> class DRecord(PRecord):
  267. ... x = field(factory=int)
  268. ...
  269. >>> class ERecord(PRecord):
  270. ... d = field(type=DRecord)
  271. ...
  272. >>> ERecord.create({'d': {'x': '1'}})
  273. ERecord(d=DRecord(x=1))
  274. Collection fields
  275. *****************
  276. It is also possible to have fields with ``pyrsistent`` collections.
  277. .. code:: python
  278. >>> from pyrsistent import pset_field, pmap_field, pvector_field
  279. >>> class MultiRecord(PRecord):
  280. ... set_of_ints = pset_field(int)
  281. ... map_int_to_str = pmap_field(int, str)
  282. ... vector_of_strs = pvector_field(str)
  283. ...
  284. Serialization
  285. *************
  286. PRecords support serialization back to dicts. Default serialization will take keys and values
  287. "as is" and output them into a dict. It is possible to specify custom serialization functions
  288. to take care of fields that require special treatment.
  289. .. code:: python
  290. >>> from datetime import date
  291. >>> class Person(PRecord):
  292. ... name = field(type=unicode)
  293. ... birth_date = field(type=date,
  294. ... serializer=lambda format, d: d.strftime(format['date']))
  295. ...
  296. >>> john = Person(name=u'John', birth_date=date(1985, 10, 21))
  297. >>> john.serialize({'date': '%Y-%m-%d'})
  298. {'birth_date': '1985-10-21', 'name': u'John'}
  299. .. _instar: https://github.com/boxed/instar/
  300. .. _PClass:
  301. PClass
  302. ~~~~~~
  303. A PClass is a python class with a fixed set of specified fields. PClasses are declared as python classes inheriting
  304. from PClass. It is defined the same way that PRecords are and behaves like a PRecord in all aspects except that it
  305. is not a PMap and hence not a collection but rather a plain Python object.
  306. .. code:: python
  307. >>> from pyrsistent import PClass, field
  308. >>> class AClass(PClass):
  309. ... x = field()
  310. ...
  311. >>> a = AClass(x=3)
  312. >>> a
  313. AClass(x=3)
  314. >>> a.x
  315. 3
  316. Checked collections
  317. ~~~~~~~~~~~~~~~~~~~
  318. Checked collections currently come in three flavors: CheckedPVector, CheckedPMap and CheckedPSet.
  319. .. code:: python
  320. >>> from pyrsistent import CheckedPVector, CheckedPMap, CheckedPSet, thaw
  321. >>> class Positives(CheckedPSet):
  322. ... __type__ = (long, int)
  323. ... __invariant__ = lambda n: (n >= 0, 'Negative')
  324. ...
  325. >>> class Lottery(PRecord):
  326. ... name = field(type=str)
  327. ... numbers = field(type=Positives, invariant=lambda p: (len(p) > 0, 'No numbers'))
  328. ...
  329. >>> class Lotteries(CheckedPVector):
  330. ... __type__ = Lottery
  331. ...
  332. >>> class LotteriesByDate(CheckedPMap):
  333. ... __key_type__ = date
  334. ... __value_type__ = Lotteries
  335. ...
  336. >>> lotteries = LotteriesByDate.create({date(2015, 2, 15): [{'name': 'SuperLotto', 'numbers': {1, 2, 3}},
  337. ... {'name': 'MegaLotto', 'numbers': {4, 5, 6}}],
  338. ... date(2015, 2, 16): [{'name': 'SuperLotto', 'numbers': {3, 2, 1}},
  339. ... {'name': 'MegaLotto', 'numbers': {6, 5, 4}}]})
  340. >>> lotteries
  341. LotteriesByDate({datetime.date(2015, 2, 15): Lotteries([Lottery(numbers=Positives([1, 2, 3]), name='SuperLotto'), Lottery(numbers=Positives([4, 5, 6]), name='MegaLotto')]), datetime.date(2015, 2, 16): Lotteries([Lottery(numbers=Positives([1, 2, 3]), name='SuperLotto'), Lottery(numbers=Positives([4, 5, 6]), name='MegaLotto')])})
  342. # The checked versions support all operations that the corresponding
  343. # unchecked types do
  344. >>> lottery_0215 = lotteries[date(2015, 2, 15)]
  345. >>> lottery_0215.transform([0, 'name'], 'SuperDuperLotto')
  346. Lotteries([Lottery(numbers=Positives([1, 2, 3]), name='SuperDuperLotto'), Lottery(numbers=Positives([4, 5, 6]), name='MegaLotto')])
  347. # But also makes asserts that types and invariants hold
  348. >>> lottery_0215.transform([0, 'name'], 999)
  349. Traceback (most recent call last):
  350. PTypeError: Invalid type for field Lottery.name, was int
  351. >>> lottery_0215.transform([0, 'numbers'], set())
  352. Traceback (most recent call last):
  353. InvariantException: Field invariant failed
  354. # They can be converted back to python built ins with either thaw()
  355. # or serialize() (which provides possibilities to customize serialization)
  356. >>> thaw(lottery_0215)
  357. [{'numbers': set([1, 2, 3]), 'name': 'SuperLotto'}, {'numbers': set([4, 5, 6]), 'name': 'MegaLotto'}]
  358. >>> lottery_0215.serialize()
  359. [{'numbers': set([1, 2, 3]), 'name': 'SuperLotto'}, {'numbers': set([4, 5, 6]), 'name': 'MegaLotto'}]
  360. .. _transformations:
  361. Transformations
  362. ~~~~~~~~~~~~~~~
  363. Transformations are inspired by the cool library instar_ for Clojure. They let you evolve PMaps and PVectors
  364. with arbitrarily deep/complex nesting using simple syntax and flexible matching syntax.
  365. The first argument to transformation is the path that points out the value to transform. The
  366. second is the transformation to perform. If the transformation is callable it will be applied
  367. to the value(s) matching the path. The path may also contain callables. In that case they are
  368. treated as matchers. If the matcher returns True for a specific key it is considered for transformation.
  369. .. code:: python
  370. # Basic examples
  371. >>> from pyrsistent import inc, freeze, thaw, rex, ny, discard
  372. >>> v1 = freeze([1, 2, 3, 4, 5])
  373. >>> v1.transform([2], inc)
  374. pvector([1, 2, 4, 4, 5])
  375. >>> v1.transform([lambda ix: 0 < ix < 4], 8)
  376. pvector([1, 8, 8, 8, 5])
  377. >>> v1.transform([lambda ix, v: ix == 0 or v == 5], 0)
  378. pvector([0, 2, 3, 4, 0])
  379. # The (a)ny matcher can be used to match anything
  380. >>> v1.transform([ny], 8)
  381. pvector([8, 8, 8, 8, 8])
  382. # Regular expressions can be used for matching
  383. >>> scores = freeze({'John': 12, 'Joseph': 34, 'Sara': 23})
  384. >>> scores.transform([rex('^Jo')], 0)
  385. pmap({'Joseph': 0, 'Sara': 23, 'John': 0})
  386. # Transformations can be done on arbitrarily deep structures
  387. >>> news_paper = freeze({'articles': [{'author': 'Sara', 'content': 'A short article'},
  388. ... {'author': 'Steve', 'content': 'A slightly longer article'}],
  389. ... 'weather': {'temperature': '11C', 'wind': '5m/s'}})
  390. >>> short_news = news_paper.transform(['articles', ny, 'content'], lambda c: c[:25] + '...' if len(c) > 25 else c)
  391. >>> very_short_news = news_paper.transform(['articles', ny, 'content'], lambda c: c[:15] + '...' if len(c) > 15 else c)
  392. >>> very_short_news.articles[0].content
  393. 'A short article'
  394. >>> very_short_news.articles[1].content
  395. 'A slightly long...'
  396. # When nothing has been transformed the original data structure is kept
  397. >>> short_news is news_paper
  398. True
  399. >>> very_short_news is news_paper
  400. False
  401. >>> very_short_news.articles[0] is news_paper.articles[0]
  402. True
  403. # There is a special transformation that can be used to discard elements. Also
  404. # multiple transformations can be applied in one call
  405. >>> thaw(news_paper.transform(['weather'], discard, ['articles', ny, 'content'], discard))
  406. {'articles': [{'author': 'Sara'}, {'author': 'Steve'}]}
  407. Evolvers
  408. ~~~~~~~~
  409. PVector, PMap and PSet all have support for a concept dubbed *evolvers*. An evolver acts like a mutable
  410. view of the underlying persistent data structure with "transaction like" semantics. No updates of the original
  411. data structure is ever performed, it is still fully immutable.
  412. The evolvers have a very limited API by design to discourage excessive, and inappropriate, usage as that would
  413. take us down the mutable road. In principle only basic mutation and element access functions are supported.
  414. Check out the documentation_ of each data structure for specific examples.
  415. Examples of when you may want to use an evolver instead of working directly with the data structure include:
  416. * Multiple updates are done to the same data structure and the intermediate results are of no
  417. interest. In this case using an evolver may be a more efficient and easier to work with.
  418. * You need to pass a vector into a legacy function or a function that you have no control
  419. over which performs in place mutations. In this case pass an evolver instance
  420. instead and then create a new pvector from the evolver once the function returns.
  421. .. code:: python
  422. >>> from pyrsistent import v
  423. # In place mutation as when working with the built in counterpart
  424. >>> v1 = v(1, 2, 3)
  425. >>> e = v1.evolver()
  426. >>> e[1] = 22
  427. >>> e = e.append(4)
  428. >>> e = e.extend([5, 6])
  429. >>> e[5] += 1
  430. >>> len(e)
  431. 6
  432. # The evolver is considered *dirty* when it contains changes compared to the underlying vector
  433. >>> e.is_dirty()
  434. True
  435. # But the underlying pvector still remains untouched
  436. >>> v1
  437. pvector([1, 2, 3])
  438. # Once satisfied with the updates you can produce a new pvector containing the updates.
  439. # The new pvector will share data with the original pvector in the same way that would have
  440. # been done if only using operations on the pvector.
  441. >>> v2 = e.persistent()
  442. >>> v2
  443. pvector([1, 22, 3, 4, 5, 7])
  444. # The evolver is now no longer considered *dirty* as it contains no differences compared to the
  445. # pvector just produced.
  446. >>> e.is_dirty()
  447. False
  448. # You may continue to work with the same evolver without affecting the content of v2
  449. >>> e[0] = 11
  450. # Or create a new evolver from v2. The two evolvers can be updated independently but will both
  451. # share data with v2 where possible.
  452. >>> e2 = v2.evolver()
  453. >>> e2[0] = 1111
  454. >>> e.persistent()
  455. pvector([11, 22, 3, 4, 5, 7])
  456. >>> e2.persistent()
  457. pvector([1111, 22, 3, 4, 5, 7])
  458. .. _freeze:
  459. .. _thaw:
  460. freeze and thaw
  461. ~~~~~~~~~~~~~~~
  462. These functions are great when your cozy immutable world has to interact with the evil mutable world outside.
  463. .. code:: python
  464. >>> from pyrsistent import freeze, thaw, v, m
  465. >>> freeze([1, {'a': 3}])
  466. pvector([1, pmap({'a': 3})])
  467. >>> thaw(v(1, m(a=3)))
  468. [1, {'a': 3}]
  469. Compatibility
  470. -------------
  471. Pyrsistent is developed and tested on Python 2.7, 3.5, 3.6, 3.7 and PyPy (Python 2 and 3 compatible). It will most
  472. likely work on all other versions >= 3.4 but no guarantees are given. :)
  473. Compatibility issues
  474. ~~~~~~~~~~~~~~~~~~~~
  475. .. _27: https://github.com/tobgu/pyrsistent/issues/27
  476. There is currently one known compatibility issue when comparing built in sets and frozensets to PSets as discussed in 27_.
  477. It affects python 2 versions < 2.7.8 and python 3 versions < 3.4.0 and is due to a bug described in
  478. http://bugs.python.org/issue8743.
  479. Comparisons will fail or be incorrect when using the set/frozenset as left hand side of the comparison. As a workaround
  480. you need to either upgrade Python to a more recent version, avoid comparing sets/frozensets with PSets or always make
  481. sure to convert both sides of the comparison to the same type before performing the comparison.
  482. Performance
  483. -----------
  484. Pyrsistent is developed with performance in mind. Still, while some operations are nearly on par with their built in,
  485. mutable, counterparts in terms of speed, other operations are slower. In the cases where attempts at
  486. optimizations have been done, speed has generally been valued over space.
  487. Pyrsistent comes with two API compatible flavors of PVector (on which PMap and PSet are based), one pure Python
  488. implementation and one implemented as a C extension. The latter generally being 2 - 20 times faster than the former.
  489. The C extension will be used automatically when possible.
  490. The pure python implementation is fully PyPy compatible. Running it under PyPy speeds operations up considerably if
  491. the structures are used heavily (if JITed), for some cases the performance is almost on par with the built in counterparts.
  492. Type hints
  493. ----------
  494. PEP 561 style type hints for use with mypy and various editors are available for most types and functions in pyrsistent.
  495. Type classes for annotating your own code with pyrsistent types are also available under pyrsistent.typing.
  496. Installation
  497. ------------
  498. pip install pyrsistent
  499. Documentation
  500. -------------
  501. Available at http://pyrsistent.readthedocs.org/
  502. Brief presentation available at http://slides.com/tobiasgustafsson/immutability-and-python/
  503. Contributors
  504. ------------
  505. Tobias Gustafsson https://github.com/tobgu
  506. Christopher Armstrong https://github.com/radix
  507. Anders Hovmöller https://github.com/boxed
  508. Itamar Turner-Trauring https://github.com/itamarst
  509. Jonathan Lange https://github.com/jml
  510. Richard Futrell https://github.com/Futrell
  511. Jakob Hollenstein https://github.com/jkbjh
  512. David Honour https://github.com/foolswood
  513. David R. MacIver https://github.com/DRMacIver
  514. Marcus Ewert https://github.com/sarum90
  515. Jean-Paul Calderone https://github.com/exarkun
  516. Douglas Treadwell https://github.com/douglas-treadwell
  517. Travis Parker https://github.com/teepark
  518. Julian Berman https://github.com/Julian
  519. Dennis Tomas https://github.com/dtomas
  520. Neil Vyas https://github.com/neilvyas
  521. doozr https://github.com/doozr
  522. Kamil Galuszka https://github.com/galuszkak
  523. Tsuyoshi Hombashi https://github.com/thombashi
  524. nattofriends https://github.com/nattofriends
  525. agberk https://github.com/agberk
  526. Waleed Khan https://github.com/arxanas
  527. Jean-Louis Fuchs https://github.com/ganwell
  528. Carlos Corbacho https://github.com/ccorbacho
  529. Felix Yan https://github.com/felixonmars
  530. benrg https://github.com/benrg
  531. Jere Lahelma https://github.com/je-l
  532. Max Taggart https://github.com/MaxTaggart
  533. Vincent Philippon https://github.com/vphilippon
  534. Semen Zhydenko https://github.com/ss18
  535. Till Varoquaux https://github.com/till-varoquaux
  536. Michal Kowalik https://github.com/michalvi
  537. ossdev07 https://github.com/ossdev07
  538. Kerry Olesen https://github.com/qhesz
  539. johnthagen https://github.com/johnthagen
  540. Contributing
  541. ------------
  542. Want to contribute? That's great! If you experience problems please log them on GitHub. If you want to contribute code,
  543. please fork the repository and submit a pull request.
  544. Run tests
  545. ~~~~~~~~~
  546. .. _tox: https://tox.readthedocs.io/en/latest/
  547. Tests can be executed using tox_.
  548. Install tox: ``pip install tox``
  549. Run test for Python 2.7: ``tox -epy27``
  550. Release
  551. ~~~~~~~
  552. * Update CHANGES.txt
  553. * Update README with any new contributors and potential info needed.
  554. * Update _pyrsistent_version.py
  555. * python setup.py sdist upload
  556. * Commit and tag with new version: git add -u . && git commit -m 'Prepare version vX.Y.Z' && git tag -a vX.Y.Z -m 'vX.Y.Z'
  557. * Push commit and tags: git push && git push --tags
  558. Project status
  559. --------------
  560. Pyrsistent can be considered stable and mature (who knows, there may even be a 1.0 some day :-)). The project is
  561. maintained, bugs fixed, PRs reviewed and merged and new releases made. I currently do not have time for development
  562. of new features or functionality which I don't have use for myself. I'm more than happy to take PRs for new
  563. functionality though!
  564. There are a bunch of issues marked with ``enhancement`` and ``help wanted`` that contain requests for new functionality
  565. that would be nice to include. The level of difficulty and extend of the issues varies, please reach out to me if you're
  566. interested in working on any of them.
  567. If you feel that you have a grand master plan for where you would like Pyrsistent to go and have the time to put into
  568. it please don't hesitate to discuss this with me and submit PRs for it. If all goes well I'd be more than happy to add
  569. additional maintainers to the project!