{ "info": { "author": "", "author_email": "", "bugtrack_url": null, "classifiers": [], "description": "funcportal\n==========\n\n.. image:: https://travis-ci.org/acroz/funcportal.svg?branch=master\n :target: https://travis-ci.org/acroz/funcportal\n\n.. image:: https://badge.fury.io/py/funcportal.svg\n :target: https://pypi.org/project/funcportal/\n\n*funcportal* runs your Python functions as a web API, with no code changes\nrequired.\n\nUsage\n-----\n\nGiven a Python module like ``code.py`` below:\n\n.. code-block:: python\n\n # code.py\n def hello(name):\n return f'Hello, {name}!'\n\nYou can serve the function ``hello()`` as a web API with *funcportal* on the\ncommand line:\n\n.. code-block:: bash\n\n $ funcportal server code:hello\n\nand you can then make HTTP POST requests to it, for example with the Python\n*requests* library:\n\n.. code-block:: python\n\n >>> import requests\n >>> response = requests.post(\n >>> 'http://localhost:5000/hello',\n >>> json={'name': 'Jane'}\n >>> )\n >>> print(response.status_code)\n 200\n >>> print(response.json())\n {'result': 'Hello, Jane!'}\n\nAlternatively, use a configuration file to specify the functions to serve and\ntheir endpoints. The configuration file is YAML formatted:\n\n.. code-block:: yaml\n\n routes:\n - module: code\n function: hello\n endpoint: /hello\n - module: code\n function: other\n endpoint: /other\n\nAs with the command line interface, the module and function indicate the code\nto be run, and the endpoint is the address on the server that the API will be\nrun.\n\nLoad endpoints from the configuration file with the ``-c``/``--config`` command\nline option:\n\n.. code-block:: bash\n\n $ funcportal server -c config.yaml\n\nAsynchronous execution\n----------------------\n\nWhen executing longer running function calls, you won't want to hold open the\nHTTP connection for a long time, as it increases the risk of failure (as well\nas making management of server resources more difficult). To avoid this, use\n*funcportal*'s asynchronous execution feature. To enable asynchronous\nexecution, set the ``async`` flag to true for a route in the configuration\nfile:\n\n.. code-block:: yaml\n\n routes:\n - module: code\n function: slow\n endpoint: /slow\n async: true\n\n**Important:** To execute functions asynchonously, you need to have redis\nserver installed and running, and then also run one or more *funcportal* worker\nprocesses separately from the server process(es):\n\n.. code-block:: bash\n\n $ funcportal worker\n\nThen, when you call this endpoint, instead of waiting until the function has\nfinished running and returning the result (if any), a response will be returned\nimmediately with a token that can be redeemed later for the result:\n\n.. code-block:: python\n\n >>> response = requests.post(\n >>> 'http://localhost:5000/slow',\n >>> json={'input': 4}\n >>> )\n >>> print(response.status_code)\n 202\n >>> print(response.json())\n {'result_token': '3bf409d0-4b91-4e75-87e4-c377f2f9dbf6'}\n\nYou can then poll the original endpoint plus the result token with an HTTP GET\nto retrieve the result when ready. Before the result is ready, a 404 NOT FOUND\nstatus is returned:\n\n.. code-block:: python\n\n >>> response = requests.get(\n >>> 'http://localhost:5000/slow/3bf409d0-4b91-4e75-87e4-c377f2f9dbf6'\n >>> )\n >>> print(response.status_code)\n 404\n >>> print(response.json())\n {'error': 'Job result not available.'}\n\nOnce the job is finished, a 200 OK status is returned along with the result:\n\n.. code-block:: python\n\n >>> response = requests.get(\n >>> 'http://localhost:5000/slow/3bf409d0-4b91-4e75-87e4-c377f2f9dbf6'\n >>> )\n >>> print(response.status_code)\n 200\n >>> print(response.json())\n {'result': 79}\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "funcportal", "package_url": "https://pypi.org/project/funcportal/", "platform": "", "project_url": "https://pypi.org/project/funcportal/", "project_urls": null, "release_url": "https://pypi.org/project/funcportal/0.2.0/", "requires_dist": [ "flask", "requests", "six", "pyyaml", "rq", "redis" ], "requires_python": "", "summary": "Serve Python functions as web APIs", "version": "0.2.0" }, "last_serial": 3770771, "releases": { "0.0.0": [ { "comment_text": "", "digests": { "md5": "2699cc9dd522a1f5364264549e44dd52", "sha256": "2c8e6f2ffa369e379b5b10b661111775a66eb4b6594e96d1b80bffd1a429c91d" }, "downloads": -1, "filename": "funcportal-0.0.0.tar.gz", "has_sig": false, "md5_digest": "2699cc9dd522a1f5364264549e44dd52", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 604, "upload_time": "2018-04-03T23:15:24", "url": "https://files.pythonhosted.org/packages/f5/08/d7e3c56b4e1bc756fc1696343f99752975f95228cab2c1e50692ce9178a5/funcportal-0.0.0.tar.gz" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "fbce0a4a88a59e81267553e2e9884ea1", "sha256": "1f4ff84a77f82c54cb99c3e6bcd6cf94f015f7f25df673a696c0a51539abab92" }, "downloads": -1, "filename": "funcportal-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "fbce0a4a88a59e81267553e2e9884ea1", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5980, "upload_time": "2018-04-13T15:26:57", "url": "https://files.pythonhosted.org/packages/af/ff/0e619199a74b8086d696dfa579ab4575de3f76298a0d9c2eb034481ded64/funcportal-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "08beffba32fe7f038a3b439f5f112e11", "sha256": "39355be9fc67dbe0e0ce8f8cc80e1ca9b3f9d2d2296ef9e3d38d66be743affe1" }, "downloads": -1, "filename": "funcportal-0.1.0.tar.gz", "has_sig": false, "md5_digest": "08beffba32fe7f038a3b439f5f112e11", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4946, "upload_time": "2018-04-13T15:26:58", "url": "https://files.pythonhosted.org/packages/03/a7/b31dd5f34154a181afac672128a9388dd6b108065ed4ff23423b322d11de/funcportal-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "3729745236dc35c79895a63297f790ed", "sha256": "a2c5ca83081659fdd1eb2cd80a7c5fd33248558108051b052cd81c5f19cebf27" }, "downloads": -1, "filename": "funcportal-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "3729745236dc35c79895a63297f790ed", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6055, "upload_time": "2018-04-15T18:42:50", "url": "https://files.pythonhosted.org/packages/5c/83/2dab395687e5ae727233f0406b3255717310864dad6f8c71fb3ff0ea9b31/funcportal-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7d5fb37ed9a3120d7dd938ce2efd5a2a", "sha256": "f8ae4453406e4c62367ff034901be8aaf7f6063724e01ef02d5edd61d35a0949" }, "downloads": -1, "filename": "funcportal-0.1.1.tar.gz", "has_sig": false, "md5_digest": "7d5fb37ed9a3120d7dd938ce2efd5a2a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5106, "upload_time": "2018-04-15T18:42:50", "url": "https://files.pythonhosted.org/packages/f5/ee/e5e71fd583c4ced86214ffa5c09a0ecd351eab98d56118a194edc5e82f0c/funcportal-0.1.1.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "8a100b3016c615541a58d41c56db51e7", "sha256": "b5e475a8436a01565178707753690704a450b4f9ade68b6e39e7dd90b69c502d" }, "downloads": -1, "filename": "funcportal-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "8a100b3016c615541a58d41c56db51e7", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7705, "upload_time": "2018-04-16T21:55:30", "url": "https://files.pythonhosted.org/packages/75/b0/2e6160197585a7aa18ac52d842be526437141d1b165f8d25776e09daec7f/funcportal-0.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a7289a734a33028cfd0793a0cf1aa45f", "sha256": "a56f5df9e60188af7edc274befa65c58a6f01ba70ebb507dbc4181370bfeda5d" }, "downloads": -1, "filename": "funcportal-0.2.0.tar.gz", "has_sig": false, "md5_digest": "a7289a734a33028cfd0793a0cf1aa45f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7052, "upload_time": "2018-04-16T21:55:31", "url": "https://files.pythonhosted.org/packages/2d/2d/12d6e29ebfcf3898c116e4f0892bff99cbf49553f7f0dcc5015e7fdacf29/funcportal-0.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8a100b3016c615541a58d41c56db51e7", "sha256": "b5e475a8436a01565178707753690704a450b4f9ade68b6e39e7dd90b69c502d" }, "downloads": -1, "filename": "funcportal-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "8a100b3016c615541a58d41c56db51e7", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7705, "upload_time": "2018-04-16T21:55:30", "url": "https://files.pythonhosted.org/packages/75/b0/2e6160197585a7aa18ac52d842be526437141d1b165f8d25776e09daec7f/funcportal-0.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a7289a734a33028cfd0793a0cf1aa45f", "sha256": "a56f5df9e60188af7edc274befa65c58a6f01ba70ebb507dbc4181370bfeda5d" }, "downloads": -1, "filename": "funcportal-0.2.0.tar.gz", "has_sig": false, "md5_digest": "a7289a734a33028cfd0793a0cf1aa45f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7052, "upload_time": "2018-04-16T21:55:31", "url": "https://files.pythonhosted.org/packages/2d/2d/12d6e29ebfcf3898c116e4f0892bff99cbf49553f7f0dcc5015e7fdacf29/funcportal-0.2.0.tar.gz" } ] }