FastAPI tools
Project description
FastAPIBoot
简单易用、功能强大的FastAPI工具库,支持CBV、依赖注入、声明式公共路由依赖和生命周期等写法,为提高效率而生。
cbv: class based view
特点
- 📦无缝集成FastAPI,开箱即用,继承FastAPI的优点,支持通过
CLI初始化。 - 🐎支持
CBV、FBV,想套多少层就套多少层,路由层级关系更清晰。 - ✅ 践行
IOC、DI、AOP,开发更高效。 - 🌈公共依赖提取,结合多层
CBV,避免endpoint中大量的Depends。 - 🔨丰富的工具,生命周期、异常处理、中间件、
tortoise工具。
1. 快速开始
1.1 安装
pip install fastapi-boot
# 或者使用uv
uv add fastapi-boot
1.2 和FastAPI比较
📌要实现这些接口
- 用fastapi_boot
from typing import Annotated
from fastapi import Query
from fastapi_boot.core import Controller, Get, provide_app, Post
import uvicorn
# fbv, function based view
@Get('/r1')
def top_level_fbv1():
return '/r1'
# fbv
@Controller('/r2').get('')
def top_level_fbv2():
return '/r2'
# cbv, class based view
@Controller('/r3')
class CBVController:
@Get('/1')
async def cbv_endpoint1(self):
return '/r3/1'
@Post('/2')
def cbv_endpoint2(self, q: Annotated[str, Query()]):
return dict(query=q, path='/r3/2')
app = provide_app(controllers=[top_level_fbv1, top_level_fbv2, CBVController])
if __name__ == '__main__':
uvicorn.run('main:app', reload=True)
- 用fastapi
from typing import Annotated
from fastapi import APIRouter, FastAPI, Query
import uvicorn
app = FastAPI()
@app.get('/r1')
def endpoint1():
return '/r1'
router1 = APIRouter(prefix='/r2')
@router1.get('')
def endpoint2():
return '/r2'
app.include_router(router1)
router2 = APIRouter(prefix='/r3')
@router2.get('/1')
async def endpoint3():
return '/r3/1'
@router2.post('/2')
def endpoint4(q: Annotated[str, Query()]):
return dict(query=q, path='/r3/2')
app.include_router(router2)
if __name__ == '__main__':
uvicorn.run('main:app', reload=True)
1.3 💡通过CLI生成:
fastapi-boot --host=localhost --port=8000 --reload --name=Demo
2. 所有API
from fastapi_boot.core import (
Injectable,
Bean,
provide_app,
use_dep,
use_http_middleware,
use_ws_middleware,
inject.
Controller,
Delete,
Get,
Head,
Options,
Patch,
Post,
Prefix,
Put,
Req,
Trace,
WebSocket as WS,
)
# tortoise工具
from fastapi_boot.tortoise_util import Sql, Select, Update, Insert, Delete as SqlDelete
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastapi_boot-0.0.50.tar.gz.
File metadata
- Download URL: fastapi_boot-0.0.50.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
182a6d1f8ae56fd4833fd9f88551a77db1ceb68aae54fe22725e8a07643ff501
|
|
| MD5 |
a6b31000ea09244ee2b87b7cabaaa2a4
|
|
| BLAKE2b-256 |
0899097554bc21497dc897318b13036e0431a11de8d64f5ec1a1c827f6afae9e
|
Provenance
The following attestation bundles were made for fastapi_boot-0.0.50.tar.gz:
Publisher:
build_publish.yml on hfdy0935/fastapi-boot
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_boot-0.0.50.tar.gz -
Subject digest:
182a6d1f8ae56fd4833fd9f88551a77db1ceb68aae54fe22725e8a07643ff501 - Sigstore transparency entry: 968260130
- Sigstore integration time:
-
Permalink:
hfdy0935/fastapi-boot@e073014929c2fbf7b756e3c198b93bbc903a177f -
Branch / Tag:
refs/tags/v0.0.50 - Owner: https://github.com/hfdy0935
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_publish.yml@e073014929c2fbf7b756e3c198b93bbc903a177f -
Trigger Event:
release
-
Statement type:
File details
Details for the file fastapi_boot-0.0.50-py3-none-any.whl.
File metadata
- Download URL: fastapi_boot-0.0.50-py3-none-any.whl
- Upload date:
- Size: 20.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5933ee2e4688f5afe7942e701d0141f5dfcc610d6bb7e25e51f0f4d685036762
|
|
| MD5 |
c9d407863077d2ecddb80f291eecc4a3
|
|
| BLAKE2b-256 |
1224f85eca609bbadf39ddd16eece1f42a669481649a825bd87098ead2542c57
|
Provenance
The following attestation bundles were made for fastapi_boot-0.0.50-py3-none-any.whl:
Publisher:
build_publish.yml on hfdy0935/fastapi-boot
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_boot-0.0.50-py3-none-any.whl -
Subject digest:
5933ee2e4688f5afe7942e701d0141f5dfcc610d6bb7e25e51f0f4d685036762 - Sigstore transparency entry: 968260194
- Sigstore integration time:
-
Permalink:
hfdy0935/fastapi-boot@e073014929c2fbf7b756e3c198b93bbc903a177f -
Branch / Tag:
refs/tags/v0.0.50 - Owner: https://github.com/hfdy0935
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_publish.yml@e073014929c2fbf7b756e3c198b93bbc903a177f -
Trigger Event:
release
-
Statement type: