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=对象)
Metadata
Release files for fastapi-kit 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| fastapi_kit-0.1.5.tar.gz | 3.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fastapi_kit-0.1.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.7 kB
Release files / fastapi_kit-0.1.5.tar.gz
| Download URL | fastapi_kit-0.1.5.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3d11e5a83d9aabbdeae1389661eaf649c0316722941c18b587309c7db9cf62f7
|
|
BLAKE2b-256 checksum How to use checksums |
9feb3d27c2bfabbe0ce890d9620d1bda1599b78bd7271ea1f178c75bcfa232a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.11.2 Darwin/22.3.0
|
Release files / fastapi_kit-0.1.5-py3-none-any.whl
| Download URL | fastapi_kit-0.1.5-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
decbb20fd0ed46677b92264219b9cd0f757d9aac45da6f693b8fa353b4cb8b52
|
|
BLAKE2b-256 checksum How to use checksums |
10deb0629464988c6345d39ac5ac2f8220329b704906b1606760764ca8d2b5e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.11.2 Darwin/22.3.0
|
Security for fastapi-kit 0.1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.