{ "info": { "author": "Tobias Gustafsson", "author_email": "tobias.l.gustafsson@gmail.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python" ], "description": "Introduction\n============\n\n.. _Pyrsistent: https://www.github.com/tobgu/pyrsistent/\n\nPyrthon is a utility library that substitutes python collection literals with their Pyrsistent_ counterparts.\n\nInstead of writing this:\n\n.. code:: python\n\n from pyrsistent import pvector\n x = pvector([1, 2, 3])\n y = x.set(0, 17)\n\nYou can simply write this:\n\n.. code:: python\n\n x = [1, 2, 3]\n y = x.set(0, 17)\n\nThe results will be equivalent.\n\nExamples\n--------\n\nIn *foo/main.py*:\n\n.. code:: python\n\n # Register any modules under 'foo' for pyrsistent substitution before any\n # imports from 'foo' modules.\n #\n # Registration can be done in three ways:\n # * Exact module name.\n # register('foo.bar')\n # * Prefix with wild card. All submodules of the prefix.\n # register('foo.*')\n # * Custom matcher function that returns true if substitution should be applied in the module.\n # register(lambda name: name.startswith('foo') and name.endswith('baz'))\n\n from pyrthon import register\n register('foo.*')\n\n from foo.app import run\n\n if __name__ == '__main__':\n run()\n\n\nIn *foo/app.py*:\n\n.. code:: python\n\n # All literal collection declarations in this module will now be mapped to\n # corresponding pyrsistent collections.\n\n def run():\n x = [1, 2, 3] # -> pvector([1, 2, 3])\n y = {'a': 1} # -> pmap({'a': 1})\n z = {'a'} # -> pset(['a'])\n\n # It's not possible to declare an empty set in python using a literal.\n # Therefore some special treatment is required.\n p = set() # -> pset([]), pyrsistent pset\n q = set([]) # -> set(), regular python set\n\n # To declare regular python lists, dicts and sets just use the function syntax\n a = list([1, 2, 3]) # -> [1, 2, 3]\n b = dict(a=1) # -> {'a': 1}\n c = set(['a']) # -> set(['a'])\n\n print('Hello functional world!')\n\nPyrthon also has basic shell support. Just import *pyrthon.console* and you're good to go:\n\n.. code:: python\n\n >>> import pyrthon.console\n Pyrsistent data structures enabled\n >>> [1, 2, 3]\n pvector([1, 2, 3])\n >>> {'a': 1}\n pmap({'a': 1})\n >>> {'a'}\n pset(['a'])\n\n\nIt's also possible to use pyrthon from Jupyter/IPython notebooks. For that an extension must be loaded.\nThis can be done from the console or a cell:\n\n.. code:: shell\n\n % load_ext pyrthon\n\n\nInstallation\n------------\n\npip install pyrthon\n\nHow it works\n------------\n\nPyrthon works by Python AST manipulation and import hooks. All literal lists and list comprehensions,\ndicts and dict comprehensions, sets and set comprehensions in selected modules are substituted to produce\nthe equivalent Pyrsistent data structure upon module import.\n\nLimitations and quirks\n----------------------\n\nThis library is currently in experimental status.\n\nIf combined with other frameworks that manipulate the AST or performs other \"magic\" transformations to your\ncode the result may not be as expected.\n\nUsage in tests executed with pytest requires some additional work since no explicit import of the test files\nis ever performed. Also the assert used by pytest is heavily manipulated compared to the original assert and\nprevents direct substitution of literals. Normally this should not matter for the sake of testing though since\na pvector compares to a list, a pmap to a dict and a pset to a set but it's good to know.\n\nBecause substitution is performed on import Pyrthon currently requires at least two python files in any application\nand library. One file, in which no substitutions will take place, will have to register all modules on which\ntransformations should be applied before those modules are imported. The file containing the main entry point for\na program/library would be a good point to perform this registration.\n\nCompatibility\n-------------\n\nPyrthon is developed and tested on Python 2.7, 3.4 and PyPy (Python 2.7 compatible).\n\nContributors\n------------\n\nTobias Gustafsson https://github.com/tobgu\n\nTodd Iverson https://github.com/yardsale8 (IPython/Jupyter support)\n\nContributing\n------------\n\nIf you experience problems please log them on GitHub. If you want to contribute code, please submit a pull request.\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/tobgu/pyrthon/", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "pyrthon", "package_url": "https://pypi.org/project/pyrthon/", "platform": "", "project_url": "https://pypi.org/project/pyrthon/", "project_urls": { "Homepage": "http://github.com/tobgu/pyrthon/" }, "release_url": "https://pypi.org/project/pyrthon/0.1.2/", "requires_dist": null, "requires_python": "", "summary": "Literal syntax for Pyrsistent data structures", "version": "0.1.2" }, "last_serial": 2668698, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "a43412a0312ec0643068db2e80c86bc7", "sha256": "1ee9a0624d3d15045a29d1616ecc2793c41a934e108d6a7f4df411c92a367e95" }, "downloads": -1, "filename": "pyrthon-0.1.0.tar.gz", "has_sig": false, "md5_digest": "a43412a0312ec0643068db2e80c86bc7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5137, "upload_time": "2015-05-03T13:32:21", "url": "https://files.pythonhosted.org/packages/1f/0b/df3bdb74cdde3eaed6bef56c9751d21f97833762ec7a43b5039d6e51f0ea/pyrthon-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "9f99013f45c72077a1c0c3dbce96b053", "sha256": "24046f1265ddb42f0490d7aefe2500389105941d318305c84d30d61777720e8b" }, "downloads": -1, "filename": "pyrthon-0.1.1.tar.gz", "has_sig": false, "md5_digest": "9f99013f45c72077a1c0c3dbce96b053", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4873, "upload_time": "2015-05-27T17:43:25", "url": "https://files.pythonhosted.org/packages/f0/89/c422ad36f83b50eb5133214762a134f7b976500fc9026b6c8df6bc5edaf1/pyrthon-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "3a5497598309e67efe15e12aa641d01f", "sha256": "489436189fd1e777d8b703b4d5cd665ebd245d490a5e70f0af8ef0eebd045e81" }, "downloads": -1, "filename": "pyrthon-0.1.2.tar.gz", "has_sig": false, "md5_digest": "3a5497598309e67efe15e12aa641d01f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5171, "upload_time": "2017-02-26T11:08:34", "url": "https://files.pythonhosted.org/packages/8d/25/1f95fe127a5c4a76c122b7f2b1033a688de35eb82e187f80f29873b1cea8/pyrthon-0.1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "3a5497598309e67efe15e12aa641d01f", "sha256": "489436189fd1e777d8b703b4d5cd665ebd245d490a5e70f0af8ef0eebd045e81" }, "downloads": -1, "filename": "pyrthon-0.1.2.tar.gz", "has_sig": false, "md5_digest": "3a5497598309e67efe15e12aa641d01f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5171, "upload_time": "2017-02-26T11:08:34", "url": "https://files.pythonhosted.org/packages/8d/25/1f95fe127a5c4a76c122b7f2b1033a688de35eb82e187f80f29873b1cea8/pyrthon-0.1.2.tar.gz" } ] }