Skip to main content

No project description provided

Project description

fastapi_kit

认证

from fastapi import FastAPI
from fastapi_kit.auth import register_auth

app = FastAPI(...)

register_auth(app)

完成以上操作,即可在request中拿到user

异常

内置异常:

  • ExistException对于已经存在的异常
  • NoPermissionException对于无权限操作的异常
  • NotFoundException对于不存在的异常
  • OverLimitException对于超出限制的异常

对于自定义的业务报错,可以继承CustomException直接在业务处抛错。

注意:自定义异常类,需要使用app.add_exception_handler来注册。

from fastapi_kit.exception import error_exception_handler
app.add_exception_handler(自定义异常类, error_exception_handler)

权限

直接在路由定义处设置权限

from fastapi import APIRouter, Request
from fastapi_kit.permission import permission

router = APIRouter()
@router.post('/subscribe')
@permission('bidding_subscribe_create')
async def subscribe(request: Request):
    """ 创建用户订阅器 """

通用schema返回

对于正常的数据返回,使用RestfulResponse

对于具有翻页的数据返回,使用RestfulPageResponse

  • RestfulResponse
from fastapi_kit.schema import RestfulResponse
@router.post('/subscribe', response_model=RestfulResponse[对象的schema])
async def subscribe(request):
    """ 创建用户订阅器 """

    return dict(data=对象)
  • RestfulPageResponse(常用于列表)
from fastapi_kit.schema import RestfulPageResponse
@router.get('/subscribe', response_model=RestfulPageResponse[List[对象的schema]])
async def subscribe(request):
    """ 获取用户订阅器 """
    return RestfulPageResponse(data=对象)

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_kit-0.1.1.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

fastapi_kit-0.1.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_kit-0.1.1.tar.gz.

File metadata

  • Download URL: fastapi_kit-0.1.1.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.4 Darwin/22.6.0

File hashes

Hashes for fastapi_kit-0.1.1.tar.gz
Algorithm Hash digest
SHA256 43bf880248cda54969bdfab6f4546770413a7c39fe79e1bbb5d959270d789538
MD5 255da5886eabc50643bfe0780a38cd4c
BLAKE2b-256 e6ac6bf901d2dc3a4bba1062bf804694f9d962941809123e6fafee728f39f850

See more details on using hashes here.

File details

Details for the file fastapi_kit-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: fastapi_kit-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.4 Darwin/22.6.0

File hashes

Hashes for fastapi_kit-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 23f619cb66cc9aab015d7dadf89a4dcbf846068a826c7a423645270e8e77da36
MD5 8ff75d898f20b26da500a8246c03e37f
BLAKE2b-256 88e02c8e5444c0789741ec005cfa07f3e613b4bb9ee3476e1ce9843b9fafce44

See more details on using hashes here.

Supported by

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