fastapi | FastAPI framework , high performance | REST library

 by   tiangolo Python Version: 0.110.1 License: MIT

kandi X-RAY | fastapi Summary

kandi X-RAY | fastapi Summary

fastapi is a Python library typically used in Web Services, REST, Fastapi, Swagger applications. fastapi has no vulnerabilities, it has build file available, it has a Permissive License and it has high support. However fastapi has 9 bugs. You can install using 'pip install fastapi' or download it from GitHub, PyPI.

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

            kandi-support Support

              fastapi has a highly active ecosystem.
              It has 59196 star(s) with 4933 fork(s). There are 631 watchers for this library.
              There were 10 major release(s) in the last 6 months.
              There are 18 open issues and 3312 have been closed. On average issues are closed in 311 days. There are 502 open pull requests and 0 closed requests.
              It has a positive sentiment in the developer community.
              The latest version of fastapi is 0.110.1

            kandi-Quality Quality

              fastapi has 9 bugs (0 blocker, 0 critical, 4 major, 5 minor) and 523 code smells.

            kandi-Security Security

              fastapi has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              fastapi code analysis shows 0 unresolved vulnerabilities.
              There are 89 security hotspots that need review.

            kandi-License License

              fastapi is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              fastapi releases are available to install and integrate.
              Deployable package is available in PyPI.
              Build file is available. You can build the component from source.
              Installation instructions, examples and code snippets are available.
              fastapi saves you 16583 person hours of effort in developing the same functionality from scratch.
              It has 48740 lines of code, 2321 functions and 790 files.
              It has low code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed fastapi and discovered the below as its top functions. This is intended to give you an instant insight into fastapi implemented functionality, and help decide if they suit your requirements.
            • Include the given router
            • Gets a default value from first_item
            • Add a new API web websocket route
            • Add API route
            • Build documentation for lang
            • Get the sections of a list
            • Return a mapping of file to file name
            • Get a section of a key
            • Get experiments from GraphQL
            • Update item
            • Get the model field for a given dependant
            • Returns the contributors of the pull request
            • Create a new language
            • Include a router
            • Get a list of the most common users
            • Build all languages
            • Read items from an item
            • Get the current user
            • Construct an API route
            • Create a trace from a response
            • Make a PUT request
            • Make a DELETE request
            • Generate options for a request
            • Make a HEAD request
            • Set up the server
            • Make a GET request
            Get all kandi verified functions for this library.

            fastapi Key Features

            No Key Features are available at this moment for fastapi.

            fastapi Examples and Code Snippets

            Réponses supplémentaires dans OpenAPI-Réponse supplémentaire avec model
            Pythondot img1Lines of Code : 119dot img1License : Permissive (MIT)
            copy iconCopy
            **FastAPI** prendra le modèle Pydantic à partir de là, générera le `JSON Schema` et le placera au bon endroit.
            Le bon endroit est :
            * Dans la clé `content`, qui a pour valeur un autre objet  
            Additional Responses in OpenAPI-Additional Response with model
            Pythondot img2Lines of Code : 119dot img2License : Permissive (MIT)
            copy iconCopy
            **FastAPI** will take the Pydantic model from there, generate the `JSON Schema`, and put it in the correct place.
            The correct place is:
            * In the key `content`, that has as value another JSO  
            Release Notes-0.80.0-Breaking Changes - Fixes
            Pythondot img3Lines of Code : 43dot img3License : Permissive (MIT)
            copy iconCopy
            from fastapi import FastAPI
            from pydantic import BaseModel
            class Item(BaseModel):
                name: str
                price: Optional[float] = None
                owner_ids: Optional[List[int]] = None
            app = FastAPI()
            @app.get("/items/invalidnone", response_model=Item)
            def get  
            fastapi - termynal
            JavaScriptdot img4Lines of Code : 171dot img4License : Permissive (MIT License)
            copy iconCopy
             * termynal.js
             * A lightweight, modern and extensible animated terminal window, using
             * async/await.
             * @author Ines Montani 
             * @version 0.0.1
             * @license MIT
            'use strict';
            /** Generate a terminal widget. */
            class Termynal {
            fastapi - custom
            JavaScriptdot img5Lines of Code : 168dot img5License : Permissive (MIT License)
            copy iconCopy
            const div = document.querySelector('.github-topic-projects')
            async function getDataBatch(page) {
                const response = await fetch(`${page}`, { headers: { Accept: 'a  
            fastapi - chat
            JavaScriptdot img6Lines of Code : 3dot img6License : Permissive (MIT License)
            copy iconCopy
            ((window.gitter = {}).chat = {}).options = {
                room: 'tiangolo/fastapi'
            FastAPI - How to get the response body in Middleware
            Pythondot img7Lines of Code : 22dot img7License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            from starlette.concurrency import iterate_in_threadpool
            async def some_middleware(request: Request, call_next):
                response = await call_next(request)
                response_body = [chunk async for chunk in response.body_it
            copy iconCopy
            class Inputs(BaseModel):
                id: int
                f1: float
                f2: float
                f3: str
            class InputsList(BaseModel):
                inputs: List[Inputs]
              "inputs": [
                  "id": 1,
                  "f1": 1.0,
                  "f2": 1.0,
            copy iconCopy
            class Inputs(BaseModel):
                id: int
                f1: float
                f2: float
                f3: str
              "inputs": [
                  "id": 1,
                  "f1": 1.0,
                  "f2": 1.0,
                  "f3": "text"
                  "id": 2,
                  "f1": 2.0,
            How to dockerize multi-file python project
            Pythondot img10Lines of Code : 20dot img10License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            ├── requirements.txt
            ├── Dockerfile
            ├── async_fastapi
            FROM python:3.8.10
            ENV WORKSPACE /opt/instal

            Community Discussions


            FastAPI - GET request results in typeerror (value is not a valid dict)
            Asked 2022-Mar-23 at 22:19

            this is my database schema.

            I defined my Schema like this:

            from pydantic import BaseModel



            Answered 2022-Mar-23 at 22:19

            SQLAlchemy does not return a dictionary, which is what pydantic expects by default. You can configure your model to also support loading from standard orm parameters (i.e. attributes on the object instead of dictionary lookups):



            Conditional call of a FastApi Model
            Asked 2022-Mar-20 at 10:36

            I have a multilang FastApi connected to MongoDB. My document in MongoDB is duplicated in the two languages available and structured this way (simplified example):



            Answered 2022-Feb-22 at 08:00

            There are 2 parts to the answer (API call and data structure)

            for the API call, you could separate them into 2 routes like /api/v1/fr/... and /api/v1/en/... (separating ressource representation!) and play with fastapi.APIRouter to declare the same route twice but changing for each route the validation schema by the one you want to use.

            you could start by declaring a common BaseModel as an ABC as well as an ABCEnum.



            fastapi (starlette) RedirectResponse redirect to post instead get method
            Asked 2022-Mar-18 at 10:58

            I have encountered strange redirect behaviour after returning a RedirectResponse object




            Answered 2022-Jan-19 at 20:22

            When you want to redirect to a GET after a POST, the best practice is to redirect with a 303 status code, so just update your code to:



            uvicorn [fastapi] python run both HTTP and HTTPS
            Asked 2022-Mar-01 at 20:49

            I'm trying to run a fastapi app with SSL.

            I am running the app with uvicorn.

            I can run the server on port 80 with HTTP,



            Answered 2021-Oct-03 at 16:23

            Run a subprocess to return a redirect response from one port to another.




            how to render a json from a dataframe in fastAPI
            Asked 2022-Feb-23 at 09:03

            I have a csv file that i want to render in a fastAPI app. I only managed to render te csv in json format like following:



            Answered 2022-Feb-23 at 09:03

            The below shows four different ways to return the data from a csv file.

            Option 1 is to get the file data as JSON and parse it into a dict. You can optionally change the orientation of the data using the orient parameter in the to_json() method.

            • Update 1: Using to_dict() method might be a better option, as there is no need for parsing the JSON string.
            • Update 2: When using to_dict() method and returning the dict, FastAPI, behind the scenes, automatically converts that return value into JSON, using the jsonable_encoder. Thus, to avoid that extra work, you could still use to_json() method, but instead of parsing the JSON string, put it in a Response and return it directly, as shown in the example below.

            Option 2 is to return the data in string form, using to_string() method.

            Option 3 is to return the data as an HTML table, using to_html() method.

            Option 4 is to return the file as is using FastAPI's FileResponse.



            FastAPI - Pydantic - Value Error Raises Internal Server Error
            Asked 2022-Jan-14 at 12:44

            I am using FastAPI with Pydantic.

            My problem - I need to raise ValueError using Pydantic



            Answered 2021-Aug-25 at 04:48

            If you're not raising an HTTPException then normally any other uncaught exception will generate a 500 response (an Internal Server Error). If your intent is to respond with some other custom error message and HTTP status when raising a particular exception - say, ValueError - then you can use add a global exception handler to your app:



            Kill a python subprocess that does not return
            Asked 2022-Jan-06 at 13:00

            TLDR I want to kill a subprocess like top while it is still running
            I am using Fastapi to run a command on input. For example if I enter top my program runs the command but since it does not return, at the moment I have to use a time delay then kill/terminate it. However I want to be able to kill it while it is still running. However at the moment it won't run my kill command until the time runs out. Here is the current code for running a process:



            Answered 2022-Jan-06 at 13:00

            It's because is blocking itself - you need to run shell command in background e.g. if you have asnycio loop already on, you could use subprocesses



            "422 Unprocessable Entity" error when making POST request with both attributes and key using FastAPI
            Asked 2021-Dec-19 at 11:55

            I have a file called as follows:



            Answered 2021-Dec-19 at 11:55

            Let's start by explaining what you are doing wrong.

            FastAPI's TestClient is just a re-export of Starlette's TestClient which is a subclass of requests.Session. The requests library's post method has the following signature:



            FastAPI responding slowly when calling through other Python app, but fast in cURL
            Asked 2021-Nov-27 at 22:15

            I have an issue that I can't wrap my head around. I have an API service built using FastAPI, and when I try to call any endpoint from another Python script on my local machine, the response takes 2+ seconds. When I send the same request through cURL or the built-in Swagger docs, the response is nearly instant.

            The entire server script is this:



            Answered 2021-Nov-27 at 22:15

            Try using „“ instead of „localhost“ to refer to your machine. I once had a similar issue, where the DNS lookup for localhost on windows was taking half a second or longer. I don‘t have an explanation for that behaviour, but at least one other person on SO seems to have struggled with it as well…



            How to apply transaction logic in FastAPI RealWorld example app?
            Asked 2021-Nov-20 at 02:01

            I am using nsidnev/fastapi-realworld-example-app.

            I need to apply transaction logic to this project.

            In one API, I am calling a lot of methods from repositories and doing updating, inserting and deleting operations in many tables. If there is an exception in any of these operations, how can I roll back changes? (Or if everything is correct then commit.)



            Answered 2021-Nov-20 at 02:01

            nsidnev/fastapi-realworld-example-app is using asyncpg.

            There are two ways to use Transactions.

            1. async with statement


            Community Discussions, Code Snippets contain sources that include Stack Exchange Network


            No vulnerabilities reported

            Install fastapi

            You will also need an ASGI server, for production such as Uvicorn or Hypercorn.
            Now modify the file to receive a body from a PUT request. Declare the body using standard Python types, thanks to Pydantic. The server should reload automatically (because you added --reload to the uvicorn command above).


            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
          • PyPI

            pip install fastapi

          • CLONE
          • HTTPS


          • CLI

            gh repo clone tiangolo/fastapi

          • sshUrl


          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link