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
1
vote
1 answer

FastApi TestClient WebSockets | How to test an FastApi app which uses threads and processes properly?

I would like to write tests for my FastApi WebSocket application, but a single test runs forever and doesn't stop, which prevents the next test to start. I invoke a thread during the FastApi app "startup" which itself spawns processes. I feel like…
MJey
  • 345
  • 3
  • 16
1
vote
0 answers

python sse-starlette generator stuck after closing the sse client

I am trying to use SSE as fastApi endpoint. And the event generator never exits and getting stuck. Machine details: Ubuntu 20 Python 3.8 Server: import asyncio import uvicorn from fastapi import FastAPI, Request from sse_starlette.sse import…
Mark
  • 11
  • 2
1
vote
1 answer

How to decode the file uploaded in postman using python starlette

I have uploaded a .mp4 file in postman and now i need to read the file contents into a variable in python This is my postman upload This is my python file where i my request will be catched in this function now how will be decode the file uploaded…
SPMK
  • 19
  • 5
1
vote
0 answers

How do you access the response headers in a Starlette app?

Is there a way to access the headers that will be included in the response without writing a custom middleware to intercept them? For example, how would I get the expiration date/time of a cookie set by the SessionMiddleware, or its last access? I…
ZSwat
  • 85
  • 6
1
vote
1 answer

Is it possible to use starlette framwork to interact with elasticsearch?

I am facing difficulty in accessing the elasticsearch index using starlette framework My main.py is from urllib.request import Request from webbrowser import get from elasticsearch import Elasticsearch, helpers from starlette.applications import…
SPMK
  • 19
  • 5
1
vote
0 answers

`await call_next(request)` gets stuck indefinitely on larger payloads

I got this snippet from here. When implemented, response = await call_next(request) gets stuck indefinitely when the JSON payload is too large. What could be the reason? Is it the right way to modify the body of JSON in FastAPI? class…
Irfanuddin
  • 2,295
  • 1
  • 15
  • 29
1
vote
1 answer

How to add context to HTMLResponse?

How to add context to HTMLResponse as you can do with TemplateResponse to insert content into the HTML site? Example with TemplateResponse: return templates.TemplateResponse('index.html', context={'request': request, "Variable1": V1, "Variable2":…
BluebayX
  • 15
  • 3
1
vote
0 answers

Access fastapi.Request object without router method

I have a FastAPI app and on app-startup, I create a State for it like this: app.state.player["id"] = Player() And now I want to access this player state whenever I need it. And the only way of accessing this state is through fastapi.Request object…
Eziz Durdyyev
  • 1,110
  • 2
  • 16
  • 34
1
vote
1 answer

FastAPI: How to upload a file without using multipart/form-data request?

I have a FastAPI endpoint for handling file uploads that looks something like this: @app.post('/upload') async def accept_some_file(f: UploadFile): content = await f.read() # ... do stuff with content and generate a response but this…
kingkupps
  • 3,284
  • 2
  • 16
  • 28
1
vote
1 answer

How to update response schema in swagger for all endpoints after modifying response at middleware level in a FastAPI Application?

So, I have created a Custom Middleware for my big FastAPI Application, which alters responses from all of my endpoints this way: Response model is different for all APIs. However, my MDW adds meta data to all of these responses, in an uniform…
raghavsikaria
  • 867
  • 17
  • 30
1
vote
1 answer

How to modify the content-length post modification of response in a middleware in FastAPI?

Example Code: # Here is a minimal reproducible example import json from starlette.datastructures import MutableHeaders from starlette.types import ASGIApp, Receive, Scope, Send, Message import datetime import socket import uvicorn from fastapi…
raghavsikaria
  • 867
  • 17
  • 30
1
vote
0 answers

understanding Starlette authentication

I'm trying to build a login page for a web application. As documented here: https://www.starlette.io/authentication/ I have the following: class BasicAuthBackend(AuthenticationBackend): async def authenticate(self, conn): if…
Yonatan
  • 13
  • 4
1
vote
1 answer

In FastAPI, how can I expand a model's output with a reverse URL lookup based on a field?

Let's assume I have a simple file storage in the database. The SQLAlchemy model looks like this: class Blob(Base): id = Column(Integer, primary_key=True) blob = deferred(Column(LargeBinary().with_variant(LONGBLOB, "mysql"))) The respective…
Nikolai Prokoschenko
  • 8,465
  • 11
  • 58
  • 97
1
vote
1 answer

How to add metrics to external services using aioprometheus and FastAPI?

I'm trying to add metrics to external services with aioprometheus in an app built with FastAPI. Here is a simplified example of what I'm trying to achieve. Say I have a wrapper App class as such: from aioprometheus import Registry, Counter,…
Isaac
  • 273
  • 3
  • 19
1
vote
0 answers

Starlette - how to log in user in a view

I am making a Facebook login feature in my FastAPI/Starlette app, and have a problem with it. I see starlette provides some documentation on how to make authentication like: https://www.starlette.io/authentication/ , but with SSO, I would expect to…
tikej
  • 179
  • 1
  • 16