Fast API

Installation

# Install
pip install "fastapi[standard]"
# Develop
fastapi dev main.py
# Production
fastapi run main.py

Feature

  • the interactive API documentation will be generated automatically

  • Uvicorn is used as a web server for Python

Concurrency

  • Starlette (and FastAPI) are based on AnyIO, which makes it compatible with both Python's standard library asyncio and Trio and provides an event loop similar to Node.js.

  • FastAPI applications run on ASGI servers like Uvicorn or Hypercorn. ASGI is an interface which allows communication between web server and Asynchronous web application and frameworks

@app.get("/test")
async def test():
    test = await fn()
    return test

Error Handling

Middleware

Sub Applications

  • If you need to have two independent FastAPI applications, with their own independent OpenAPI and their own docs UIs, you can have a main app and "mount" one (or more) sub-application(s).

  • The middleware and error handler will also be independent between sub applications

Mounting

  • "Mounting" means adding a completely "independent" application in a specific path, that then takes care of handling everything under that path

Last updated

Was this helpful?