fastapi

Python FastAPI Async Variable Sharing

一笑奈何 提交于 2021-02-07 10:09:58
问题 If I had the below code, how would the variable service affect the asynchronous nature of the endpoints? Will the variable be shared? Or will it be locked when in use, thus blocking other endpoints from accessing it until the current one is done? I ask the above assuming that Service instances are stateless, i.e. it would be equivalent if I created an instance of Service in each endpoint. I am reluctant to do that because I don't know which is more time consuming, instantiating and destroying

Python FastAPI Async Variable Sharing

对着背影说爱祢 提交于 2021-02-07 10:09:35
问题 If I had the below code, how would the variable service affect the asynchronous nature of the endpoints? Will the variable be shared? Or will it be locked when in use, thus blocking other endpoints from accessing it until the current one is done? I ask the above assuming that Service instances are stateless, i.e. it would be equivalent if I created an instance of Service in each endpoint. I am reluctant to do that because I don't know which is more time consuming, instantiating and destroying

Python FastAPI Async Variable Sharing

China☆狼群 提交于 2021-02-07 10:09:09
问题 If I had the below code, how would the variable service affect the asynchronous nature of the endpoints? Will the variable be shared? Or will it be locked when in use, thus blocking other endpoints from accessing it until the current one is done? I ask the above assuming that Service instances are stateless, i.e. it would be equivalent if I created an instance of Service in each endpoint. I am reluctant to do that because I don't know which is more time consuming, instantiating and destroying

Python FastAPI Async Variable Sharing

拟墨画扇 提交于 2021-02-07 10:08:02
问题 If I had the below code, how would the variable service affect the asynchronous nature of the endpoints? Will the variable be shared? Or will it be locked when in use, thus blocking other endpoints from accessing it until the current one is done? I ask the above assuming that Service instances are stateless, i.e. it would be equivalent if I created an instance of Service in each endpoint. I am reluctant to do that because I don't know which is more time consuming, instantiating and destroying

Python FastAPI Async Variable Sharing

穿精又带淫゛_ 提交于 2021-02-07 10:07:05
问题 If I had the below code, how would the variable service affect the asynchronous nature of the endpoints? Will the variable be shared? Or will it be locked when in use, thus blocking other endpoints from accessing it until the current one is done? I ask the above assuming that Service instances are stateless, i.e. it would be equivalent if I created an instance of Service in each endpoint. I am reluctant to do that because I don't know which is more time consuming, instantiating and destroying

FastApi-02-路径参数

梦想的初衷 提交于 2021-02-04 17:58:57
何为路径参数 顾名思义,路径参数就是 url 中带的请求参数,比如根据 id 查询信息。 例:自动大写首字母 main.py ... @app.get('/format/{name}') async def fmt (name) : new_name = name.title() return { 'result' :new_name} ... 启动服务后测试 访问: http://127.0.0.1:8765/format/phyger 可以看到,功能已经实现! 存在的问题 访问: http://127.0.0.1:8765/format/123 虽然有结果返回,但是我们期望后台能够对请求参数的格式进行校验。请继续往下看。 默认的路径参数类型都是 str ,所以 123 已经被转换成了 str 类型。 带格式的路径参数 当我们在处理数字的时候,我们不希望后台对非法类型的数据进行处理。 老代码 ... @app.get('/format1/{num}') async def fmt1 (num) : print(type(num)) new_num = num+ 1 return { 'result' :new_num} ... 路径参数为 123 的结果 Internal Server Error ,因为后台将 123 当做 str 处理了,所以在进行计算的时候出错了。 新代码

How to extend FastAPI docs with another swagger docs?

孤街醉人 提交于 2021-01-27 16:16:26
问题 I decided to make a micro-services gateway in Python's FastApi framework. My authorization service is written in Django and there are already generated by drf-yasg package swagger docs. I was thinking if there is a way to somehow import auth's schema to the gateway. I can serve the schema in json format via http and access it from the gateway. The question is how to integrate FastApi's docs with raw swagger schema file. 回答1: According to docs you can modify the openAPI json. Example: from

How to extend FastAPI docs with another swagger docs?

纵然是瞬间 提交于 2021-01-27 16:15:09
问题 I decided to make a micro-services gateway in Python's FastApi framework. My authorization service is written in Django and there are already generated by drf-yasg package swagger docs. I was thinking if there is a way to somehow import auth's schema to the gateway. I can serve the schema in json format via http and access it from the gateway. The question is how to integrate FastApi's docs with raw swagger schema file. 回答1: According to docs you can modify the openAPI json. Example: from

How to extend FastAPI docs with another swagger docs?

你离开我真会死。 提交于 2021-01-27 16:14:13
问题 I decided to make a micro-services gateway in Python's FastApi framework. My authorization service is written in Django and there are already generated by drf-yasg package swagger docs. I was thinking if there is a way to somehow import auth's schema to the gateway. I can serve the schema in json format via http and access it from the gateway. The question is how to integrate FastApi's docs with raw swagger schema file. 回答1: According to docs you can modify the openAPI json. Example: from

How to extend FastAPI docs with another swagger docs?

久未见 提交于 2021-01-27 16:13:05
问题 I decided to make a micro-services gateway in Python's FastApi framework. My authorization service is written in Django and there are already generated by drf-yasg package swagger docs. I was thinking if there is a way to somehow import auth's schema to the gateway. I can serve the schema in json format via http and access it from the gateway. The question is how to integrate FastApi's docs with raw swagger schema file. 回答1: According to docs you can modify the openAPI json. Example: from