Skip to content
Advertisement

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 optional value into the helper function instead of into the route function. This does

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 header? Thanks :) The decorator: I need to read ‘Authorization’

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 whenever my

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 also tried using prefetch_related this way but that doesn’t

HTTPS POST to query FastAPI using python requests

I am trying to serve a Neural Network using FastAPI. The manual site http://localhost:8000/docs#/default/predict_predict_post works fine and translates into the following curl command: which also works. When I try to query the API using python requests: I only get the “422 Unprocessable Entity” Errors. Where am I going wrong here? Answer You provide a data argument to requests.post, which does

Advertisement