{
"info": {
"author": "Marsel Mavletkulov",
"author_email": "marselester@ya.ru",
"bugtrack_url": null,
"classifiers": [
"Environment :: Web Environment",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
"Topic :: Software Development :: Libraries :: Python Modules"
],
"description": "===============\nFlask-API-Utils\n===============\n\n.. image:: https://travis-ci.org/marselester/flask-api-utils.png\n :target: https://travis-ci.org/marselester/flask-api-utils\n\nFlask-API-Utils helps you to create APIs. It makes responses in appropriate\nformats, for instance, JSON. All you need to do is to return dictionary\nfrom your views. Another useful feature is an authentication.\nThe library supports Hawk_ HTTP authentication scheme and `Flask-Login`_\nextension. To sum up, there is an `API example project`_.\n\n\"Accept\" Header based Response\n------------------------------\n\n**ResponsiveFlask** tends to make responses based on **Accept**\nrequest-header (RFC 2616). If a view function does not return a dictionary,\nthen response will be processed as usual. Here is an example.\n\n.. code-block:: python\n\n from api_utils import ResponsiveFlask\n\n app = ResponsiveFlask(__name__)\n\n\n @app.route('/')\n def hello_world():\n return {'hello': 'world'}\n\n\n def dummy_xml_formatter(*args, **kwargs):\n return 'world'\n\n xml_mimetype = 'application/vnd.company+xml'\n app.response_formatters[xml_mimetype] = dummy_xml_formatter\n\n if __name__ == '__main__':\n app.run()\n\n\nIt's assumed that file was saved as ``api.py``:\n\n.. code-block:: console\n\n $ python api.py\n * Running on http://127.0.0.1:5000/\n\nHere are curl examples with different **Accept** headers:\n\n.. code-block:: console\n\n $ curl http://127.0.0.1:5000/ -i\n HTTP/1.0 200 OK\n Content-Type: application/json\n Content-Length: 22\n Server: Werkzeug/0.9.4 Python/2.7.5\n Date: Sat, 07 Dec 2013 14:01:14 GMT\n\n {\n \"hello\": \"world\"\n }\n $ curl http://127.0.0.1:5000/ -H 'Accept: application/vnd.company+xml' -i\n HTTP/1.0 200 OK\n Content-Type: application/vnd.company+xml; charset=utf-8\n Content-Length: 20\n Server: Werkzeug/0.9.4 Python/2.7.5\n Date: Sat, 07 Dec 2013 14:01:50 GMT\n\n world\n $ curl http://127.0.0.1:5000/ -H 'Accept: blah/*' -i\n HTTP/1.0 406 NOT ACCEPTABLE\n Content-Type: application/json\n Content-Length: 83\n Server: Werkzeug/0.9.4 Python/2.7.5\n Date: Sat, 07 Dec 2013 14:02:23 GMT\n\n {\n \"mimetypes\": [\n \"application/json\",\n \"application/vnd.company+xml\"\n ]\n }\n\nHTTP Error Handling\n-------------------\n\nYou can set HTTP error handler by using **@app.default_errorhandler**\ndecorator. Note that it might override already defined error handlers,\nso you should declare it before them.\n\n.. code-block:: python\n\n from flask import request\n from api_utils import ResponsiveFlask\n\n app = ResponsiveFlask(__name__)\n\n\n @app.default_errorhandler\n def werkzeug_default_exceptions_handler(error):\n error_info_url = (\n 'http://developer.example.com/errors.html#error-code-{}'\n ).format(error.code)\n\n response = {\n 'code': error.code,\n 'message': str(error),\n 'info_url': error_info_url,\n }\n return response, error.code\n\n\n @app.errorhandler(404)\n def page_not_found(error):\n return {'error': 'This page does not exist'}, 404\n\n\n class MyException(Exception):\n pass\n\n\n @app.errorhandler(MyException)\n def special_exception_handler(error):\n return {'error': str(error)}\n\n\n @app.route('/my-exc')\n def hello_my_exception():\n raise MyException('Krivens!')\n\n\n @app.route('/yarr')\n def hello_bad_request():\n request.args['bad-key']\n\n if __name__ == '__main__':\n app.run()\n\n\nLet's try to curl this example. First response shows that we redefined\ndefault ``{'code': 400, 'message': '400: Bad Request'}`` error format.\nNext ones show that you can handle specific errors as usual.\n\n.. code-block:: console\n\n $ curl http://127.0.0.1:5000/yarr -i\n HTTP/1.0 400 BAD REQUEST\n Content-Type: application/json\n Content-Length: 125\n Server: Werkzeug/0.9.4 Python/2.7.5\n Date: Sun, 29 Dec 2013 14:26:30 GMT\n\n {\n \"code\": 400,\n \"info_url\": \"http://developer.example.com/errors.html#error-code-400\",\n \"message\": \"400: Bad Request\"\n }\n $ curl http://127.0.0.1:5000/ -i\n HTTP/1.0 404 NOT FOUND\n Content-Type: application/json\n Content-Length: 41\n Server: Werkzeug/0.9.4 Python/2.7.5\n Date: Sun, 29 Dec 2013 14:28:46 GMT\n\n {\n \"error\": \"This page does not exist\"\n }\n $ curl http://127.0.0.1:5000/my-exc -i\n HTTP/1.0 200 OK\n Content-Type: application/json\n Content-Length: 25\n Server: Werkzeug/0.9.4 Python/2.7.5\n Date: Sun, 29 Dec 2013 14:27:33 GMT\n\n {\n \"error\": \"Krivens!\"\n }\n\nAuthentication\n--------------\n\n**Hawk** extension provides API authentication for Flask.\n\nHawk_ is an HTTP authentication scheme using a message authentication code\n(MAC) algorithm to provide partial HTTP request cryptographic verification.\n\nThe extension is based on Mohawk_, so make sure you have installed it.\n\n.. code-block:: console\n\n $ pip install mohawk\n\nUsage example:\n\n.. code-block:: python\n\n from flask import Flask\n from api_utils import Hawk\n\n app = Flask(__name__)\n hawk = Hawk(app)\n\n\n @hawk.client_key_loader\n def get_client_key(client_id):\n # In a real project you will likely use some storage.\n if client_id == 'Alice':\n return 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn'\n else:\n raise LookupError()\n\n\n @app.route('/')\n @hawk.auth_required\n def index():\n return 'hello world'\n\n if __name__ == '__main__':\n app.run()\n\n.. code-block:: console\n\n $ curl http://127.0.0.1:5000/ -i\n HTTP/1.0 401 UNAUTHORIZED\n ...\n\nCookie based authentication is disabled by default.\nSet ``HAWK_ALLOW_COOKIE_AUTH = True`` to enable it. Also **Hawk** supports\nresponse signing, enable it ``HAWK_SIGN_RESPONSE = True`` if you need it.\n\nFollowing configuration keys are used by Mohawk_ library.\n\n.. code-block:: python\n\n HAWK_ALGORITHM = 'sha256'\n HAWK_ACCEPT_UNTRUSTED_CONTENT = False\n HAWK_LOCALTIME_OFFSET_IN_SECONDS = 0\n HAWK_TIMESTAMP_SKEW_IN_SECONDS = 60\n\nCheck `Mohawk documentation`_ for more information.\n\nIt can be convenient to globally turn off authentication when unit testing\nby setting ``HAWK_ENABLED = False``.\n\nTests\n-----\n\nTests are run by:\n\n.. code-block:: console\n\n $ pip install -r requirements.txt\n $ tox\n\n.. _API example project: https://github.com/marselester/api-example-based-on-flask\n.. _Hawk: https://github.com/hueniverse/hawk\n.. _Mohawk: https://github.com/kumar303/mohawk\n.. _Mohawk documentation: http://mohawk.readthedocs.org\n.. _Flask-Login: https://flask-login.readthedocs.org",
"description_content_type": null,
"docs_url": null,
"download_url": "UNKNOWN",
"downloads": {
"last_day": -1,
"last_month": -1,
"last_week": -1
},
"home_page": "https://github.com/marselester/flask-api-utils",
"keywords": null,
"license": "UNKNOWN",
"maintainer": null,
"maintainer_email": null,
"name": "Flask-API-Utils",
"package_url": "https://pypi.org/project/Flask-API-Utils/",
"platform": "UNKNOWN",
"project_url": "https://pypi.org/project/Flask-API-Utils/",
"project_urls": {
"Download": "UNKNOWN",
"Homepage": "https://github.com/marselester/flask-api-utils"
},
"release_url": "https://pypi.org/project/Flask-API-Utils/1.0.2/",
"requires_dist": null,
"requires_python": null,
"summary": "Flask-API-Utils helps you to create APIs.",
"version": "1.0.2"
},
"last_serial": 1769744,
"releases": {
"0.1.0": [
{
"comment_text": "",
"digests": {
"md5": "0de9485c295fa69ddae516c771da1946",
"sha256": "921dd9f32aef8e0c9b8ff6ef92caf7cdadd110539ba36839a90a3e27ecaa1d50"
},
"downloads": -1,
"filename": "Flask-API-Utils-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "0de9485c295fa69ddae516c771da1946",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3064,
"upload_time": "2013-12-10T13:22:06",
"url": "https://files.pythonhosted.org/packages/b8/97/7fdfa84b01cbc520441d689702c0f540b654d4c0d2aac10c939c68845e5a/Flask-API-Utils-0.1.0.tar.gz"
}
],
"0.2.0": [
{
"comment_text": "",
"digests": {
"md5": "166a2406b0d4fd9166a00ce27a380aaa",
"sha256": "68c60a79f6544c8382d149b7738c93a118718e8416ba6c8dc1a91c9528f11c18"
},
"downloads": -1,
"filename": "Flask-API-Utils-0.2.0.tar.gz",
"has_sig": false,
"md5_digest": "166a2406b0d4fd9166a00ce27a380aaa",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3987,
"upload_time": "2013-12-31T08:43:34",
"url": "https://files.pythonhosted.org/packages/f1/b6/aeba2cfbc434c96f8aba8fb261e75c54ecd3821ff081fa7d34dd2c445b5e/Flask-API-Utils-0.2.0.tar.gz"
}
],
"1.0.0": [
{
"comment_text": "",
"digests": {
"md5": "e80e1cc7f4be4975f7132a1663140cb9",
"sha256": "1fafce0ee8b74e188253ed4d3d7b1fbd81600e6c5d17ffa438c323fbedf9a4fb"
},
"downloads": -1,
"filename": "Flask-API-Utils-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "e80e1cc7f4be4975f7132a1663140cb9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 6026,
"upload_time": "2014-06-21T13:33:43",
"url": "https://files.pythonhosted.org/packages/e6/15/bb387d1c571fa692cae6d864550c910a19c5b65c64aff3edb3373858aaff/Flask-API-Utils-1.0.0.tar.gz"
}
],
"1.0.1": [
{
"comment_text": "",
"digests": {
"md5": "47c6941d04e8b75e76889f32e55d42f1",
"sha256": "51d9654e914942cb0d7ca0aab71f2a2bad3cca597411869353fcfe39e28e94b6"
},
"downloads": -1,
"filename": "Flask-API-Utils-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "47c6941d04e8b75e76889f32e55d42f1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 6197,
"upload_time": "2015-10-15T02:44:25",
"url": "https://files.pythonhosted.org/packages/06/ae/25d102b3a84a324ba707e7dabc01517acfa92236163592f4d9098d2ac006/Flask-API-Utils-1.0.1.tar.gz"
}
],
"1.0.2": [
{
"comment_text": "",
"digests": {
"md5": "9d58b8fd15eadb1f625139487e17111c",
"sha256": "c108000b91b6ebdf6cd2ff8e57af091edb12feb80e97484619311783d073437d"
},
"downloads": -1,
"filename": "Flask-API-Utils-1.0.2.tar.gz",
"has_sig": false,
"md5_digest": "9d58b8fd15eadb1f625139487e17111c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 6311,
"upload_time": "2015-10-15T08:31:55",
"url": "https://files.pythonhosted.org/packages/88/7a/ea0575cd9f410f3bebed0d18ee06a72d488db99260a5331a641dbbcfb218/Flask-API-Utils-1.0.2.tar.gz"
}
]
},
"urls": [
{
"comment_text": "",
"digests": {
"md5": "9d58b8fd15eadb1f625139487e17111c",
"sha256": "c108000b91b6ebdf6cd2ff8e57af091edb12feb80e97484619311783d073437d"
},
"downloads": -1,
"filename": "Flask-API-Utils-1.0.2.tar.gz",
"has_sig": false,
"md5_digest": "9d58b8fd15eadb1f625139487e17111c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 6311,
"upload_time": "2015-10-15T08:31:55",
"url": "https://files.pythonhosted.org/packages/88/7a/ea0575cd9f410f3bebed0d18ee06a72d488db99260a5331a641dbbcfb218/Flask-API-Utils-1.0.2.tar.gz"
}
]
}