Python LiveReload
Python LiveReload is a tool for web developers that automatically reloads webpages in the browser when file changes are detected. It provides a WSGI-compatible server and a command-line utility, focusing on simple, real-time feedback during development. The current version is 2.7.1, with a release cadence that includes bug fixes and minor enhancements.
Warnings
- breaking The `Guardfile` configuration method was removed in version 2.0.0. Older setups relying on a `Guardfile` will no longer work.
- gotcha When watching a large number of files, or during a build process that generates many files, `livereload` can trigger excessive reloads and high CPU usage.
- gotcha `livereload` internally uses `Tornado`'s IOLoop. Improper integration with existing `Tornado` applications or other async loops can lead to issues, especially around the loop's lifecycle.
- gotcha While a command-line interface (`livereload` command) is available, it's recommended to use the Python API for more advanced or custom watching scenarios, especially since the removal of `Guardfile`.
- gotcha When running behind a reverse proxy, particularly with HTTPS, the `livereload.js` client might attempt to connect via `ws://` instead of `wss://`, leading to connection errors.
Install
-
pip install livereload
Imports
- Server
from livereload import Server
- shell
from livereload import shell
Quickstart
import os
from livereload import Server, shell
# Create a dummy index.html for demonstration
with open('index.html', 'w') as f:
f.write('<!DOCTYPE html>\n<html><head><title>LiveReload Test</title></head><body><h1>Hello, LiveReload!</h1></body></html>')
server = Server()
server.watch('*.html')
server.serve(open_url_delay=1)