lsyflasksdkcore_v0
领数云 Flask SDK 核心库,为 Flask 应用提供常用的功能模块和工具。
功能特性
- 🔐 身份认证与授权 - JWT Token 管理和权限控制
- 📊 数据处理 - 数据模型、序列化和 LINQ 查询
- 📈 数据导出 - Excel/CSV 文件导出功能
- 📝 API 文档 - Swagger 文档自动生成
- 🔒 加密工具 - SM2 国密算法支持
- 📋 日志管理 - 文件和 Logstash 日志记录
- 🛠 实用工具 - 延迟加载、单例模式、树结构等
安装
pip install lsyflasksdkcore_v0
或者从源码安装:
git clone https://github.com/9kl/lsyflasksdkcore.git
cd lsyflasksdkcore
pip install -e .
快速开始
基本使用
from flask import Flask
from lsyflasksdkcore import Model, sresponse, eresponse
app = Flask(__name__)
# 初始化模型
model = Model(app)
@app.route('/api/success')
def success():
return sresponse(data={"message": "操作成功"})
@app.route('/api/error')
def error():
return eresponse(message="操作失败", code=400)
权限控制
from lsyflasksdkcore.blueprints import AuthGrant
# 创建权限控制实例
auth = AuthGrant("user_management", __name__)
@app.route('/admin/users')
@auth.grant("view") # 需要查看权限
def list_users():
return sresponse(data=[])
数据导出
from lsyflasksdkcore.excel import xlsresponse
@app.route('/export/users')
@xlsresponse("用户列表.xlsx")
def export_users():
headers = ["ID", "用户名", "邮箱"]
data = [
[1, "张三", "zhangsan@example.com"],
[2, "李四", "lisi@example.com"]
]
return headers, data
JWT Token 管理
from lsyflasksdkcore.utils.token_utils import encode_auth_token, decode_auth_token
# 生成 Token
token = encode_auth_token(user_id=123, login_time=1640995200)
# 验证 Token
payload = decode_auth_token(token)
user_id = payload['data']['id']
模块说明
核心模块
- context - 请求上下文和响应处理
- model - 数据模型和查询结果封装
- schema - 数据验证和序列化模式
- serialization - 对象序列化工具
功能模块
- blueprints - Flask 蓝图和权限控制
- excel - Excel/CSV 导出功能
- swagger - API 文档生成
- linq - LINQ 风格的数据查询
- logging - 日志记录工具
- export - 数据导出处理
工具模块
- utils/token_utils - JWT Token 工具
- utils/sm2encry - SM2 加密工具
- utils/lazy - 延迟加载装饰器
- utils/singleton_meta - 单例模式元类
- utils/tree - 树形数据结构
- utils/unique - 唯一性工具
依赖要求
- Python >= 3.8
- Flask >= 3.0.3
- marshmallow >= 3.11.1
- SQLAlchemy >= 2.0.43
- PyJWT >= 2.1.0
- gmssl >= 3.2.1
详细依赖列表请查看 requirements.txt
许可证
本项目采用 Apache License 2.0 许可证。详情请查看 LICENSE 文件。
贡献
欢迎提交 Issue 和 Pull Request 来帮助改进项目。
联系方式
Release files for lsyflasksdkcore-v0 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| lsyflasksdkcore_v0-1.0.1.tar.gz | 39.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| lsyflasksdkcore_v0-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size:83.7 kB
Release files / lsyflasksdkcore_v0-1.0.1.tar.gz
| Download URL | lsyflasksdkcore_v0-1.0.1.tar.gz |
|---|---|
| Size | 39.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7ee519f4d4bae906a42c52caf30ad81c1a0fe30aa3b2c83c2c0f072191877cea
|
|
BLAKE2b-256 checksum How to use checksums |
0a20fa4cf0bf9c86eaeaaec48eea56118df733a7bcb745a70717a9bf17690747
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.11
|
Release files / lsyflasksdkcore_v0-1.0.1-py3-none-any.whl
| Download URL | lsyflasksdkcore_v0-1.0.1-py3-none-any.whl |
|---|---|
| Size | 44.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
44ad25affefbcf5c5d50adc1724a38494b5fe60b9bf1405a20ca608e19305d9f
|
|
BLAKE2b-256 checksum How to use checksums |
443aa3af7eb769e8b31deea68d3ad5f61764a852a78de211d1d07e2f7e5bc373
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.11
|