首页 > 解决方案 > 如何添加 API 在 JSON 响应中响应所需的执行时间 - 带有烧瓶的 Python

问题描述

如何添加 API 响应 JSON 响应所需的执行时间

I would like to add the time taken by the API to respond in the response JSON. Currently calling an API using python with flask

If anyone can guide with best approach.

Note:I have updated the question

标签: pythonflask

解决方案


如果您正在使用该requests库,则该Response对象将返回一个elapsed属性。此属性为您提供请求和响应之间的时间增量。例如:

res = requests.get(url)
print(res.elapsed)

推荐阅读