I am writing an API in a flask that returns json. Each bulb function has the form
from flask import jsonify @app.route('/getdata') def get_data(): data = load_data_as_dict() return jsonify(data)
If I return a large amount of data, calling this function will take about 1.7 seconds. However, if I do this:
from flask import Response @app.route('/getdata') def get_data(): data = load_data_as_dict() data_as_str = json.dumps(data) return Response(response=data_as_str, status=200, mimetype="application/json"
... the function completes in about 0.5 seconds.
Can someone tell me why jsonify so much slower? Is there anything wrong with returning the original response to the flask instead?
Thanks!
performance json python api flask
chris_dev
source share