- FastAPI 教程
- FastAPI - 首頁
- FastAPI - 簡介
- FastAPI - Hello World
- FastAPI - OpenAPI
- FastAPI - Uvicorn
- FastAPI - 型別提示
- FastAPI - IDE 支援
- FastAPI - REST 架構
- FastAPI - 路徑引數
- FastAPI - 查詢引數
- FastAPI - 引數驗證
- FastAPI - Pydantic
- FastAPI - 請求體
- FastAPI - 模板
- FastAPI - 靜態檔案
- FastAPI - HTML 表單模板
- FastAPI - 訪問表單資料
- FastAPI - 上傳檔案
- FastAPI - Cookie 引數
- FastAPI - 頭部引數
- FastAPI - 響應模型
- FastAPI - 巢狀模型
- FastAPI - 依賴項
- FastAPI - CORS
- FastAPI - CRUD 操作
- FastAPI - SQL 資料庫
- FastAPI - 使用 MongoDB
- FastAPI - 使用 GraphQL
- FastAPI - WebSockets
- FastAPI - FastAPI 事件處理器
- FastAPI - 掛載子應用
- FastAPI - 中介軟體
- FastAPI - 掛載 Flask 應用
- FastAPI - 部署
- FastAPI 有用資源
- FastAPI - 快速指南
- FastAPI - 有用資源
- FastAPI - 討論
FastAPI - 簡介
FastAPI 是一個現代化的 Python Web 框架,非常高效地構建 API。它基於 Python 自 3.6 版本起新增的型別提示功能。它是 Python 最快的 Web 框架之一。
由於它基於 Starlette 和 Pydantic 庫的功能,其效能處於最佳水平,與 NodeJS 和 Go 效能相當。
除了提供高效能外,FastAPI 還提供顯著的開發速度,減少程式碼中人為錯誤,易於學習,並且完全可用於生產環境。
FastAPI 完全相容知名的 API 標準,即 OpenAPI 和 JSON Schema。
FastAPI 由Sebastian Ramirez 於 2018 年 12 月開發。目前可用的版本為 FastAPI 0.68.0。
FastAPI – 環境設定
要安裝 FastAPI(最好在虛擬環境中),請使用pip 安裝程式。
pip3 install fastapi
FastAPI 依賴於Starlette 和Pydantic 庫,因此它們也會被安裝。
使用 PIP 安裝 Uvicorn
FastAPI 沒有內建的伺服器應用程式。要執行 FastAPI 應用程式,需要一個名為uvicorn 的 ASGI 伺服器,因此也使用 pip 安裝程式安裝它。它還會安裝 uvicorn 的依賴項 - asgiref、click、h11 和 typing-extensions。
pip3 install uvicorn
安裝這兩個庫後,我們可以檢查到目前為止安裝的所有庫。
pip3 freeze asgiref==3.4.1 click==8.0.1 colorama==0.4.4 fastapi==0.68.0 h11==0.12.0 importlib-metadata==4.6.4 pydantic==1.8.2 starlette==0.14.2 typing-extensions==3.10.0.0 uvicorn==0.15.0 zipp==3.5.0
廣告