Skip to main content

Build a web server framework using Python.

Project description

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 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.

Features

  • 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 3.8-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)

Quick Start

Installation

pip install litefs

Or install from source:

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

Basic Usage

CLI Tools

Litefs provides powerful CLI tools for quick project creation and development.

Create a new project:

litefs startproject myapp
cd myapp

Start development server:

litefs runserver

Show version:

litefs version

For detailed CLI usage, see CLI Tools Documentation.

Standalone Server

import litefs
litefs.test_server()

Or from command line:

litefs --host localhost --port 9090 --webroot ./site

WSGI Deployment

Litefs 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:application

Deploy with uWSGI:

uwsgi --http :8000 --wsgi-file wsgi_example.py

Deploy with Waitress (Windows):

waitress-serve --port=8000 wsgi_example:application

For detailed deployment instructions, see WSGI_DEPLOYMENT.md.

New Features

Version Management

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.

Enhanced Request Handling

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}

Form Validation

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}

Cache Backend Selection

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
)

Custom Error Pages

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 Request
  • 403.html - Forbidden
  • 404.html - Not Found
  • 500.html - Internal Server Error
  • 502.html - Bad Gateway
  • 503.html - Service Unavailable
  • 504.html - Gateway Timeout

Project Structure

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

Documentation

Complete documentation is available at docs/:

示例

Litefs 提供了丰富的示例,按照功能模块组织,帮助您快速上手和深入学习:

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

构建文档

使用 Sphinx 构建文档:

make docs-build

查看文档:

make docs-serve

访问 http://localhost:8000 查看文档。

License

MIT License - see LICENSE for details.

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

litefs-0.5.0.tar.gz (737.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

litefs-0.5.0-py3-none-any.whl (109.9 kB view details)

Uploaded Python 3

File details

Details for the file litefs-0.5.0.tar.gz.

File metadata

  • Download URL: litefs-0.5.0.tar.gz
  • Upload date:
  • Size: 737.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.9

File hashes

Hashes for litefs-0.5.0.tar.gz
Algorithm Hash digest
SHA256 7a0d88564fa7b70cd6ef3a01f7a14d1613fb590fd68231591901f43c625ce271
MD5 6ed4914924fd7d55ade7f25966bfa7d3
BLAKE2b-256 4e8294e4a20a61c0aed960801064f43b37bd25e98cd3284d239a31b2195c6798

See more details on using hashes here.

File details

Details for the file litefs-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: litefs-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 109.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.9

File hashes

Hashes for litefs-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cadd21680504024d5f17bcc0b636d215a80a9b255dd9b6acdc5e4845b0835349
MD5 3c898688a1ab8b3cb698bb2963fe6aa5
BLAKE2b-256 e0e8ecd73b9b07a76d87ec004d405e50cbc82467f8539fd4df8a914a3307b9f8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page