{ "info": { "author": "Todd Wolfson", "author_email": "todd@twolfson.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Framework :: Flask", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python" ], "description": "flask-json-multidict\n====================\n\n.. image:: https://travis-ci.org/underdogio/flask-json-multidict.png?branch=master\n :target: https://travis-ci.org/underdogio/flask-json-multidict\n :alt: Build Status\n\nConvert Flask's `request.get_json`_ dict into a `MultiDict`_ like `request.form`_\n\nThis was written to maintain a consistent API for interacting with both ``request.form`` and ``request.get_json()``. This allows use to leverage ``.get`` with type coercion and ``.getlist``.\n\n.. _`request.get_json`: http://flask.pocoo.org/docs/0.10/api/#flask.Request.get_json\n.. _`MultiDict`: http://werkzeug.pocoo.org/docs/0.10/datastructures/#werkzeug.datastructures.MultiDict\n.. _`request.form`: http://flask.pocoo.org/docs/0.10/api/#flask.Request.form\n\nGetting Started\n---------------\nInstall the module with: ``pip install flask_json_multidict``\n\n.. code:: python\n\n # Load in our dependencies\n from flask import Flask, request, jsonify\n from flask_json_multidict import get_json_multidict\n\n # Start an application\n app = Flask(__name__)\n\n def resolve_request_body():\n \"\"\"Before every request, resolve `request.body` from either `request.form` or `request.get_json()`\"\"\"\n request.body = request.form\n if request.headers['content-type'] == 'application/json':\n request.body = get_json_multidict(request)\n app.before_request(resolve_request_body)\n\n @app.route('/', methods=['POST'])\n def root():\n \"\"\"Reply with POST data as we see it\"\"\"\n body = request.body\n return jsonify({key: body[key] for key in body})\n # We can also leverage `request.body.getlist` as we do with `request.form`\n\n\n if __name__ == '__main__':\n app.run()\n\n # $ curl http://localhost:5000/ -X POST --data 'hello=world'\n # {\"hello\": \"world\"}\n # $ curl http://localhost:5000/ -X POST -H 'Content-Type: application/json' --data '{\"hello\": \"world\"}\n # {\"hello\": \"world\"}\n\nDocumentation\n-------------\n``flask-json-multidict`` can be imported via ``flask_json_multidict``.\n\nflask_json_multidict.get_json_multidict(request)\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n``get_json_multidict`` walks over the ``json`` provided by ``request.get_json()`` and returns a `MultiDict`_.\n\n- request ``object`` - Current ``request`` being handled by Flask\n\n**Returns:**\n\n- body ``object`` - MultiDict with ``json`` information\n - If there were any dictionaries or nested lists, then these will be ignored as parameters\n - This is for consistency with how ``request.form`` behaves\n\n.. code:: python\n\n # Assume we receive `{\"colors\": [\"red\", \"blue\"]}`\n body = get_json_multidict(request)\n body.getlist('colors') # ['red', 'blue']\n\n # Assume we receive `{\"hello\": \"world\"}`\n body = get_json_multidict(request)\n body.['hello'] # 'world'\n body.get('hello') # 'world'\n\n # Assume we receive `{\"foo\": {\"bar\": \"baz\"}}`\n # This is the silent ignore of bad parameters\n body = get_json_multidict(request)\n body.get('foo') # None\n\nContributing\n------------\nIn lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Test via ``nosetests``.\n\nLicense\n-------\nCopyright (c) 2015 Underdog.io\n\nLicensed under the MIT license.", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/underdogio/flask-json-multidict/archive/master.zip", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/underdogio/flask-json-multidict", "keywords": "flask,request,json,multidict,form", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "flask_json_multidict", "package_url": "https://pypi.org/project/flask_json_multidict/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/flask_json_multidict/", "project_urls": { "Download": "https://github.com/underdogio/flask-json-multidict/archive/master.zip", "Homepage": "https://github.com/underdogio/flask-json-multidict" }, "release_url": "https://pypi.org/project/flask_json_multidict/1.0.0/", "requires_dist": null, "requires_python": null, "summary": "Convert Flask's `request.get_json` dict into a MultiDict like `request.form`", "version": "1.0.0" }, "last_serial": 1448088, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "7d7eece96d522ad7847113d9bf5b25fc", "sha256": "26234ff1dd6020b0c2d671b85b2bd3887724be6e18aa36957ede332f9f6ef6b7" }, "downloads": -1, "filename": "flask_json_multidict-1.0.0.tar.gz", "has_sig": false, "md5_digest": "7d7eece96d522ad7847113d9bf5b25fc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10955, "upload_time": "2015-03-04T18:03:08", "url": "https://files.pythonhosted.org/packages/47/d4/ee55bc2e7e1608c563b2dc61bb45c4807c5dfc826a777b4a9085b0f3533f/flask_json_multidict-1.0.0.tar.gz" }, { "comment_text": "", "digests": { "md5": "1235a4c1ec9b1df3754c40e1bc8eb8e1", "sha256": "c45c25d1c2a439999626c645daa8dfc251de4a1e0718de3eb118b57ca9125495" }, "downloads": -1, "filename": "flask_json_multidict-1.0.0.zip", "has_sig": false, "md5_digest": "1235a4c1ec9b1df3754c40e1bc8eb8e1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23969, "upload_time": "2015-03-04T18:03:11", "url": "https://files.pythonhosted.org/packages/f2/14/f301f084d3ad70b995a7fe62e1aa3caacc460e4b810ff0e8d6868805318b/flask_json_multidict-1.0.0.zip" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "7d7eece96d522ad7847113d9bf5b25fc", "sha256": "26234ff1dd6020b0c2d671b85b2bd3887724be6e18aa36957ede332f9f6ef6b7" }, "downloads": -1, "filename": "flask_json_multidict-1.0.0.tar.gz", "has_sig": false, "md5_digest": "7d7eece96d522ad7847113d9bf5b25fc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10955, "upload_time": "2015-03-04T18:03:08", "url": "https://files.pythonhosted.org/packages/47/d4/ee55bc2e7e1608c563b2dc61bb45c4807c5dfc826a777b4a9085b0f3533f/flask_json_multidict-1.0.0.tar.gz" }, { "comment_text": "", "digests": { "md5": "1235a4c1ec9b1df3754c40e1bc8eb8e1", "sha256": "c45c25d1c2a439999626c645daa8dfc251de4a1e0718de3eb118b57ca9125495" }, "downloads": -1, "filename": "flask_json_multidict-1.0.0.zip", "has_sig": false, "md5_digest": "1235a4c1ec9b1df3754c40e1bc8eb8e1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23969, "upload_time": "2015-03-04T18:03:11", "url": "https://files.pythonhosted.org/packages/f2/14/f301f084d3ad70b995a7fe62e1aa3caacc460e4b810ff0e8d6868805318b/flask_json_multidict-1.0.0.zip" } ] }