Skip to main content

Litefs

GitHub forks GitHub forks GitHub forks

GitHub release (latest by date) GitHub top language GitHub code size in bytes GitHub commit activity PyPI - Downloads

Litefs 是一个轻量级的 Python Web 框架,提供高性能的 HTTP 服务器、现代路由系统、WSGI/ASGI 支持、中间件系统、缓存管理等功能。

🌟 特性亮点

  • 高性能 HTTP 服务器 - 支持 epoll、greenlet 和 asyncio
  • 现代路由系统 - 装饰器风格、方法链风格,支持路径参数
  • WSGI/ASGI 兼容 - 支持 Gunicorn、Uvicorn、UWSGI 等服务器
  • 中间件系统 - 日志、安全、CORS、限流、健康检查
  • 多级缓存 - Memory、Tree、Redis、Database、Memcache 后端
  • 会话管理 - Database、Redis、Memcache 后端支持
  • 认证授权 - JWT Token、OAuth2 社交登录(GitHub、Google、微信、企业微信)
  • WebSocket 支持 - 实时通信、房间管理、心跳检测
  • Celery 集成 - 异步任务队列、定时任务
  • OpenAPI 文档 - 自动生成 Swagger UI 文档
  • 静态文件服务 - 自动 MIME 类型、安全防护、子路径访问
  • 健康检查 - 内置健康检查端点
  • 文件监控 - 热重载支持
  • Python 3.8+ 支持 - 兼容多个 Python 版本

📖 文档

完整文档已迁移至 Docsify:

🚀 快速开始

安装

pip install litefs

或从源码安装:

git clone https://github.com/leafcoder/litefs.git
cd litefs
pip install -r requirements.txt
python setup.py install

基本示例

装饰器风格

from litefs.core import Litefs
from litefs.routing import get, post

app = Litefs(host='0.0.0.0', port=8080, debug=True)

@get('/', name='index')
def index_handler(request):
    return 'Hello, World!'

@get('/user/{id}', name='user_detail')
def user_detail_handler(request, id):
    return f'User ID: {id}'

@post('/login', name='login')
def login_handler(request):
    username = request.data.get('username')
    password = request.data.get('password')
    return {'status': 'success', 'username': username}

app.register_routes(__name__)
app.run()

方法链风格

from litefs.core import Litefs

app = Litefs()

def index_handler(request):
    return 'Hello, World!'

def user_detail_handler(request, id):
    return f'User ID: {id}'

app.add_get('/', index_handler, name='index')
app.add_get('/user/{id}', user_detail_handler, name='user_detail')

app.run()

WSGI 部署

创建 wsgi.py:

from litefs.core import Litefs

app = Litefs()

@get('/', name='index')
def index_handler(request):
    return 'Hello, World!'

application = app.wsgi()

使用 Gunicorn:

gunicorn -w 4 -b :8000 wsgi:application

使用 Uvicorn (ASGI):

uvicorn asgi:application --host 0.0.0.0 --port 8000 --workers 4

📁 项目结构

litefs/
├── README.md              # 项目说明
├── pyproject.toml         # 项目配置
├── setup.py               # 安装脚本
├── docs/                  # 文档目录
│   ├── README.md         # 文档导航
│   └── source/           # 文档源文件
│       ├── getting-started.md
│       ├── routing-guide.md
│       ├── middleware-guide.md
│       ├── auth-system.md
│       ├── websocket.md
│       ├── celery-integration.md
│       ├── openapi-integration.md
│       └── ...
├── examples/              # 示例代码
│   ├── 01-quickstart/
│   ├── 02-rest-api/
│   ├── 03-web-app/
│   ├── 04-realtime/
│   └── 05-production/
├── src/litefs/            # 源代码
│   ├── __init__.py
│   ├── core.py
│   ├── routing/
│   ├── middleware/
│   ├── auth/
│   ├── websocket/
│   ├── tasks/
│   ├── openapi/
│   ├── cache/
│   ├── session/
│   └── ...
└── tests/                 # 测试代码
    ├── unit/
    ├── integration/
    └── performance/

📚 示例代码

Litefs 提供了丰富的示例,按照功能模块组织:

每个示例都包含详细的 README 文档和可运行的代码,请参考 examples/README.md 了解更多。

📊 性能测试

LiteFS 提供完整的性能测试套件,支持多种服务器模式和部署方案的对比测试。

测试矩阵

服务器形式 单进程 多进程 测试场景
LiteFS HttpServer ✅ ✅ (4/8 Worker) Hello World
LiteFS + Gunicorn (gevent) ✅ ✅ (4/8 Worker) Hello World
FastAPI + Gunicorn + UvicornWorker (对照组) ✅ ✅ (4/8 Worker) Hello World
FastAPI + Uvicorn (对照组) ✅ ✅ (4/8 Worker) Hello World

性能测试结果

测试环境: 12 核 CPU, Python 3.10.9, Linux 6.18 测试工具: Apache Benchmark (ab), 10000 请求, 3 次迭代取中位数 测试时间: 2026-05-19

1 Worker 性能对比 (req/s)

并发数 LiteFS+HttpServer LiteFS+Gunicorn FastAPI+Gunicorn+Uvicorn FastAPI+Uvicorn 优势倍数 (HS vs GU)
100 7,977 5,259 2,804 2,984 2.84x
500 4,865 5,272 3,071 2,388 1.58x
1000 6,068 5,076 2,777 2,692 2.18x

4 Worker 性能对比 (req/s)

并发数 LiteFS+HttpServer LiteFS+Gunicorn FastAPI+Gunicorn+Uvicorn FastAPI+Uvicorn 优势倍数 (HS vs GU)
100 15,851 13,117 3,861 5,019 4.10x
500 9,895 10,133 5,906 5,228 1.67x
1000 12,783 6,666 4,662 6,001 2.74x

8 Worker 性能对比 (req/s)

并发数 LiteFS+HttpServer LiteFS+Gunicorn FastAPI+Gunicorn+Uvicorn FastAPI+Uvicorn 优势倍数 (HS vs GU)
100 19,590 13,706 5,316 6,845 3.68x
500 12,291 7,121 6,798 5,905 1.80x
1000 11,518 9,952 6,710 6,742 1.71x

性能特点

  • LiteFS HttpServer 最高 RPS: 8 Worker / 100 并发下达 19,590 req/s
  • 多 Worker 扩展性优异: 从 1 Worker 到 8 Worker,RPS 提升 2.5 倍
  • 低并发优势最大: 100 并发下 LiteFS HttpServer 是 FastAPI 的 2.8~4.1 倍
  • 高并发依然领先: 即使 1000 并发,LiteFS 仍保持 1.7~2.7 倍优势
  • 内置服务器最优: LiteFS HttpServer 在所有场景下均优于 Gunicorn 部署

快速开始

# 进入测试目录
cd tests/performance

# 运行完整性能测试
bash run_test.sh

# 测试完成后查看报告
cat performance_report.md

测试配置

参数 默认值 说明
总请求数 10,000 ab -n 参数
预热请求数 1,000 消除冷启动影响
迭代次数 3 取中位数减少波动
并发级别 100 / 500 / 1000 ab -c 参数
Worker 数 1 / 4 / 8 多进程对比
冷却间隔 2s 确保端口完全释放

输出报告

测试完成后在 tests/performance/ 目录生成:

  • performance_report.md - 详细性能测试报告
  • test_results/ - 原始测试数据

报告包含:

  • 各部署模式 RPS 性能对比
  • 多 Worker / 多并发级别交叉对比
  • LiteFS vs FastAPI 优势倍数
  • 性能分析及建议

🧪 测试

运行单元测试:

pytest tests/unit/ -v --cov=litefs --cov-report=html

运行性能测试:

cd tests/performance && bash run_test.sh

查看测试覆盖率:

make coverage

📊 测试覆盖率

当前测试覆盖率:52%

目标:80%+

详细测试报告见 单元测试文档。

🔧 开发指南

本地开发

# 克隆仓库
git clone https://github.com/leafcoder/litefs.git
cd litefs

# 安装依赖
pip install -r requirements.txt

# 安装开发依赖
pip install -r requirements-dev.txt

# 运行测试
pytest

# 构建文档
make docs-build

# 运行文档服务器
make docs-serve

代码规范

  • 遵循 PEP8 规范
  • 使用类型注解
  • 编写单元测试
  • 保持文档更新

🤝 贡献

欢迎贡献代码、文档和建议!

  1. Fork 本仓库
  2. 创建特性分支 (git checkout -b feature/AmazingFeature)
  3. 提交更改 (git commit -m 'Add some AmazingFeature')
  4. 推送到分支 (git push origin feature/AmazingFeature)
  5. 开启 Pull Request

📄 License

MIT License - 详见 LICENSE 文件。

🔗 相关链接


如果这个项目对你有帮助,请给一个 ⭐️ Star 支持!

Metadata

Release files for litefs 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for litefs 0.9.0
File Size Uploaded Provenance
litefs-0.9.0.tar.gz 2.1 MB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for litefs 0.9.0
File Interpreter ABI Platform
litefs-0.9.0-py3-none-any.whl Python 3 none any Details

Total release size: 2.4 MB

Release files / litefs-0.9.0.tar.gz

Download URL litefs-0.9.0.tar.gz
Size 2.1 MB
Tags Source
SHA-256 checksum
How to use checksums
6d61e20625c113a352a4ae18fc7b10501f8c4c4bf3c9873e9a47be7642b5b461
BLAKE2b-256 checksum
How to use checksums
39b8447b119ac450bbb4151cca88d8b966b412559ec3bfca15db2f3ba86143c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.9

Release files / litefs-0.9.0-py3-none-any.whl

Download URL litefs-0.9.0-py3-none-any.whl
Size 244.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0148e09d4c307f768e9bd87eee4e0b1ac8de46268f1d9828ae2672419a1b4bd7
BLAKE2b-256 checksum
How to use checksums
a983b92c1810add182e9cdd8dab5712d4899fbde26448d15e1d2b9e77369419f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.9

Security for litefs 0.9.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page