Skip to main content

FastAPI 权限检查库 (参考 mwpermission Flask 版本重构)

Project description

FastAPI 权限检查库,参考 mwpermission (Flask 版本) 重构为 FastAPI 版本。

功能特点

  • 支持 FastAPI 依赖注入系统的权限检查

  • 支持装饰器风格的权限验证

  • 开发模式下可跳过权限检查

  • 支持动态权限检查

安装方法

pip install mwpermission-fastapi

快速开始

  1. 创建 FastAPI 应用并配置权限

from fastapi import FastAPI, Depends
from mwpermission_fastapi import Permission

app = FastAPI()

# 初始化权限检查器
p = Permission(sysname="maxwinweb")

使用说明

初始化权限检查器后,可以使用以下方式保护您的API端点:

# 检查用户对 employee 模块的查看权限
@app.get("/employees")
async def get_employees(user_id: int = Depends(p.check("employee", ["view"]))):
    return {"message": "employees list"}

更多详细信息,请参见完整文档。

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

mwpermission_fastapi-0.1.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

mwpermission_fastapi-0.1.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file mwpermission_fastapi-0.1.0.tar.gz.

File metadata

  • Download URL: mwpermission_fastapi-0.1.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for mwpermission_fastapi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fe4d0c1cd563da86776198d877f64d6c47e204a7bee8808fbc406f496f94f648
MD5 d0542d0161ce35148c39faa227f523ed
BLAKE2b-256 c76979046ace24b844f8b367bc1a8f8a158491e6c7cf95f13011c79fa6e9285c

See more details on using hashes here.

File details

Details for the file mwpermission_fastapi-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mwpermission_fastapi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 20954719fbb3a3d2ddcb58c0034318813c6aca68e3278fc135aa45cfec227349
MD5 7a8a66e646e4138f037fbde5a5f21336
BLAKE2b-256 340f6d26b4cc1ba5bb5ef303ee79379fd05485cfadf1729a067f1a889d7d717e

See more details on using hashes here.

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