Litefs 是一个轻量级的 Python Web 框架,提供高性能的 HTTP 服务器、现代路由系统、WSGI/ASGI 支持、中间件系统、缓存管理等功能。
- 中间件系统 - 内置和自定义中间件
- 缓存系统 - 多级缓存管理
- 会话管理 - Session 后端和使用
- WSGI 部署 - Gunicorn、uWSGI 部署
- ASGI 部署 - Uvicorn、Daphne 部署
- Keep-Alive 支持 - HTTP 长连接
- Greenlet vs asyncio - 性能对比
- ASGI 服务器实现 - 异步服务器
- API 参考 - 完整 API 文档
from litefs 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()pip install litefs或从源码安装:
git clone https://github.com/leafcoder/litefs.git
cd litefs
pip install -r requirements.txt
python setup.py install- 高性能 HTTP 服务器 - 支持 epoll 和 greenlet
- 现代路由系统 - 装饰器风格、方法链风格
- WSGI/ASGI 兼容 - 支持 Gunicorn、Uvicorn 等
- 中间件系统 - 日志、安全、CORS、限流
- 多级缓存 - Memory、Tree、Redis、Database、Memcache
- 会话管理 - Database、Redis、Memcache 后端
- 静态文件服务 - 自动 MIME 类型、安全防护
- 健康检查 - 内置健康检查端点
- 文件监控 - 热重载支持
本文档使用 Docsify 构建,支持实时渲染和搜索。
本地预览文档:
# 使用 docsify-cli
docsify serve docs
# 或使用 Python HTTP 服务器
cd docs
python -m http.server 8000然后访问 http://localhost:8000 查看文档。
MIT License - 详见 LICENSE