Questions tagged [starlette]

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

Filter by
Sorted by
Tagged with
1 vote
1 answer
40 views

How to get a list of mounted sub applications from a FastAPI app?

I have a FastAPI app with a few mounted sub applications, and would like to know if there is a app.subapps() or similar method to give me the instances of sub applications mounted to the main app. ...
Jamie J's user avatar
  • 1,230
0 votes
1 answer
122 views

'anyio' has no attribute 'start_blocking_portal'

One of my fast api endpoints is supposed to return a csv response. I try to check this endpoint but I get this error self = <starlette.testclient.TestClient object at 0x7f834a5f6ec0> @...
panos's user avatar
  • 370
0 votes
1 answer
40 views

Returning Large Files With FastAPI and StreamingResponse runs out of memory because read() loads whole file into memory

I've been working with FastAPI and I've noticed that distributing large files is an issue. While I can upload them to a FastAPI server: async with aiofiles.open(temp_file_path, 'wb') as f: ...
Drowzee's user avatar
  • 11
1 vote
0 answers
26 views

FastAPI protecting shared variable with multiprocessing lock

My objective is to have a stateful app that is optimized for latency, albeit going against 12-factor pattern. Thus, I need a state manager that can safely handle concurrency/race conditions to a ...
Silver Flash's user avatar
0 votes
0 answers
10 views

Sending request to Starlettle Test client with httpx library

Hi guys I am using starlett test client. Is it possible to send request using httpx library to this test client. My use case is I have 2 apps. Say,App 1 and App2. for single app testing for App 1. ...
Origin's user avatar
  • 1,287
0 votes
1 answer
80 views

how to decide if StreamingResponse was closed in FastAPI/Starlette?

When looping a generator in StreamingResponse() using FastAPI/starlette https://www.starlette.io/responses/#streamingresponse how can we tell if the connection was somehow disconnected, so a event ...
est's user avatar
  • 11.5k
0 votes
1 answer
31 views

Modifying path param on the fly in FastAPI

