CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-livereload

Python LiveReload server that automatically reloads web pages when source files change

Pending
Overview
Eval results
Files

LiveReload

A Python implementation of LiveReload functionality that automatically reloads web pages when source files change. It provides a tornado-based development server with file watching capabilities, enabling rapid web development workflows without manual browser refreshing.

Package Information

  • Package Name: livereload
  • Language: Python
  • Installation: pip install livereload
  • Dependencies: tornado

Core Imports

from livereload import Server, shell

Alternative server-only import:

from livereload import Server

Advanced imports for custom handlers:

from livereload.handlers import LiveReloadHandler, StaticFileHandler
from livereload.watcher import get_watcher_class, Watcher

Basic Usage

Simple File Watching Server

from livereload import Server

# Create a server instance
server = Server()

# Watch current directory for changes
server.watch('.')

# Start serving on default port 5500
server.serve()

Server with Shell Command Integration

from livereload import Server, shell

server = Server()

# Watch LESS files and compile them when changed
server.watch('styles/*.less', shell('lessc styles/main.less styles/main.css'))

# Watch Python files and restart server
server.watch('*.py')

# Serve with custom configuration
server.serve(port=8000, host='0.0.0.0', open_url_delay=1)

Command Line Usage

# Serve current directory with live reload
livereload

# Serve specific directory on custom port
livereload --port 8080 /path/to/project

# Watch specific files with custom delay
livereload --target "*.css" --wait 0.5

Architecture

LiveReload consists of several key components:

  • Server: Main class managing HTTP serving, WebSocket connections, and file watching coordination
  • Watcher: File system monitoring with cross-platform support (polling + Linux inotify)
  • Handlers: Tornado-based HTTP/WebSocket handlers for browser communication and static file serving
  • Shell Integration: Command execution system for build tools and preprocessors
  • CLI/Django Integration: Command-line tools and Django management command

Capabilities

Server Management

Core server functionality including HTTP serving, WebSocket communication, and development server features with support for custom headers, debug modes, and automatic browser opening.

class Server:
    def __init__(self, app=None, watcher=None): ...
    def serve(self, port=5500, liveport=None, host=None, root=None, debug=None, 
              open_url=False, restart_delay=2, open_url_delay=None, 
              live_css=True, default_filename='index.html'): ...
    def watch(self, filepath, func=None, delay=None, ignore=None): ...
    def setHeader(self, name, value): ...

Server Management

File Watching System

Cross-platform file system monitoring with support for files, directories, and glob patterns. Includes polling-based fallback and Linux inotify optimization for efficient change detection.

class Watcher:
    def __init__(self): ...
    def watch(self, path, func=None, delay=0, ignore=None): ...
    def is_changed(self, path, ignore=None): ...
    def start(self, callback): ...

def get_watcher_class(): ...

File Watching

Shell Command Integration

Execute shell commands as file change callbacks with support for build tools, preprocessors, and custom development workflows.

def shell(cmd, output=None, mode='w', cwd=None, shell=False): ...

Shell Integration

Command Line Interface and Framework Integration

Command-line tool for quick development server setup and Django framework integration for seamless development workflow.

def main(argv=None): ...

class Command(BaseCommand):
    def handle(self, *args, **options): ...

CLI and Integrations

Types

Common parameter types used throughout the LiveReload API:

# File change callback function
def callback_function():
    """Callback function invoked when file changes are detected."""
    pass

# Path specifications (files, directories, or glob patterns)  
path_spec = "file.py"           # Single file
path_spec = "directory/"        # Directory
path_spec = "**/*.css"          # Glob pattern

# Ignore function for filtering files
def ignore_function(filename):
    """
    Custom function to determine which files should be ignored.
    
    Args:
        filename (str): File name to check
        
    Returns:
        bool: True if file should be ignored, False otherwise
    """
    return filename.endswith('.tmp')

Install with Tessl CLI

npx tessl i tessl/pypi-livereload
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/livereload@2.7.x
Publish Source
CLI
Badge
tessl/pypi-livereload badge