{ "info": { "author": "Will Sijp", "author_email": "wim.sijp@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# functionfaker\nLightweight [Decorator to cache (memoize) function calls](https://github.com/wsijp/functionfaker) and replay responses for expensive computations and API requests.\n\n[Pip installable](https://pypi.org/project/functionfaker/) via `pip install functionfaker` \n\nFunctionfaker offers lightweight and easy to understand function (and method) caching, similar to some of the functionality of the [Joblib](https://joblib.readthedocs.io/en/latest/) package. A function response is recorded once and then replayed from cache from thereon. This allows for unit testing applications with API calls without actaully calling the API. It can also speed up prototyping of computationally expensive code. Functionfaker consists of simple code, and provides a single decorator for your functions and methods, as shown in the following \"hello world\" example.\n\n```\nfrom functionfaker import response_player\nimport os\n```\nAdd the `response_player` decorator to an example function called `add`:\n\n```\n@response_player()\ndef add(x, y):\n return x + y\n```\n\nThen set RECORD mode by setting the environment variable:\n\n```\n# enter record mode, to record function responses.\nos.environ['RECORD'] = \"record\"\n```\n\nCall the `add` function a few times:\n\n```\n# Clear the stored function responses\nif os.path.exists('responses.p'):\n os.remove('responses.p')\n# call the add function to record some responses.\nadd(1,2)\nadd(1,y=3)\nadd(1,3)\nadd(2,1)\n```\n```Recording response function \"add\"\nRecording response function \"add\"\nRecording response function \"add\"\nRecording response function \"add\"\n```\nSet `replay` mode via the environment variable:\n\n```\n# enter replay mode, so that function will not run, but return stored values instead.\nos.environ['RECORD'] = \"replay\"\n```\n\nCall the `add` function again, with arguments that it has already seen:\n\n```\nresult = add(1,2)\nprint(\"The saved result of adding 1 and 2 using function 'add' is %d\"%result)\n```\n```\nFaking function \"add\". Response found\nThe saved result of adding 1 and 2 using function 'add' is 3\n```\n\nThe outputs for these inputs (1,2) are now read from cache.\n\nSome funtion arguments might be irrelevant or difficult to serialize. To ignore these arguments, provide the `args2ignore` argument as a list of integers to the `response_player` decorator, where the integers represent the index in the argument list.\n\nDefault function response storage is in a simple Pickle file `responses.p`. To use your own storage system, provide a class derived from `BaseStore` class with an `update` and `get_response` method. An object of this class is then provided as the `store` argument to the `response_player` decorator.", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/wsijp/functionfaker", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "functionfaker", "package_url": "https://pypi.org/project/functionfaker/", "platform": "", "project_url": "https://pypi.org/project/functionfaker/", "project_urls": { "Homepage": "https://github.com/wsijp/functionfaker" }, "release_url": "https://pypi.org/project/functionfaker/0.2/", "requires_dist": null, "requires_python": "", "summary": "Function Faker", "version": "0.2" }, "last_serial": 5399010, "releases": { "0.1.3": [ { "comment_text": "", "digests": { "md5": "0649ee20542eeb390719ddf102dee2f2", "sha256": "a5bb47acc69140c13d6352bf214d1a646b17198bb918f319ce4846a3723d5686" }, "downloads": -1, "filename": "functionfaker-0.1.3.tar.gz", "has_sig": false, "md5_digest": "0649ee20542eeb390719ddf102dee2f2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3382, "upload_time": "2019-06-12T07:27:13", "url": "https://files.pythonhosted.org/packages/29/b2/59d610055c7926e731609d78c1a2237dc5d598f88ddae146da552b6bfd17/functionfaker-0.1.3.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "f54f877f2869dbf31da368e41efa3c05", "sha256": "8c7ee43c9a6a41b06b62582667bd57ce50f34da02475cc0e8a26c4225aa05c0b" }, "downloads": -1, "filename": "functionfaker-0.1.4.tar.gz", "has_sig": false, "md5_digest": "f54f877f2869dbf31da368e41efa3c05", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3377, "upload_time": "2019-06-13T06:11:01", "url": "https://files.pythonhosted.org/packages/60/52/82e2dd001283301c7601407e4c7c826ad88329a1e064a08c43c036ea935c/functionfaker-0.1.4.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "9e3332e27d207e4fce0ae20f6d8267e0", "sha256": "c9af20400c61403cbd975e57fda4be9c5b10c906cecf81f75a8f6dca97b6133e" }, "downloads": -1, "filename": "functionfaker-0.2.tar.gz", "has_sig": false, "md5_digest": "9e3332e27d207e4fce0ae20f6d8267e0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4351, "upload_time": "2019-06-14T05:45:40", "url": "https://files.pythonhosted.org/packages/f8/77/b7d3c2ba3b0cb486ef631aa3be3f6a5097f1c605c4948c2e331bc5147c02/functionfaker-0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "9e3332e27d207e4fce0ae20f6d8267e0", "sha256": "c9af20400c61403cbd975e57fda4be9c5b10c906cecf81f75a8f6dca97b6133e" }, "downloads": -1, "filename": "functionfaker-0.2.tar.gz", "has_sig": false, "md5_digest": "9e3332e27d207e4fce0ae20f6d8267e0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4351, "upload_time": "2019-06-14T05:45:40", "url": "https://files.pythonhosted.org/packages/f8/77/b7d3c2ba3b0cb486ef631aa3be3f6a5097f1c605c4948c2e331bc5147c02/functionfaker-0.2.tar.gz" } ] }