Skip to content

Tag: fastapi

Set an optional endpoint parameter dynamically

What is the best way to set an optional endpoint parameter dynamically? Naively, I have tried with activated_on: Optional[date] = Depends(date.today) thinking FastAPI would call the callable, but it doesn’t work. Answer TL;DR Change the callable of your Depends to a helper function, and inject the optio…

How can I get headers or a specific header from my backend API?

I want to retrieve a specific header from my API inside a function with fastAPI, but I can’t found a solution for this. In flask was simply: request.headers[‘your-header-name’] Why the hell with fastAPI is so complicated to do a simple thing like this? Anyone know a solution to retrieve a he…

Push live updates through Socket

I need to pass live data from a python script to my server (made with FastApi) and from this server I need to pass all of them to a client (made with Angular). Currently I’m doing Http PUT requests from my script and then I’m using Websocket to pass the updates to the client. The problem is that w…

Fastapi/Tortoise early model init

I have the following implementation with fastapi. My current problem is that I can’t for the life of me do an early init on the tortoise models to get the relationship back in the schema. I’ve tried dumping the following line basically everywhere and it just doesn’t seem to work. i’ve …