Skip to content

leafcoder/litefs

Repository files navigation

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 后端支持
  • 静态文件服务 - 自动 MIME 类型、安全防护、子路径访问
  • 健康检查 - 内置健康检查端点
  • 文件监控 - 热重载支持
  • Python 3.7+ 支持 - 兼容多个 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 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 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 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              # 项目说明
├── index.html             # Docsify 文档入口
├── _sidebar.md            # Docsify 侧边栏
├── CNAME                  # GitHub Pages 域名配置
├── docs/                  # 文档目录
│   ├── README.md         # 文档导航
│   └── source/           # 文档源文件
│       ├── getting-started.md
│       ├── routing-guide.md
│       ├── middleware-guide.md
│       ├── cache-system.md
│       ├── session-management.md
│       ├── wsgi-deployment.md
│       ├── asgi-deployment.md
│       └── ...
├── examples/              # 示例代码
│   ├── 01-hello-world/
│   ├── 02-routing/
│   ├── 03-blog/
│   ├── 04-api-service/
│   ├── 05-fullstack/
│   ├── 06-sqlalchemy/
│   └── 07-streaming/
├── src/litefs/            # 源代码
│   ├── __init__.py
│   ├── core.py
│   ├── routing.py
│   ├── middleware/
│   ├── cache/
│   ├── session/
│   └── ...
└── tests/                 # 测试代码
    ├── unit/
    ├── integration/
    └── performance/

📚 示例代码

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

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

🧪 测试

运行单元测试:

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

运行性能测试:

pytest tests/performance/ -v

查看测试覆盖率:

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 支持!

About

Build a web server framework using Python. Litefs was developed to implement a server framework that can quickly, securely, and flexibly build Web projects. Litefs is a high-performance HTTP server. Litefs has the characteristics of high stability, rich functions, and low system consumption.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages