{ "info": { "author": "Tyler Singer-Clark", "author_email": "tscizzle@gmail.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2", "Topic :: Scientific/Engineering" ], "description": "MemoPy\n======\n\n.. image:: https://travis-ci.org/tscizzle/memopy.svg?branch=master\n :target: https://travis-ci.org/tscizzle/memopy\n\n.. image:: https://coveralls.io/repos/github/tscizzle/memopy/badge.svg?branch=master\n :target: https://coveralls.io/github/tscizzle/memopy?branch=master\n\n.. image:: https://badge.fury.io/py/memopy.svg\n :target: https://badge.fury.io/py/memopy\n\nStore results of functions calls so that subsequent calls with the same arguments do not have to redo work.\n\nThis strategy of memoizing past results is only fully correct with \"pure functions\". Pure functions (https://en.wikipedia.org/wiki/Pure_function) are functions that, when run with the same arguments, always return the same result. They should not have any side effects (e.g. modifying global variables, writing to an external database), or depend on anything besides the parameters (e.g. a random number generator, reading from an external database). Typically any mathematically-defined function (fibonacci, factorial, sine, cosine, etc.) is a pure function.\n\nBut MemoPy can be useful with impure functions, too, when perfect correctness is not required. For example, it can be used to cache the results of network calls to external API's, to avoid repeating expensive network requests (but the cache should be cleared when it is necessary to get completely up to date information).\n\nUse\n---\n\nImport the memoify decorator::\n\n from memopy.memopy import memoify\n\nApply the ``memoify`` decorator to a function to turn that function into a memo function::\n\n @memoify\n def multiply(x, y):\n return x * y\n\nSubsequent calls to ``multiply`` with the same args will not perform the multiplication, but rather look up the past answer.\n\nMultiplying numbers is not a typical use case, so take a look at a function which is inherently reused on the same arguments a lot::\n\n @memoify\n def fibo(n):\n if n in [0, 1]:\n return n\n return fibo(n-1) + fibo(n-2)\n\nWithout memoization, some values of the fibonacci sequence would be computed an exponential number of times. With the single line ``@memoify``, for a given ``n`` every computation after the first will be replaced with a lookup. Check out the difference between the above memoified version of fibo and the regular version of that same function::\n\n def regular_fibo(n):\n if n in [0, 1]:\n return n\n return regular_fibo(n-1) + regular_fibo(n-2)\n\nSee how the difference grows as ``n`` grows larger. (For me, for example, with ``n = 30``, the difference is already very noticable, and with ``n = 100``, ``regular_fibo`` takes forever while the memoized ``fibo`` is still instant.)\n\nHashability\n~~~~~~~~~~~\n\nFunction arguments are not *required* to be hashable, but they should be for best (fastest) results. If they are not, the memoizing version of the function could become slower than the original under special circumstances (depending on the runtime of the original function, and the number and nature of different arguments the memoizing version has been called with).\n\nConcurrency\n~~~~~~~~~~~\n\nMemoPy was not designed with concurrency in mind. So multiple runs of the same function in different threads at the same time is advised against as it has not been thoroughly thought through what would happen.\n\nDocumentation\n-------------\n\nThe tests found on Github at https://github.com/tscizzle/memopy/tree/master/tests give some examples and showcase the library's functionality.\n\nInstallation\n------------\n\nIf you don't have pip, get pip at: https://pip.pypa.io/en/stable/installing\n\nRun the command ``pip install memopy`` in your terminal to get the MemoPy library.\n\nTo test your installation, start a Python interpreter with the ``python`` command in your terminal and make sure you can run ``import memopy`` in it without getting an error.\n\nContribute\n----------\n\nFind the code on Github at: https://github.com/tscizzle/memopy\n\nSupport\n-------\n\nContact me (Tyler Singer-Clark) at tscizzle@gmail.com with any questions or concerns.\n\nLicense\n-------\n\nThe project is licensed under the MIT license.", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/tscizzle/memopy", "keywords": "cache memoization function", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "memopy", "package_url": "https://pypi.org/project/memopy/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/memopy/", "project_urls": { "Homepage": "https://github.com/tscizzle/memopy" }, "release_url": "https://pypi.org/project/memopy/0.0.1/", "requires_dist": null, "requires_python": "", "summary": "Memoize / cache function call results", "version": "0.0.1" }, "last_serial": 2561558, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "410b1abb616c3976ace0bd906b0f8e70", "sha256": "3a3787231e76591a0a4cda463054a8ccff1e6fbf815be8f984c6353840b833c0" }, "downloads": -1, "filename": "memopy-0.0.1-py2-none-any.whl", "has_sig": false, "md5_digest": "410b1abb616c3976ace0bd906b0f8e70", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 7537, "upload_time": "2017-01-09T04:00:06", "url": "https://files.pythonhosted.org/packages/f0/ca/fd60e91889ae9e30c8396ecf747b1724b157915869b399acfeef9fa1ec61/memopy-0.0.1-py2-none-any.whl" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "410b1abb616c3976ace0bd906b0f8e70", "sha256": "3a3787231e76591a0a4cda463054a8ccff1e6fbf815be8f984c6353840b833c0" }, "downloads": -1, "filename": "memopy-0.0.1-py2-none-any.whl", "has_sig": false, "md5_digest": "410b1abb616c3976ace0bd906b0f8e70", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 7537, "upload_time": "2017-01-09T04:00:06", "url": "https://files.pythonhosted.org/packages/f0/ca/fd60e91889ae9e30c8396ecf747b1724b157915869b399acfeef9fa1ec61/memopy-0.0.1-py2-none-any.whl" } ] }