Package: livereload
This is a brand new LiveReload in version 2.0.0.Download on PyPiInstallationPython LiveReload is designed for web developers who know Python.Install Python LiveReload with pip:$ pip install livereloadIf you don’t have pip installed, try easy_install:$ easy_install livereloadCommand Line InterfacePython LiveReload provides a command line utility,livereload, for starting a server in a directory.By default, it will listen to port 35729, the common port forLiveReload browser extensions.$ livereload --help
usage: livereload [-h] [-p PORT] [-w WAIT] [directory]

Start a `livereload` server

positional arguments:
  directory             Directory to watch for changes

optional arguments:
  -h, --help            show this help message and exit
  -p PORT, --port PORT  Port to run `livereload` server on
  -w WAIT, --wait WAIT  Time delay before reloadingOlder versions of Python LiveReload used aGuardfileto describe optional additional rules for files to watch and build commands to run on changes.  This conflicted with other tools that used the same file for their configuration and is no longer supported since Python LiveReload version 2.0.0.  Instead of aGuardfileyou can now write a Python script using very similar syntax and run it instead of the command line application.Script example: SphinxHere’s a simple example script that rebuilds Sphinx documentation:#!/usr/bin/env pythonfromlivereloadimportServer,shellserver=Server()server.watch('docs/*.rst',shell('make html',cwd='docs'))server.serve(root='docs/_build/html')Run it, then openhttp://localhost:5500/and you can see the documentation changes in real time.Developer GuideThe new livereload server is designed for developers. It can power a
wsgi application now:fromlivereloadimportServer,shellserver=Server(wsgi_app)# run a shell commandserver.watch('static/*.stylus','make static')# run a functiondefalert():print('foo')server.watch('foo.txt',alert)# output stdout into a fileserver.watch('style.less',shell('lessc style.less',output='style.css'))server.serve()TheServerclass accepts parameters:app: a wsgi applicationwatcher: a watcher instance, you don’t have to create oneserver.watchserver.watchcan watch a filepath, a directory and a glob pattern:server.watch('path/to/file.txt')
server.watch('directory/path/')
server.watch('glob/*.pattern')You can also use other library (for example: formic) for more powerful
file adding:for filepath in formic.FileSet(include="**.css"):
    server.watch(filepath, 'make css')You can delay a certain seconds to send the reload signal:# delay 2 seconds for reloading
server.watch('path/to/file', delay=2)server.setHeader`server.setHeader`can be used to add one or more headers to the HTTP
response:server.setHeader('Access-Control-Allow-Origin', '*')
server.setHeader('Access-Control-Allow-Methods', '*')server.serveSetup a server withserver.servemethod. It can create a static server
and a livereload server:# use default settings
server.serve()

# livereload on another port
server.serve(liveport=35729)

# use custom host and port
server.serve(port=8080, host='localhost')

# open the web browser on startup, based on $BROWSER environment variable
server.serve(open_url_delay=5, debug=False)

# set a custom default file to open
server.serve(default_filename='example.html')shellThe powerfulshellfunction will help you to execute shell commands. You
can use it withserver.watch:# you can redirect command output to a file
server.watch('style.less', shell('lessc style.less', output='style.css'))

# commands can be a list
server.watch('style.less', shell(['lessc', 'style.less'], output='style.css'))

# working with Makefile
server.watch('assets/*.styl', shell('make assets', cwd='assets'))Frameworks IntegrationLivereload can work seamlessly with your favorite framework.DjangoFor Django there is a management command included.To use simplyadd'livereload'to yourINSTALLED_APPSandthen run./manage.py livereload.For available options like host and ports please refer to./manage.py livereload-h.To automagically serve static files like the nativerunservercommand you have to usedj-static. (follow the simple instructions there).FlaskWrap Flask with livereload is much simpler:# app is a Flask objectapp=create_app()# remember to use DEBUG mode for templates auto reload# https://github.com/lepture/python-livereload/issues/144app.debug=Trueserver=Server(app.wsgi_app)# server.watchserver.serve()BottleWrap theBottleapp with livereload server:# Without this line templates won't auto reload because of caching.# http://bottlepy.org/docs/dev/tutorial.html#templatesbottle.debug(True)app=Bottle()server=Server(app)# server.watchserver.serve()Security ReportTo report a security vulnerability, please use theTidelift security contact.
Tidelift will coordinate the fix and disclosure.