Questions tagged [fastapi]

FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints.

FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints. FastAPI is released under the terms of the MIT license.

Some notable features of FastAPI are:

  • Based on open standards like OpenAPI and JSON Schema.
  • Automatic docs including Swagger UI and ReDoc
  • Just Modern Python (based on standard Python 3.6 type declarations)
  • Editor support (especially auto-completion)
  • Written on top of Starlette, inherits all its features and provides native ASYNC support
  • Uses Pydantic to validate request and response which is Pythonic and developer does not need to learn another micro-framework to write validation schemas for requests and responses
  • Native Dependency Injection System
  • Useful Plugins

And other features described in detail here.

Documentation: https://fastapi.tiangolo.com

Source Code: https://github.com/tiangolo/fastapi

5670 questions
2
votes
0 answers

fastapi testing (RuntimeError("Task ... running at ... got Future ... attached to a different loop")

RuntimeError("Task cb=[_run_until_complete_cb() at /usr/lib/python3.8/asyncio/base_events.py:184]> got Future
salius
  • 918
  • 1
  • 14
  • 30
2
votes
0 answers

Apscheduler clock process crashes every time

I am creating a fairly straightforward little app, and am trying to use apscheduler to send a text to a user at a certain time. It works wonderfully locally, but the clock process, as specified in the Procfile, crashes every time. The only…
J. B.
  • 155
  • 1
  • 8
2
votes
1 answer

Raising Exception from ApiRouter does not run the exception handler, returns 500 internal server error instead. FAST API

I am raising a custom exception in a Fast API using an API Router added to a Fast API. I am defining the exception class and handler and adding them both using the following code. It was working before and now I am not quite sure what is the issue.…
Aidan Tan
  • 43
  • 1
  • 5
2
votes
0 answers

Exception in ASGI application Of FastAPI

I'm using FastAPI and the following error is reported, but I don't know where the error is when I'm tracing. I have read this link, but it's no…
gthank
  • 71
  • 2
  • 6
2
votes
2 answers

Conditionally set FastAPI response model for route

I'm trying to return a list of objects of type Company, including only "approved" ones, and with more or less attributes depending on whether the user requesting the list is a superuser or a regular user. This is my code so far: @router.get("/",…
Dijkie85
  • 1,036
  • 8
  • 21
2
votes
0 answers

How to update request parameters in FastAPI

I am using FastAPI, I want to define a Middleware in which I can intercept the encrypted parameters passed by the front-end and decrypt them, and replace the original parameters with the decrypted ones, what should I do? I have tried body = await…
gthank
  • 71
  • 2
  • 6
2
votes
2 answers

Python FastAPI doesn't save content from POST file request

I have this simple code snippet that I use for File upload using FastAPI in Python. @app.post("/uploadfile") async def create_upload_file(file: UploadFile = File(...)): contents = await file.read() print(str(contents)[2:-1]) with…
anthino12
  • 770
  • 1
  • 6
  • 29
2
votes
2 answers

How to logout in FastAPI-login?

I have a basic web site on FastAPI. I would like to implement login/logout (Auth) behavior similar to Flask-login, i.e. allow access to a function/path with decorator like @login_required or FastAPI Dependecy injection. I found fastapi-login module…
uzla
  • 515
  • 1
  • 4
  • 20
2
votes
1 answer

Cookie based Authentication in FastAPI

I am looking to integrate Cookie based authentication in my FastAPI App. I want the same to work seamlessly with swagger as well. I want to have a route (eg: /login) which sets my browser cookies. All other protected route uses Depends in the…
Irfanuddin
  • 2,295
  • 1
  • 15
  • 29
2
votes
1 answer

Write data to a CSV on the fly and download the file using fast api

I am getting corrupted data when I am downloading the file using the api: file_name = 'download' prepared_df = pd.DataFrame.from_dict(data) path_to_excel = os.path.join(dir_to_download, file_name) writer = pd.ExcelWriter(path_to_excel,…
Rohan Kumar
  • 181
  • 1
  • 2
  • 16
2
votes
1 answer

Why does documentation use lru_cache decorated function to get settings, instead of importing an initialized settings object from the module directly

FastAPI documentation recommends using lru_cache decorated functions to retrieve the config file. That makes sense to avoid I/O getting the env file. config.py from pydantic import BaseSettings class Settings(BaseSettings): app_name: str =…
mowienay
  • 1,264
  • 4
  • 19
  • 32
2
votes
1 answer

Request do not reach FastAPI Server

I was working on Flask microservice and I needed to rewrite it with FastAPI but I had a problem that I had not with Flask. The problem is that I send a request which is not reaching the server indefinitely. To unstuck the request for example with…
2
votes
1 answer

fastapi connection using Python requests

I have a fast api for a simple ML model. THE post request for API is @app.post('/predict') def predict_species(data: str): data_new = np.array([data]) prob = lr_tfidf.predict_proba(data_new).max() pred = lr_tfidf.predict(data_new) …
Ahmad Anis
  • 2,322
  • 4
  • 25
  • 54
2
votes
0 answers

How to use refresh token with Keycloak and Fastapi?

I am using the built-in Oauth2 fastapi module to contact the Keycloak token endpoint and get an access token. In Keycloak I have a client with openid-connect and confidential access type, and client credentials flow enabled (this looked like the…
Mylden
  • 21
  • 1
  • 3
2
votes
2 answers

Increase API timeout in fastapi from docker image

I running FastAPI docker image and getting timeouts. The default timeout is 60 seconds. Any idea what will be the simplest way to increase the timeout?
MTZ4
  • 2,274
  • 2
  • 25
  • 41
1 2 3
99
100