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
0
votes
0 answers

Understanding how Python websocket keepalive mechanism works

Not able to understand how the ping pong is handled for python websockets package. The following is a simple fastapi websocket server and a python client. I expect keepalive timeout error but that does not happen. FastAPI server: from fastapi import…
Baenka
  • 243
  • 3
  • 15
0
votes
0 answers

Pydantic JSON validation

Currently i am working on a sample project using pydantic and starlette. This is code from main file: async def submit(request): response = await request.json() resume = Resume(**response) JsonResponse({"Hello":"World"}) Code from Validation…
0
votes
0 answers

Webpage stops reciving FastAPI websocket events

So I'm transfering from node into FastAPI (Because it's more convinient for me) And I have a webpage (full code here), which was working in node, but when transferred to FastAPI only starting websocket messages get through, the one in loop get lost…
Moder New
  • 457
  • 1
  • 5
  • 18
0
votes
0 answers

Starlette's Middleware causes HTTP communication to stall

I try to make custom middleware to validate upload file in http requests. sample code: class MyMiddleware(BaseHTTPMiddleware): ... async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) -> Response: …
ttt
  • 1
0
votes
0 answers

FastAPI how to print the HTTP request status code

I am new to FastAPI framework, I want to print out the response status code from a PUT request. @app.put('/user/{id}', status_code=status.HTTP_200_OK) async def processing(id: str, request: Request, response: Response): data = await…
uk_butterfly
  • 93
  • 1
  • 2
  • 8
0
votes
1 answer

FastAPI/Starlette, Web UI: Save File Dialog, Open File Dialog

I've been studying this example project. Very concise and to the point, and a pleasant surprise, too: a Save File Dialog (a standard desktop File Dialog, opened from Chrome). The responsible code: src/html.py: @app.post('/download') def…
Alexey Orlov
  • 2,412
  • 3
  • 27
  • 46
0
votes
1 answer

Create parent child object simultaneously when both has no validation/uniqueness issue using encode/databases wrapper

I have a following model where a parent can have many children. User can just create the parent or create a parent along with the child at the same time. class Parent(Base): name = Column(String) slug = Column(String) values =…
milan
  • 2,409
  • 2
  • 34
  • 71
0
votes
1 answer

utf-8 decode error when trying to feed an image into a model

I have successfully created a webpage that takes an image file and passes it to the API I built. The only problem is that once I feed that image to preprocessing.image.load_img from tensorflow, I get this error: UnicodeDecodeError: 'utf-8' codec…
Luleo_Primoc
  • 75
  • 1
  • 12
0
votes
1 answer

serve pre-compressed files with Starlette, when uncompressed is requested, but 'accept-encoding' includes 'gzip'

Assuming as request.url GET /fomantic-ui/default/semantic.min.css for certain file extension, e.g. .css, I need to serve a pre-compressed .gz version. From node-express I know an approach, that when applied to Starlette would be to simply…
Wu Wei
  • 1,827
  • 1
  • 15
  • 27
0
votes
0 answers

FastAPI persist DB connection

I use FastAPI in a microservice environment on a public cloud. Most of the request needs a pymongo and redis connection. The preferred model of FastAPI is to inject db connections via dependencies. However the DB is rolling its credentials once a…
Lau
  • 1,353
  • 7
  • 26
0
votes
1 answer

Hypercorn - AsyncioWSGIMiddleware

I couldn't find a way to limit request body size (POST with json body) on Gunicorn/Uvicorn/Hypercorn (using Starlette), and I didn't find anything that suggests it's possible. Is it, by any chance?
Tal
  • 91
  • 1
  • 5
0
votes
1 answer

FastAPI - Set the url or path for the Request object

I have a function that looks like this: @app.middleware("http") async def process_api_event(request: Request, call_next): url = request.url path = request.url.path # request.__setattr__('url', 'sample_url') # request.url.__…
lovprogramming
  • 593
  • 11
  • 24
0
votes
1 answer

Pytorch is really slow and uses a lot of GPU memory when used in Starlette with WEB_CONCURRENCY > 1

I am trying to build an API that uses a Pytorch model. However, as soon as I increase WEB_CONCURRENCY to something above 1, it creates substantially more threads than expected and slows down by a lot, even when sending a single request. Example…
0
votes
1 answer

Browser refresh not sending the last-event-id received as part of server sent response

I'm trying to build real time notification system for users using Server sent events in python. The issue I'm facing is when I refresh the browser, which means the browser then will try to hit the EventSource url again, and as per docs it…
Cyclotron3x3
  • 2,188
  • 23
  • 40
0
votes
1 answer

How to interface hypercorn and starlette web framwork

I was able to get it up and running with gunicorn and uvloop, but having a hard time getting this working with hypercorn. Another issue is specifying the number of workers for ASGI frameworks.
Dan N
  • 7
  • 1
  • 7
1 2 3
17
18