Skip to main content

FastAPI tools

Project description

FastAPIBoot

test build&publish coverage pypi support-version

  简单易用、功能强大的FastAPI工具库,支持CBV、依赖注入、声明式公共路由依赖和生命周期等写法,为提高效率而生。

cbv: class based view

特点

  • 📦无缝集成FastAPI,开箱即用,继承FastAPI的优点,支持通过CLI初始化。
  • 🐎支持CBVFBV,想套多少层就套多少层,路由层级关系更清晰。
  • 践行IOCDIAOP,开发更高效。
  • 🌈公共依赖提取,结合多层CBV,避免endpoint中大量的Depends
  • 🔨丰富的工具,生命周期、异常处理、中间件、tortoise工具。

1. 快速开始

1.1 安装

pip install fastapi-boot
# 或者使用uv
uv add fastapi-boot

1.2 和FastAPI比较

📌要实现这些接口

  1. 用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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi_boot-0.0.50.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_boot-0.0.50-py3-none-any.whl (20.6 kB view details)

Uploaded Python 3

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

Hashes for fastapi_boot-0.0.50.tar.gz
Algorithm Hash digest
SHA256 182a6d1f8ae56fd4833fd9f88551a77db1ceb68aae54fe22725e8a07643ff501
MD5 a6b31000ea09244ee2b87b7cabaaa2a4
BLAKE2b-256 0899097554bc21497dc897318b13036e0431a11de8d64f5ec1a1c827f6afae9e

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_boot-0.0.50.tar.gz:

Publisher: build_publish.yml on hfdy0935/fastapi-boot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for fastapi_boot-0.0.50-py3-none-any.whl
Algorithm Hash digest
SHA256 5933ee2e4688f5afe7942e701d0141f5dfcc610d6bb7e25e51f0f4d685036762
MD5 c9d407863077d2ecddb80f291eecc4a3
BLAKE2b-256 1224f85eca609bbadf39ddd16eece1f42a669481649a825bd87098ead2542c57

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page