Questions tagged [fastapi]

FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints.

FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints. FastAPI is released under the terms of the MIT license.

Some notable features of FastAPI are:

  • Based on open standards like OpenAPI and JSON Schema.
  • Automatic docs including Swagger UI and ReDoc
  • Just Modern Python (based on standard Python 3.6 type declarations)
  • Editor support (especially auto-completion)
  • Written on top of Starlette, inherits all its features and provides native ASYNC support
  • Uses Pydantic to validate request and response which is Pythonic and developer does not need to learn another micro-framework to write validation schemas for requests and responses
  • Native Dependency Injection System
  • Useful Plugins

And other features described in detail here.

Documentation: https://fastapi.tiangolo.com

Source Code: https://github.com/tiangolo/fastapi

5670 questions
2
votes
0 answers

Fastapi Union for Query object or Schema Field (union without separate schema for every query parameter)

I'm trying to get Union "statuses" or "ids" query parameters at my endpoint. One way to do it - create a separate schema with a single field for every query parameter (statuses, ids, etc). But this way is pretty blown up (what if I need 10 sorts of…
salius
  • 918
  • 1
  • 14
  • 30
2
votes
3 answers

FastApi 422 Unprocessable Entity, on authentication, how to fix?

Cannot understand even if i delete all inside function and just print something still got this error, but when i use fastapi docs, and try signing with that, it work. @auth_router.post('/signin') async def sign_in(username: str = Form(...),…
2
votes
0 answers

Running fastapi with motor async framework

I am trying to play around with fastapi by creating a simple mongo based rest api . Below is what i have done so far : File : mongo.py This has all the code for getting the data from mongo db using motor framework: """Module for handling the motor…
Subhayan Bhattacharya
  • 5,407
  • 7
  • 42
  • 60
2
votes
1 answer

Is There A FastAPI Library That Can be Used to Mark An Endpoint As Protected And Verify Auth JWT Tokens In HTTP Only Cookie?

I am trying to learn and use AWS Cognito User Pools and integrate with and API implemented with Python FastAPI. So far I am using Authorisation Code Flow with my Cognito user pool redirecting to an endpoint on FastAPI to resolve the code challenge.…
anon_dcs3spp
  • 2,342
  • 2
  • 28
  • 62
2
votes
0 answers

Swagger autogenerated schema models (FastAPI, Pydantic)

I'm building my first project with FastAPI and I'm using Pydantic models so that I have autogenerated Swagger documentation for my API. I have an endpoint which have two Pydantic models as its input. Here's a signature: @router.post('',…
goedwig
  • 351
  • 1
  • 2
  • 11
2
votes
3 answers

What is the best way to stop Uvicorn server programmatically?

In Docker, I run uvicorn with bootstrap.sh & command line. In code there is a condition about public key file, if exception occurs, server needs to shutdown. So what I want to do in main.py is here (It is FastAPI). public_key = None try: with…
Ömer Alkin
  • 163
  • 3
  • 17
2
votes
1 answer

How to allow List as query params instead of requestbody in pydantic model for fastapi

So I have a simple fastapi model as follows: from typing import List from fastapi import Query, Depends, FastAPI from pydantic import BaseModel class QueryParams(BaseModel): req1: float = Query(...) opt1: int = Query(None) …
Jon E
  • 99
  • 7
2
votes
0 answers

Working example for aio pika with Fastapi

aio pika library has a working example for the Tornado framework. Is there any similar example for the Fastapi framework? I want to run RabbitMQ consumer on REST API defined with Fastapi
2
votes
2 answers

Authentication in FastApi using oauth2 and jwt

I am new to FastApi. I am trying to authenticate an user and redirect him to a protected endpoint. Upon giving the username and password (johndoe, secret) in /docs or /token, I am getting the authentication token. In the examples, they use cURL to…
2
votes
1 answer

Tests in FastAPI doesn't work with relative static path file

I'm trying to run tests in my FastAPI application and I'm using a static file that contains a JSON with colors. Once I'm running the command 'pytest {path of my test file}' I'm getting the error - No such file or directory. At first I was running…
Tomer S
  • 900
  • 1
  • 10
  • 21
2
votes
0 answers

FastAPI machine to machine token authentication

I need to implement an API with FastAPI and I would like to use a token based authentication like TokenAuthentication of Django Rest Framework offers. I would need to be able to generate a token within FastAPI and use it within an other Python app…
Lars Peyer
  • 31
  • 3
2
votes
1 answer

FastAPI - Best way to run continuous GET requests in the background

I am trying to create a program which does periodic GET requests from around 10 websites and updates the information in a DB locally. Now when a user wants information, I will display the locally stored aggregate info. I am trying to figure out the…
Sanjith Edwin
  • 23
  • 1
  • 4
2
votes
3 answers

How to make pydantic await on a async property (tortoise-orm's reverse ForeignKey)?

(MRE in the bottom of the question) In tortoise-orm, we have to await on reverse ForeignKey field as such: comments = await Post.get(id=id).comments But in fastapi, when returning a Post instance, pydantic is…
Drdilyor
  • 1,250
  • 1
  • 12
  • 30
2
votes
2 answers

'async_generator is not a callable object' FastAPI dependency issue app

I am trying to create a FastAPI and async sqlalchemy. The get_db dependency causes a weird TypeError: is not a callable object issue. Here's my code: db.py from typing import Generator from…
joween
  • 61
  • 2
  • 8
2
votes
2 answers

How to deploy a scalable API using fastapi?

I have a complex API which takes around 7GB memory when I deploy it using Uvicorn. I want to understand how I can deploy it, such a way that from my end I want to be able to make parallel requests. The deployed API should be capable of processing…
user_12
  • 1,778
  • 7
  • 31
  • 72
1 2 3
99
100