{ "info": { "author": "Albert DeFusco", "author_email": "albert.defusco@me.com", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Framework :: Flask", "Intended Audience :: Developers", "Intended Audience :: Science/Research", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6" ], "description": "# Tranquilizer\n\nDeploy a REST API with one line by decorating your functions.\n\n## Install\n\nThe package is available for all Mac, Linux, and Windows on my conda channel. Python 2 is not supported.\n\n```\n> conda install -c conda-forge tranquilizer\n```\n\n## Quick start\n\nIn a script file called `cheese_shop.py` the decorated function\nwill be served as an end point called `cheese` with the GET method. The\nfunction must return a JSON serializable object. Dictionaries are preferable.\n\nSee the [complete description of `@tranquilize()`](#tranquilize-decorator) below.\n\n```python\nfrom tranquilizer import tranquilize\n\n@tranquilize()\ndef order(cheese):\n '''I'd like to buy some cheese!'''\n return {'response':\"I'm afraid we're fresh out of {}, Sir.\".format(cheese)}\n```\n\nThe REST API is served by [Flask](http://flask.pocoo.org/) and [Flask-RESTPlus](http://flask-restplus.readthedocs.io/en/stable/index.html)\nusing the `tranquilizer` command.\n\n\n```\n> tranquilizer cheese_shop.py\n * Serving Flask app \"tranquilizer.application\" (lazy loading)\n * Environment: production\n WARNING: Do not use the development server in a production environment.\n Use a production WSGI server instead.\n * Debug mode: off\n * Running on http://0.0.0.0:8086/ (Press CTRL+C to quit)\n\n```\n\nLet's see if there is any Red Leicester.\n\n```\n> curl -G http://localhost:8086/order --data-urlencode \"cheese=Red Leicester\"\n{\"response\":\"I'm afraid we're fresh out of Red Leicester, Sir.\"}\n```\n\nHow about in Python?\n\n```python\nIn [1]: import requests\n\nIn [2]: response = requests.get('http://localhost:8086/order', params={'cheese':'Red Leicester'})\n\nIn [3]: response.json()\nOut[3]: {'response': \"I'm afraid we're fresh out of Red Leicester, Sir.\"}\n```\n\nThe *tranquilized* API is documented with [Swagger](https://swagger.io/tools/open-source/) and is accessible\nin your web browser at [http://localhost:8086](http://localhost:8086).\n\n![](img/swagger.png)\n\n## Tranquilize Decorator\n\nThe `@tranqulize` decorator will assign the GET method by default. POST is also supported with `method='post'`.\nOther methods are under consideration.\n\nBy default a *tranquilized* function will receive all inputs as strings. This behavior can be modified by using [type hints](https://docs.python.org/3/library/typing.html). When data is received by the Flask server it will use the provided\ntype function to transform the string to the requested data type. This avoids having to perform the conversion in your *tranquilized* function.\n\n## Supported source formats\n\nTranquilizer can serve functions written in Python source (`.py`) files or Jupyter Notebooks (`.ipynb`).\n\nWhen working interactively in Jupyter Notebooks the decorated functions will continue to operate as normal.\nNote that all calls to [Jupyter Magic](https://ipython.readthedocs.io/en/stable/interactive/magics.html)\nand Shell (`!`) commands will be ignored when the REST API is served.\nOnly those lines will be ignored, the rest of the cell will continue to run.\n\n## Data Types\n\nIn addition to [*builtin* types](https://docs.python.org/3/library/stdtypes.html) Tranquilizer \nprovides specialized support for Lists, date/datetime, and files. \n\n\n|Type|Description|\n|----|-----------|\n|`datetime.date` or `datetime.datetime`| Converts string with `dateutil.parser.parse` and returns specified type.|\n|`list`| Converts *repeated* arguments to a list of strings.|\n|`typing.List[]`| Converts *repeated* arguments to a list; each value is converted to ``.|\n\n`List` arguments are constructed using the `action='append'` argument described in\nthe [Flask RESTPlus documentation](http://flask-restplus.readthedocs.io/en/stable/parsing.html#multiple-values-lists).\nAny valid type can be used in `List[]`.\n\nThe following file-like types are handled by [werkzeug `FileStorage`](http://werkzeug.pocoo.org/docs/0.14/datastructures/#werkzeug.datastructures.FileStorage).\n`FileStorage` is a file-like object that supports methods like `.read()` and `.readlines()`.\nThese types support sending files with cURL using `-F`.\n\n|Type|Description|\n|----|-----------|\n|`typing.BinaryIO`| File-like object to read binary data.|\n|`typing.TextIO`| Converts `FileStorage` type to `io.StringIO()`.|\n\nFurther, specific support for Image and NumPy files are provided. The binary contents of the file are automatically converted.\n\n|Type|Description|\n|----|-----------|\n|`PIL.Image.Image`| Converts `FileStorage` type to PIL Image.|\n|`numpy.ndarray`| Converts `FileStorage` type to NumPy array using `np.load()`. |\n\n### Custom types\n\nCustom type classes can be built...\n\n## Type hints example\n\nThe example below uses `int`, `datetime.datetime`, and `typing.List`. `datetime.datetime` support\nhas been built with `datetutil` and will convert any compatible datetime string to a `datetime.datetime` object. `typing.List`\nsupports specialization with `[]` and will transform all *repeated* arguments passed to the REST API into a list and convert\nthe type of each element.\n\nFinally, tranquilizer supports default arguments.\n\n```python\nfrom tranquilizer import tranquilize\nfrom datetime import date\nfrom typing import List\n\n@tranquilize(method='post')\ndef convert(string: str, date: date, items: List[float], factor: int = 10):\n '''Let's convert strings to something useful'''\n\n new_items = [i * factor for i in items]\n\n response = {\n 'string': string.upper(),\n 'date' : date.strftime('%c'),\n 'items' : new_items\n }\n\n return response\n```\n\nLet's see what happens when I POST to this REST API.\n\n```python\nIn [1]: data = {'string':'hello, world!', 'date':'4th July 1776', 'items':range(5)}\n\nIn [2]: import requests\n\nIn [3]: response = requests.post('http://localhost:8086/convert', data=data)\n\nIn [4]: response.json()\nOut[4]:\n{'date': 'Thu Jul 4 00:00:00 1776',\n 'items': [0.0, 10.0, 20.0, 30.0, 40.0],\n 'string': 'HELLO, WORLD!'}\n\nIn [5]:\n```", "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/AlbertDeFusco/tranquilizer", "keywords": "", "license": "BSD 3-clause", "maintainer": "", "maintainer_email": "", "name": "tranquilizer", "package_url": "https://pypi.org/project/tranquilizer/", "platform": "Windows", "project_url": "https://pypi.org/project/tranquilizer/", "project_urls": { "Homepage": "https://github.com/AlbertDeFusco/tranquilizer" }, "release_url": "https://pypi.org/project/tranquilizer/0.3.2/", "requires_dist": null, "requires_python": ">=3.5, <3.7", "summary": "Put your functions to REST", "version": "0.3.2" }, "last_serial": 5338757, "releases": { "0.0.4": [ { "comment_text": "", "digests": { "md5": "6f682eb7d68b29a2d3f5ff9047a804f2", "sha256": "7d46a6cb949839fc56dd2f275a5650a11a8e6f454eb7005dfe9379f8106b08d5" }, "downloads": -1, "filename": "tranquilizer-0.0.4-py3-none-any.whl", "has_sig": false, "md5_digest": "6f682eb7d68b29a2d3f5ff9047a804f2", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6844, "upload_time": "2018-08-05T13:49:45", "url": "https://files.pythonhosted.org/packages/4a/78/aa0b049e180eec83ce7f97d6eec8e275cfa1c0575651222320cb3b1fcb49/tranquilizer-0.0.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ab68f6a0ff4bfa46bedb1fb4bbb59d3c", "sha256": "fd3cddc6ef481c169916df31ab8412a186690aa223bd6eae86cbbfc66e49d357" }, "downloads": -1, "filename": "tranquilizer-0.0.4.tar.gz", "has_sig": false, "md5_digest": "ab68f6a0ff4bfa46bedb1fb4bbb59d3c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6649, "upload_time": "2018-08-05T13:49:46", "url": "https://files.pythonhosted.org/packages/5d/80/4353ef4661644624e352acc41b1a69aa4065c75f1771ab6787105b5f547f/tranquilizer-0.0.4.tar.gz" } ], "0.0.5": [ { "comment_text": "", "digests": { "md5": "23a61c8dcbe83f0190e976b80c362920", "sha256": "253a96ff1be964e82c73e1d2a45b10b8895601102119a3239f2c43801214ceea" }, "downloads": -1, "filename": "tranquilizer-0.0.5-py3-none-any.whl", "has_sig": false, "md5_digest": "23a61c8dcbe83f0190e976b80c362920", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 8977, "upload_time": "2018-08-05T13:54:22", "url": "https://files.pythonhosted.org/packages/07/a7/70577daa9513a7dfbd07481145c61b89480fc2505f3631f216b37e4969a4/tranquilizer-0.0.5-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "35190ddd2788ab6195712e9f32780515", "sha256": "7307cf5af783ff0fa4bcf41eef2cd9e6cc4a712c34e642eb541b53581e102e76" }, "downloads": -1, "filename": "tranquilizer-0.0.5.tar.gz", "has_sig": false, "md5_digest": "35190ddd2788ab6195712e9f32780515", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7172, "upload_time": "2018-08-05T13:54:24", "url": "https://files.pythonhosted.org/packages/de/48/991427222b9a574746e1a210631b14caa6de660b6f25d9e8635b8b8165a0/tranquilizer-0.0.5.tar.gz" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "a6ac22bee19bb4024539aea8c3a3020a", "sha256": "bd741a0c7e975bed9124860f0c9dd869272b69fbd00b061bea4b795e229c375b" }, "downloads": -1, "filename": "tranquilizer-0.1.0.tar.gz", "has_sig": false, "md5_digest": "a6ac22bee19bb4024539aea8c3a3020a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8183, "upload_time": "2018-09-27T16:47:24", "url": "https://files.pythonhosted.org/packages/55/52/f10894f02b74a6f9133234e179955847dd2b38e272c28fad1751786e061c/tranquilizer-0.1.0.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "78066a5495485b2b43f81f9ae80af7eb", "sha256": "8a818732e4b45ab66149ea55b05563f2f98e3ba0f95e346e07c39423f422133e" }, "downloads": -1, "filename": "tranquilizer-0.1.2.tar.gz", "has_sig": false, "md5_digest": "78066a5495485b2b43f81f9ae80af7eb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8399, "upload_time": "2018-12-29T22:55:01", "url": "https://files.pythonhosted.org/packages/2c/a1/b93d16c2f8d50d501ed07f0ea78b3da48ca63b1e7dde667aca001b9d72b2/tranquilizer-0.1.2.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "c366c64fe63b68b79f7d1ca91a6e217d", "sha256": "3b4351513012843177b34b669070f2063d80e6c51411e869b318b721fc24ffbf" }, "downloads": -1, "filename": "tranquilizer-0.2.0.tar.gz", "has_sig": false, "md5_digest": "c366c64fe63b68b79f7d1ca91a6e217d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8975, "upload_time": "2019-01-30T17:41:36", "url": "https://files.pythonhosted.org/packages/c8/85/8307763bd923efc8038b8fb39e7fbac47fdeb686bf56aada81cc9b814c0d/tranquilizer-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "f4f8827eff04e4afc8fe329aa8a8cfb5", "sha256": "c27b6bb28b25445efb2839b747a69be91a13a3f0ff3e8178fd48f22fe6f6cc7d" }, "downloads": -1, "filename": "tranquilizer-0.2.1.tar.gz", "has_sig": false, "md5_digest": "f4f8827eff04e4afc8fe329aa8a8cfb5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9103, "upload_time": "2019-03-06T20:58:46", "url": "https://files.pythonhosted.org/packages/9c/f3/13f6c6781f956efc6da3c902a72d68c983049f1273ed4a6157797351015a/tranquilizer-0.2.1.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "bbe49e44a81b49ff21dca24917dfb15c", "sha256": "6dbd5459d01012136fa75905592ba2725031034dbf916c54948cb524fcf16a18" }, "downloads": -1, "filename": "tranquilizer-0.3.0.tar.gz", "has_sig": false, "md5_digest": "bbe49e44a81b49ff21dca24917dfb15c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9285, "upload_time": "2019-03-06T21:52:38", "url": "https://files.pythonhosted.org/packages/6b/3c/beb27cb6093ecbe3ac66f737b4f814140c873405f3209217fa65bb7f53cb/tranquilizer-0.3.0.tar.gz" } ], "0.3.2": [ { "comment_text": "", "digests": { "md5": "d7816df99bb20fed84ed34edecf759f4", "sha256": "2d3f3f86ebf60e32842a33c8e3302f7cbf17d7311a8e0c44b021826cc3636dc1" }, "downloads": -1, "filename": "tranquilizer-0.3.2.tar.gz", "has_sig": false, "md5_digest": "d7816df99bb20fed84ed34edecf759f4", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5, <3.7", "size": 9729, "upload_time": "2019-05-30T17:59:47", "url": "https://files.pythonhosted.org/packages/f7/4a/fa5a7a4dd8f545d35576ad2608dc4559d037f24d2e45f7c06782273b2d0c/tranquilizer-0.3.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d7816df99bb20fed84ed34edecf759f4", "sha256": "2d3f3f86ebf60e32842a33c8e3302f7cbf17d7311a8e0c44b021826cc3636dc1" }, "downloads": -1, "filename": "tranquilizer-0.3.2.tar.gz", "has_sig": false, "md5_digest": "d7816df99bb20fed84ed34edecf759f4", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5, <3.7", "size": 9729, "upload_time": "2019-05-30T17:59:47", "url": "https://files.pythonhosted.org/packages/f7/4a/fa5a7a4dd8f545d35576ad2608dc4559d037f24d2e45f7c06782273b2d0c/tranquilizer-0.3.2.tar.gz" } ] }