Litefs is a lite python web framework.
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.
- High-performance HTTP server with epoll and greenlet
- WSGI 1.0 compliant (PEP 3333)
- Support for Gunicorn, uWSGI, Waitress, and other WSGI servers
- Static file serving with gzip/deflate compression
- Mako template engine support
- CGI script execution (.pl, .py, .php)
- Session management
- Multi-level caching system (Memory + Tree cache + Redis)
- File monitoring and hot reload
- Python 2.6-3.14 support
- Enhanced request handling with separated query and post parameters
- Comprehensive form validation system
- Beautiful error pages with customization support
- Flexible cache backend selection (Memory, Tree, Redis)
pip install litefsOr install from source:
git clone https://github.com/leafcoder/litefs.git
cd litefs
pip install -r requirements.txt
python setup.py installLitefs provides powerful CLI tools for quick project creation and development.
Create a new project:
litefs startproject myapp
cd myappStart development server:
litefs runserverShow version:
litefs versionFor detailed CLI usage, see CLI Tools Documentation.
import litefs
litefs.test_server()Or from command line:
litefs --host localhost --port 9090 --webroot ./siteLitefs now supports WSGI deployment with Gunicorn, uWSGI, and other WSGI servers.
Create wsgi_example.py:
import litefs
app = litefs.Litefs(webroot='./site')
application = app.wsgi()Deploy with Gunicorn:
gunicorn -w 4 -b :8000 wsgi_example:applicationDeploy with uWSGI:
uwsgi --http :8000 --wsgi-file wsgi_example.pyDeploy with Waitress (Windows):
waitress-serve --port=8000 wsgi_example:applicationFor detailed deployment instructions, see WSGI_DEPLOYMENT.md.
Litefs now uses centralized version management with version control tools. Version information is stored in src/litefs/_version.py and can be automatically managed through Git tags and build tools.
Litefs provides enhanced request handling with separated query and post parameters:
import litefs
app = litefs.Litefs(webroot='./site')
def handler(request):
# Access query parameters
query = request.query
page = query.get('page', 1)
# Access post parameters
post = request.post
username = post.get('username')
return {"page": page, "username": username}Litefs includes a comprehensive form validation system with multiple validators:
from litefs import (
required, string_type, number_type, email, url, choice, regex,
EnhancedRequestHandler, ValidationError
)
def handler(request):
enhanced = EnhancedRequestHandler(request)
# Validate query parameters
query_rules = {
"page": [number_type(min_value=1, max_value=100)],
"sort": [choice(["asc", "desc"])],
}
# Validate post parameters
post_rules = {
"username": [required(), string_type(min_length=3, max_length=20)],
"email": [required(), email()],
"age": [number_type(min_value=0, max_value=120)],
}
is_valid, errors = enhanced.validate_all(query_rules, post_rules)
if not is_valid:
return {"errors": errors}
return {"success": True}Litefs supports multiple cache backends that can be configured:
import litefs
# Memory cache (default)
app = litefs.Litefs(
webroot='./site',
cache_backend='memory',
cache_max_size=10000
)
# Tree cache
app = litefs.Litefs(
webroot='./site',
cache_backend='tree',
cache_expiration_time=3600,
cache_clean_period=60
)
# Redis cache
app = litefs.Litefs(
webroot='./site',
cache_backend='redis',
redis_host='localhost',
redis_port=6379,
redis_db=0,
redis_key_prefix='litefs:',
cache_expiration_time=3600
)Litefs provides beautiful default error pages and supports custom error pages:
import litefs
# Use default error pages
app = litefs.Litefs(webroot='./site')
# Use custom error pages
app = litefs.Litefs(
webroot='./site',
error_pages_dir='./error_pages'
)Create custom error pages in ./error_pages/ directory:
400.html- Bad Request403.html- Forbidden404.html- Not Found500.html- Internal Server Error502.html- Bad Gateway503.html- Service Unavailable504.html- Gateway Timeout
litefs/
├── litefs.py # Core module
├── setup.py # Installation configuration
├── requirements.txt # Dependencies
├── wsgi_example.py # WSGI example
├── demo/ # Example code
│ ├── site/ # Example website
│ └── example.py # Example startup script
├── test/ # Test code
└── docs/ # Documentation
Complete documentation is available at docs/:
- 在线文档 - Online documentation (Sphinx)
- 示例 - Complete examples with organized modules
- CLI 工具 - Command line tools guide
- API 文档 - Complete API reference
- 配置管理 - Configuration management guide
- 健康检查 - Health check features
- 中间件指南 - Middleware development guide
- WSGI 部署 - WSGI deployment guide
- WSGI 实现 - WSGI implementation details
- 单元测试 - Unit testing documentation
- 性能和压力测试 - Performance and stress testing
- 改进分析 - Project improvement analysis
- 测试指南 - Testing guide
- Linux 服务器指南 - Linux deployment guide
- 开发指南 - Development guide
- 项目结构 - Project structure
- 待办事项 - Planned features
- Bug 修复 - Bug fixes record
Litefs 提供了丰富的示例,按照功能模块组织,帮助您快速上手和深入学习:
- 01-quickstart - 快速入门示例
- 02-basic-handlers - 基础处理器示例
- 03-configuration - 配置管理示例
- 04-middleware - 中间件使用示例
- 05-session - 会话管理示例
- 06-cache - 缓存使用示例
- 07-health-check - 健康检查示例
- 08-wsgi-deployment - WSGI 部署示例
- 09-fullstack - 完整应用示例
每个示例都包含详细的 README 文档和可运行的代码,请参考 examples/README.md 了解更多。
使用 Sphinx 构建文档:
make docs-build查看文档:
make docs-serve访问 http://localhost:8000 查看文档。
MIT License - see LICENSE for details.