基于 FastAPI 封装的生产级 Web 应用框架
Project description
Lumary
基于 FastAPI 封装的生产级 Web 应用框架,开箱即用。
特性
- 应用封装 —
Lumary类继承 FastAPI,内置异常处理、CORS 中间件、自定义 OpenAPI 文档、健康检查 - 生命周期钩子 —
@on_startup/@on_shutdown装饰器,支持优先级排序与异常终止控制 - 统一响应格式 —
APIResponse、PageData、PageQuery等标准化 Schema - 业务异常 —
BusinessException支持自定义错误码与消息,全局自动捕获 - WebSocket 管理 —
WSConnectionManager支持分组、单播、广播、上下文管理器 - 枚举基类 —
BaseEnum提供val/label属性访问 - SQLAlchemy 混入 —
SoftDeleteMixin软删除支持(可选依赖) - 子应用管控 — 支持动态挂载子应用,禁止子应用嵌套
安装
# 最小安装(仅核心,无数据库依赖)
pip install lumary
# 仅 SQLAlchemy[asyncio] 支持
pip install lumary[sqlalchemy]
# 标准安装(含 fastapi-cli + SQLAlchemy[asyncio] + pydantic-settings)
pip install lumary[standard]
快速开始
from lumary import Lumary, on_startup, on_shutdown
app = Lumary(title='My Project', debug=True, enable_health_check=True)
@on_startup(priority=100)
async def connect_db():
print('Database connected')
@on_shutdown
async def close_db():
print('Database closed')
WebSocket
from fastapi import WebSocket
from lumary import Lumary, WSConnectionManager
app = Lumary(title='Chat')
manager = WSConnectionManager()
@app.websocket('/ws/{room}')
async def ws_endpoint(websocket: WebSocket, room: str):
async with manager.lifespan(websocket, group=room) as cid:
while True:
data = await websocket.receive_json()
await manager.broadcast_json(data, group=room, exclude={cid})
统一响应
from lumary import response_success, response_fail, APIResponse
@app.get('/users/{uid}')
async def get_user(uid: int) -> APIResponse:
user = await fetch_user(uid)
if not user:
return response_fail(code=404, message='用户不存在')
return response_success(data=user)
业务异常
from lumary import BusinessException
async def transfer(from_id: int, to_id: int, amount: float):
if amount <= 0:
raise BusinessException(code=400, message='金额必须大于零')
...
模块一览
| 模块 | 说明 |
|---|---|
lumary.application |
应用类 Lumary |
lumary.lifespan |
生命周期钩子 on_startup / on_shutdown |
lumary.schemas |
统一响应模型 APIResponse / PageData / PageQuery |
lumary.exceptions |
业务异常 BusinessException |
lumary.handlers |
全局异常处理器 |
lumary.middleware |
中间件注册 |
lumary.openapi |
自定义 OpenAPI 文档 |
lumary.websocket |
WebSocket 连接管理器 WSConnectionManager |
lumary.common.enums |
枚举基类 BaseEnum |
lumary.common.mixins |
SQLAlchemy 混入类 |
lumary.db |
数据库工具 |
License
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lumary-0.1.5.tar.gz.
File metadata
- Download URL: lumary-0.1.5.tar.gz
- Upload date:
- Size: 24.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef54d9f527edf4896fc6ec8c7ca3840aa533b9de18a49f1c8eb8d78cd4cc1da5
|
|
| MD5 |
5421aeb1fcf8a9320af24e0b402ca3b5
|
|
| BLAKE2b-256 |
fa24936879f30c4dd386017b3e7d8539290dc81f3b50061f0526b1f920253099
|
Provenance
The following attestation bundles were made for lumary-0.1.5.tar.gz:
Publisher:
publish.yml on hgz1989/pkg_lumary
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lumary-0.1.5.tar.gz -
Subject digest:
ef54d9f527edf4896fc6ec8c7ca3840aa533b9de18a49f1c8eb8d78cd4cc1da5 - Sigstore transparency entry: 1747205477
- Sigstore integration time:
-
Permalink:
hgz1989/pkg_lumary@e345f94121942fd874fbaabf7eed75772715fc22 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/hgz1989
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e345f94121942fd874fbaabf7eed75772715fc22 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file lumary-0.1.5-py3-none-any.whl.
File metadata
- Download URL: lumary-0.1.5-py3-none-any.whl
- Upload date:
- Size: 30.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc00f809adb44a46b3662df771e58415f47e6348ad1b4ac10bda67d4928a0e1c
|
|
| MD5 |
e6267ca87dd35eb4a7cb38b83b8e55e8
|
|
| BLAKE2b-256 |
5e55e1312dc02bab01380f7ff1a8827bff0909faee1b20d00a18eb1d26aa3161
|
Provenance
The following attestation bundles were made for lumary-0.1.5-py3-none-any.whl:
Publisher:
publish.yml on hgz1989/pkg_lumary
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lumary-0.1.5-py3-none-any.whl -
Subject digest:
dc00f809adb44a46b3662df771e58415f47e6348ad1b4ac10bda67d4928a0e1c - Sigstore transparency entry: 1747205619
- Sigstore integration time:
-
Permalink:
hgz1989/pkg_lumary@e345f94121942fd874fbaabf7eed75772715fc22 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/hgz1989
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e345f94121942fd874fbaabf7eed75772715fc22 -
Trigger Event:
workflow_dispatch
-
Statement type: