Questions tagged [starlette]

Questions about Starlette (a lightweight python ASGI framework/toolkit).

Starlette is a lightweight ASGI framework/toolkit, which is ideal for building high performance asyncio services.

https://www.starlette.io

259 questions
3
votes
0 answers

Hosting static files with Python Fastapi inside an Appimage

I have two projects: one of them is a Python Project with Fastapi and another one is a React project. I've packaged my Python application into an Appimage, by creating a single binary for it (with pyinstaller) and then packaging it as an Appimage.…
Computergy
  • 65
  • 1
  • 6
3
votes
1 answer

Check if request is coming from Swagger UI

Using Python and Starlette or FastAPI, How can I know if the request is coming from the Swagger UI or anywhere else (Postman, Frontend app)? I tried to see if there's something in Request object which I can use: from fastapi import…
Ghasem
  • 14,455
  • 21
  • 138
  • 171
3
votes
2 answers

How to navigate through FastAPI routes by clicking on HTML button in Jinja2 Templates?

I have a FastAPI app with some routes working fine if I move around them manually (i.e., by changing the / in the browser's address bar). For example, this is one of them: @task.get('/tasks', response_model=list[Task], tags=["Tasks"]) def…
lazlomeli
  • 61
  • 7
3
votes
1 answer

FastAPI - How can I modify request from inside dependency?

How can I modify request from inside a dependency? Basically I would like to add some information (test_value) to the request and later be able to get it from the view function (in my case root() function). Below is a simple example: from fastapi…
Mike Olszak
  • 373
  • 6
  • 12
3
votes
1 answer

FastAPI/Starlette's SessionMiddleware creates new session for every request

I need to create a session for authentication in the session_set endpoint. However, for some reason, the session is still being created in the session_info endpoint. How to make a session created only in session_set? Otherwise, I have a new session…
28 Lucky
  • 43
  • 1
  • 5
3
votes
1 answer

How to get query params including keys with blank values using FastAPI?

I want to handle a use case, where a key is passed to the GET request's query parameters, but without a value. For example (request through Postman): In the case above, name is passed as a key but no value is set. I tried…
3
votes
1 answer

How to stream HTML content with static files using FastAPI?

Question How to stream an HTML page with static files and hyperlinks from another service using FastAPI? Additional Context A common architecture in micro-services is to have a gateway layer that implements a public API that passes requests to…
Mateusz
  • 219
  • 2
  • 13
3
votes
1 answer

How to load a different file than index.html in FastAPI root path?

Here is a simple static FastAPI app. With this setup even though the root path is expected to return a FileResponse of custom.html, the app still returns index.html. How can I get the root path work and render custom.html? from fastapi import…
Abbas
  • 3,872
  • 6
  • 36
  • 63
3
votes
2 answers

How to pass URL as a path parameter to a FastAPI route?

I have created a simple API using FastAPI, and I am trying to pass a URL to a FastAPI route as an arbitrary path parameter. from fastapi import FastAPI app = FastAPI() @app.post("/{path}") def pred_image(path:str): print("path",path) return…
Talha Anwar
  • 2,699
  • 4
  • 23
  • 62
3
votes
2 answers

How to return a custom 404 Not Found page using FastAPI?

I am making a rick roll site for Discord and I would like to redirect to the rick roll page on 404 response status codes. I've tried the following, but didn't work: @app.exception_handler(fastapi.HTTPException) async def…
3
votes
1 answer

FastAPI: reject a WebSocket connection with HTTP response

In a FastAPI based Web app, I have a WebSocket endpoint that should allow connections only if some conditions are met, otherwise it should return an HTTP 404 reply instead of upgrading the connection with HTTP 101. As far as I understand, this is…
shevron
  • 3,463
  • 2
  • 23
  • 35
3
votes
1 answer

FastAPI/Mangum JSON decode error when uploading multiple files

I'm trying to create a serverless file upload API using FastAPI/Mangum and am running into a strange JSON decoding issue when attempting to follow the example in the docs. Here is my code: # main.py import os from typing import List from fastapi…
3
votes
1 answer

FastAPI `run_in_threadpool` getting stuck

I have implemented all my routes using async. And have followed all guidelines from the FastAPI documentation. Every route has multiple DB calls, which does not have async support, so they are normal function like this def db_fetch(query): # I…
Irfanuddin
  • 2,295
  • 1
  • 15
  • 29
3
votes
1 answer

Use anyio.TaskGroup with fastapi.StreamingResponse

anyio is a part of starlette and, therefore, of FastAPI. I find it quite convenient to use its task groups to perform concurrent requests to external services outside of one of my API servers. Also, I would like to stream out the results as soon as…
Oleksandr Fedorov
  • 1,213
  • 10
  • 17
3
votes
1 answer

fastapi post method call with and without trailing slashes

I was trying to write a fastapi post method as: @app.post('/method/final_path/', tags=['method/final_path']) When i do a postman call as https://......./method/final_path/ I get the expected result, but if the call is changed to …
anik jha
  • 139
  • 1
  • 9