We have a Lambda-based FastAPI application that has a bunch of routers such as this class ReportsRouter: @router.post( "/{customer_id}/report", response_model=ReportResponse, ...
Sidharth Samant's user avatar
1 vote
0 answers
84 views

Decoding non-utf-8 request bodies with fastapi

I have what feels like a simple question: I have a service using fastapi that receives requests in which the request bodies have been encoded using the ISO-8859-1 encoding and the content-type in the ...
oliviaoil's user avatar
2 votes
1 answer
148 views

Awaiting request.json() in FastAPI hangs forever

I added the exception handling as given here (https://github.com/tiangolo/fastapi/discussions/6678) to my code but I want to print the complete request body to see the complete content. However, when ...
GenError's user avatar
  • 977
0 votes
0 answers
54 views

Serve file from zipfile using FastAPI

I would like to serve a file from a zip file. Is there some method to server files from a zip file that is nice and supports handling exceptions? Here are my experiments There is the first naive ...
j123b567's user avatar
  • 3,180
1 vote
2 answers
156 views

FastAPI: How to redirect from a POST endpoint to a GET endpoint carrying the data submitted using the POST request?

I have a problem: I can’t understand how I can pass additional data to the redirect I read the answers: this, this, this but these links did not give me clarity in HTML file script: function cmb_pos()...
Speedy Gonzales's user avatar
0 votes
0 answers
60 views

How to disconnect StreamingResponse connection with client_socket's ip and port?

I'm building a API server that can stream video to clients. Is there any way to disconnect specific tcp connection with client's socket ip and port information? What I wanna do is : If there's an ...
ziri's user avatar
  • 3
1 vote
1 answer
205 views

Add startup/shutdown handlers to FastAPI app with lifespan API

Consider a FastAPI using the lifespan parameter like this: def lifespan(app): print('lifespan start') yield print('lifespan end') app = FastAPI(lifespan=lifespan) Now I want to register ...
Falko's user avatar
  • 17.2k
0 votes
1 answer
52 views

don't display primary-key field in edit view starlette-admin

Need help. I connect starlette-admin in my project. But if i try to edit Primary key column, I can't see this field in admin-view. enter image description here from starlette.applications import ...
Удалов Павел's user avatar
1 vote
1 answer
122 views

How to display related items in starlette-admin?

I want to display related items using starlette-admin, but i'm new to this, don't understand what part i should change. For example, I have orm.py: from sqlalchemy.orm import relationship from models....
Bimbo's user avatar
  • 51
1 vote
1 answer
500 views

How to set the event for when sending SSE via FastAPI/Starlette to have different events on the same stream

I want to send SSE from FastAPI with different events on a single stream and receive them using HTMX-sse in the browser. The recommended way is to use sse-starlette. Full working example at https://...
576i's user avatar
  • 7,796
0 votes
1 answer
50 views

Starlette CORSMiddleware not setting cookies in browsers, only in Postman [duplicate]

import random from typing import Any import uuid from fastapi import FastAPI, HTTPException, Request from pydantic import BaseModel from starlette.middleware.sessions import SessionMiddleware from ...
dclipca's user avatar
  • 1,817
0 votes
1 answer
90 views

HTTP/1.1 404 Not Found when reading external js and css file in Shiny python

Issue This is using Shiny.py, not R Shiny. See here for shiny.py repo. I am getting an error that says "GET /script.js HTTP/1.1" 404 Not Found . This is when I use ui.head_content(ui....
s-mabdurrazak's user avatar
0 votes
1 answer
144 views

receive_nowait raise WouldBlock error while uploading multiple files in FastAPI

I am trying to send multiple files from UI to fastAPI in formData. But the API is throwing error instantly when the API's is triggered. async def createNewDirectory(files: Optional[List[UploadFile]...
Deep Kumar Singh's user avatar
1 vote
1 answer
234 views

How to get Files using the Request object in FastAPI?

I am developing a webhook in which a third-party service will hit my URL and will provide some files, now I can not use FastAPI's UploadFile = File (...) because it throws an error of the required ...
The knight's user avatar
0 votes
0 answers
19 views

FastAPI acync BackgroundTask blocks main event loop [duplicate]

I have a FastAPI asynchronous task that I would like to run after returning from an endpoint. To do this, I am using BackgroundTasks; however, it seems that whilst the background task is running the ...
Rookleton's user avatar
0 votes
1 answer
285 views

FastApi (Starlette) + NGINX Proxy: URL scheme in Request Object not correct?

I'd like to know the following How does Starlette set the "url" property in the Request object - especially when operated behind a NGINX proxy. How can request.url be manipulated on the ...
physicus's user avatar
  • 361
0 votes
0 answers
126 views

Fast API and Netlify CORS issue

I am using netlify for frontend and fastapi in the backend which is hosted in deta space. My front end is running from "https://actuallyinflint.netlify.app" but I have custom dns for "...
thatonenerd's user avatar
1 vote
1 answer
509 views

FastAPI - catch-all route put after root route mount doesn't get hit

I'm trying to serve React SPA and a few API endpoints from FastAPI. React has its own routing, so in order to split responsibilities I use 2 FastAPI apps - one comes with all authorization bells and ...
grreeenn's user avatar
  • 2,337
2 votes
1 answer
399 views

How to pass parameters to an endpoint using `add_route()` in FastAPI?

I'm developing a simple application with FastAPI. I need a function to be called as endpoint for a certain route. Everything works just fine with the function's default parameters, but wheels come off ...
MariusPontmercy's user avatar
1 vote
1 answer
158 views

How does FastAPI access a PostgreSQL custom function which accepts a user input and returns a string

I am getting a response at my api endpoint that I don't understand: { "_row_getter": {}, "_memoized_keys": [ "_row_getter" ] } The FastAPI code: from typing import ...
user3105510's user avatar
1 vote
1 answer
195 views

How to upload a file from FastAPI application to a Facebook Page using Graph API?

When I try to upload a video file to a Facebook page using the Graph API in python with this function: def upload_video_file(page_id: str, access_token: str, video_file: UploadFile): upload_url = ...
Dimas Surya's user avatar
1 vote
0 answers
109 views

Uploading a starlette UploadFile object using azure Upload_blob method throws expected str, bytes or os.PathLike object, not UploadFile error [duplicate]

I am sending a multipart file from my client to my graphql server written in Python. The file gets received as a <starlette.datastructures.UploadFile object> Now when I try to upload the file ...
Sumchans's user avatar
  • 3,238
0 votes
0 answers
73 views

uploading list of object, where object will be having file and metadata field in FastAPI [duplicate]

In my fastAPI application, i am defining a post api, where i have to receive files and its metadata from frontend. I will be receiving list of dictionary(or object) where dictionary will be having two ...
Jitaso's user avatar
  • 1
0 votes
0 answers
27 views

How can I logging StremingRespone in Fastapi with out error? [duplicate]

import logging import time import json from typing import Callable from uuid import uuid4 from fastapi import FastAPI, Request, Response from starlette.middleware.base import BaseHTTPMiddleware from ...
NAM's user avatar
  • 3
0 votes
0 answers
211 views

Avoiding API Gateway 504 timeouts with FastAPI, BackgroundTasks (Starlette, Mangum)

I have setup a FastAPI REST API with AWS Gateway and trying to make use of the BackgroundTasks feature where I can do some work, create a unique token, schedule a background task and return ...
Marty Spallone's user avatar
1 vote
1 answer
2k views

Custom FastAPI middleware causes LocalProtocolError("Too much data for declared Content-Length") exception

I have a middleware implemented for FastAPI. For responses that includes some content, it works perfectly. But if a response has no body, it is causing LocalProtocolError("Too much data for ...
SercioSoydanov's user avatar
6 votes
1 answer
3k views

How to initialise a global object or variable and reuse it in every FastAPI endpoint?

I am having a class to send notifications. When being initialised, it involves making a connection to a notification server, which is time-consuming. I use a background task in FastAPI to send ...
LOrD_ARaGOrN's user avatar
  • 4,004
1 vote
1 answer
4k views

How to use Background Tasks inside a function that is called by a FastAPI endpoint?

I have the below FastAPI endpoint: @app.post("/abcd", response_model=abcdResponseModel) async def getServerDetails(IncomingData: serverModel) -> abcdResponseModel: """ ...
LOrD_ARaGOrN's user avatar
  • 4,004
2 votes
1 answer
2k views

How to update/modify request headers and query parameters in a FastAPI middleware?

I'm trying to write a middleware for a FastAPI project that manipulates the request headers and / or query parameters in some special cases. I've managed to capture and modify the request object in ...
SercioSoydanov's user avatar
1 vote
2 answers
1k views

How to raise custom exceptions in a FastAPI middleware?

I have a simple FastAPI setup with a custom middleware class inherited from BaseHTTPMiddleware. Inside this middleware class, I need to terminate the execution flow under certain conditions. So, I ...
JPG's user avatar
  • 84k
0 votes
1 answer
826 views

FastAPI OpenAI server side event blocks the main thread [duplicate]

I'm building a FastAPI endpoint which should stream the ChatCompletion of GPT3.5 from the openAI python library. Here is my code : @app.post("/ai_re/") async def read_item(request: Request): ...
Baudouin Arbarétier's user avatar
2 votes
1 answer
85 views

Send BackgroundTask out of controller [duplicate]

The documentation explains how to send background tasks from controllers, like @app.get("/mypath") async def send_notification(email: str, background_tasks: BackgroundTasks): pass I ...
Carlos Rojas's user avatar
0 votes
0 answers
291 views

FASTAPI/STARLETTE w/ REDIS Drops responses

I have a very simple FASTAPI app using a websocket route hooked to a busy loop on redis using BRPOP (blocking list pop) from redis. await ws.accept() while True: queue,message = await ...
Mike's user avatar
  • 23
2 votes
0 answers
238 views

FastAPI exceptions raised in middleware are not handled by the custom exception_handlers

I want to setup an exception handler that handles all exceptions raised across the whole application. The exception in middleware is raised correctly, but is not handled by the mentioned exception ...
p_kuzma's user avatar
  • 21
3 votes
1 answer
3k views

Excluding pydantic model fields only when returned as part of a FastAPI call

Context I have a very complex pydantic model with a lot of nested pydantic models. I would like to ensure certain fields are never returned as part of API calls, but I would like those fields present ...
rbhalla's user avatar
  • 949
2 votes
1 answer
201 views

How to run blocking operations loops concurrently using python async? [duplicate]

I have two unrelated blocking operations that listen to different events. When any of them return, I need to do an appropriate handling of the underlying event they raised. For some reason, no matter ...
Diane M's user avatar
  • 1,512
1 vote
3 answers
674 views

FastAPI responds with required field is missing

I'm following a simple tutorial from the FastAPI docs. I was already using SQLAlchemy in this project just added the fastapi dependency and trying to run it, here's my code: import re import json ...
Amol Borkar's user avatar
  • 2,373
0 votes
1 answer
409 views

TypeError: cannot convert 'URL' object to bytes following AuthLib Google Auth example for FastAPI

I'm trying to implement an example of Google OAuth using Authlib and FastAPI framework, most of the examples I found are using Authlib and that's the recommended approach, so I'm following the Authlib ...
Alvaro Artavia's user avatar
0 votes
0 answers
195 views

Raise fastapi HTTPException not showing full stacktrace to console

I would like to get full stacktrace of exceptions in my log when raising HTTPException, For now I only receive GET /info HTTP/1.1" 400 Bad Request. What Client receives is ok: Bad Request {"...
mikazz's user avatar
  • 159
1 vote
1 answer
75 views

Why is the client receiving a different status_code than the sent one?

I have this endpoint in my API which calls another endpoint in another API. I'm just returning the received response to the client, but sometimes the client is actually receiving a different ...
dipaoli's user avatar
  • 21
4 votes
2 answers
3k views

How to re-route requests to a different URL/endpoint in FastAPI?

I am trying to write a middleware in my FastAPI application, so that requests coming to endpoints matching a particular format will be re-routed to a different URL, but I am unable to find a way to do ...
Aniket Tiratkar's user avatar
0 votes
0 answers
90 views

Starlette - Simulate file uploads in GraphQL with TestClient

I have a problem testing an application with Starlette's test client. I'm using Ariadne for GraphQL support and I have a resolver that takes two arguments: image and id. Image is an Ariadne Upload ...
Demian's user avatar
  • 372
1 vote
0 answers
215 views

Async Warnings generation and catching inside Starlette Middleware using FastAPI

I'm trying to get a relatively big api (FastAPI), with multiple APIRoutes to be able to have functions throwing alerts (with the warnings package) to the api consumer in a way that the alert ...
Richard Nicolaas Mejerink's user avatar
3 votes
0 answers
99 views

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 ...
Computergy's user avatar

1
2 3 4 5 6