livereload


Namelivereload JSON
Version 2.6.3 PyPI version JSON
download
home_pagehttps://github.com/lepture/python-livereload
SummaryPython LiveReload is an awesome tool for web developers
upload_time2020-08-22 15:31:53
maintainer
docs_urlNone
authorHsiaoming Yang
requires_python
licenseBSD
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            LiveReload
==========

This is a brand new LiveReload in version 2.0.0.

`Download on PyPi <https://pypi.python.org/pypi/livereload>`_

Installation
------------

Python LiveReload is designed for web developers who know Python.

Install Python LiveReload with pip::

    $ pip install livereload

If you don't have pip installed, try easy_install::

    $ easy_install livereload

Command Line Interface
----------------------

Python 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 for `LiveReload 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 reloading

.. _`livereload browser extensions`: http://feedback.livereload.com/knowledgebase/articles/86242-how-do-i-install-and-use-the-browser-extensions-

Older versions of Python LiveReload used a ``Guardfile`` to 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 a ``Guardfile`` you can now write a Python script using very similar syntax and run it instead of the command line application.

Script example: Sphinx
----------------------

Here's a simple example script that rebuilds Sphinx documentation:

.. code:: python

    #!/usr/bin/env python
    from livereload import Server, shell
    server = Server()
    server.watch('docs/*.rst', shell('make html', cwd='docs'))
    server.serve(root='docs/_build/html')

Run it, then open http://localhost:5500/ and you can see the documentation changes in real time.

Developer Guide
---------------

The new livereload server is designed for developers. It can power a
wsgi application now:

.. code:: python

    from livereload import Server, shell

    server = Server(wsgi_app)

    # run a shell command
    server.watch('static/*.stylus', 'make static')

    # run a function
    def alert():
        print('foo')
    server.watch('foo.txt', alert)

    # output stdout into a file
    server.watch('style.less', shell('lessc style.less', output='style.css'))

    server.serve()

The ``Server`` class accepts parameters:

- app: a wsgi application
- watcher: a watcher instance, you don't have to create one

server.watch
~~~~~~~~~~~~

``server.watch`` can 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.serve
~~~~~~~~~~~~

Setup a server with ``server.serve`` method. 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')


shell
~~~~~

The powerful ``shell`` function will help you to execute shell commands. You
can use it with ``server.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 Integration
----------------------

Livereload can work seamlessly with your favorite framework.

Django
~~~~~~

For Django there is a management command included.

To use simply

- add ``'livereload'`` to your ``INSTALLED_APPS`` and
- then 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 native ``runserver`` command you have to use `dj-static <https://github.com/kennethreitz/dj-static>`_. (follow the simple instructions there).

Flask
~~~~~

Wrap Flask with livereload is much simpler:

.. code:: python

    # app is a Flask object
    app = create_app()

    # remember to use DEBUG mode for templates auto reload
    # https://github.com/lepture/python-livereload/issues/144
    app.debug = True

    server = Server(app.wsgi_app)
    # server.watch
    server.serve()


Bottle
~~~~~~

Wrap the ``Bottle`` app with livereload server:

.. code:: python

    # Without this line templates won't auto reload because of caching.
    # http://bottlepy.org/docs/dev/tutorial.html#templates
    bottle.debug(True)

    app = Bottle()
    server = Server(app)
    # server.watch
    server.serve()

Security Report
---------------

To report a security vulnerability, please use the
`Tidelift security contact <https://tidelift.com/security>`_.
Tidelift will coordinate the fix and disclosure.
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/lepture/python-livereload",
    "name": "livereload",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Hsiaoming Yang",
    "author_email": "me@lepture.com",
    "download_url": "https://files.pythonhosted.org/packages/bd/60/6640b819e858562ef6684abac60593b7369fe0a8a064df426d3ab0ab894d/livereload-2.6.3.tar.gz",
    "platform": "",
    "description": "LiveReload\n==========\n\nThis is a brand new LiveReload in version 2.0.0.\n\n`Download on PyPi <https://pypi.python.org/pypi/livereload>`_\n\nInstallation\n------------\n\nPython LiveReload is designed for web developers who know Python.\n\nInstall Python LiveReload with pip::\n\n    $ pip install livereload\n\nIf you don't have pip installed, try easy_install::\n\n    $ easy_install livereload\n\nCommand Line Interface\n----------------------\n\nPython LiveReload provides a command line utility, ``livereload``, for starting a server in a directory.\n\nBy default, it will listen to port 35729, the common port for `LiveReload browser extensions`_. ::\n\n    $ livereload --help\n    usage: livereload [-h] [-p PORT] [-w WAIT] [directory]\n\n    Start a `livereload` server\n\n    positional arguments:\n      directory             Directory to watch for changes\n\n    optional arguments:\n      -h, --help            show this help message and exit\n      -p PORT, --port PORT  Port to run `livereload` server on\n      -w WAIT, --wait WAIT  Time delay before reloading\n\n.. _`livereload browser extensions`: http://feedback.livereload.com/knowledgebase/articles/86242-how-do-i-install-and-use-the-browser-extensions-\n\nOlder versions of Python LiveReload used a ``Guardfile`` to 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 a ``Guardfile`` you can now write a Python script using very similar syntax and run it instead of the command line application.\n\nScript example: Sphinx\n----------------------\n\nHere's a simple example script that rebuilds Sphinx documentation:\n\n.. code:: python\n\n    #!/usr/bin/env python\n    from livereload import Server, shell\n    server = Server()\n    server.watch('docs/*.rst', shell('make html', cwd='docs'))\n    server.serve(root='docs/_build/html')\n\nRun it, then open http://localhost:5500/ and you can see the documentation changes in real time.\n\nDeveloper Guide\n---------------\n\nThe new livereload server is designed for developers. It can power a\nwsgi application now:\n\n.. code:: python\n\n    from livereload import Server, shell\n\n    server = Server(wsgi_app)\n\n    # run a shell command\n    server.watch('static/*.stylus', 'make static')\n\n    # run a function\n    def alert():\n        print('foo')\n    server.watch('foo.txt', alert)\n\n    # output stdout into a file\n    server.watch('style.less', shell('lessc style.less', output='style.css'))\n\n    server.serve()\n\nThe ``Server`` class accepts parameters:\n\n- app: a wsgi application\n- watcher: a watcher instance, you don't have to create one\n\nserver.watch\n~~~~~~~~~~~~\n\n``server.watch`` can watch a filepath, a directory and a glob pattern::\n\n    server.watch('path/to/file.txt')\n    server.watch('directory/path/')\n    server.watch('glob/*.pattern')\n\nYou can also use other library (for example: formic) for more powerful\nfile adding::\n\n    for filepath in formic.FileSet(include=\"**.css\"):\n        server.watch(filepath, 'make css')\n\nYou can delay a certain seconds to send the reload signal::\n\n    # delay 2 seconds for reloading\n    server.watch('path/to/file', delay=2)\n\nserver.setHeader\n~~~~~~~~~~~~~~~~\n\n```server.setHeader``` can be used to add one or more headers to the HTTP \nresponse::\n\n    server.setHeader('Access-Control-Allow-Origin', '*')\n    server.setHeader('Access-Control-Allow-Methods', '*')\n\n\nserver.serve\n~~~~~~~~~~~~\n\nSetup a server with ``server.serve`` method. It can create a static server\nand a livereload server::\n\n    # use default settings\n    server.serve()\n\n    # livereload on another port\n    server.serve(liveport=35729)\n\n    # use custom host and port\n    server.serve(port=8080, host='localhost')\n\n    # open the web browser on startup, based on $BROWSER environment variable\n    server.serve(open_url_delay=5, debug=False)\n\n    # set a custom default file to open\n    server.serve(default_filename='example.html')\n\n\nshell\n~~~~~\n\nThe powerful ``shell`` function will help you to execute shell commands. You\ncan use it with ``server.watch``::\n\n    # you can redirect command output to a file\n    server.watch('style.less', shell('lessc style.less', output='style.css'))\n\n    # commands can be a list\n    server.watch('style.less', shell(['lessc', 'style.less'], output='style.css'))\n\n    # working with Makefile\n    server.watch('assets/*.styl', shell('make assets', cwd='assets'))\n\n\nFrameworks Integration\n----------------------\n\nLivereload can work seamlessly with your favorite framework.\n\nDjango\n~~~~~~\n\nFor Django there is a management command included.\n\nTo use simply\n\n- add ``'livereload'`` to your ``INSTALLED_APPS`` and\n- then run ``./manage.py livereload``.\n\nFor available options like host and ports please refer to ``./manage.py livereload -h``.\n\nTo automagically serve static files like the native ``runserver`` command you have to use `dj-static <https://github.com/kennethreitz/dj-static>`_. (follow the simple instructions there).\n\nFlask\n~~~~~\n\nWrap Flask with livereload is much simpler:\n\n.. code:: python\n\n    # app is a Flask object\n    app = create_app()\n\n    # remember to use DEBUG mode for templates auto reload\n    # https://github.com/lepture/python-livereload/issues/144\n    app.debug = True\n\n    server = Server(app.wsgi_app)\n    # server.watch\n    server.serve()\n\n\nBottle\n~~~~~~\n\nWrap the ``Bottle`` app with livereload server:\n\n.. code:: python\n\n    # Without this line templates won't auto reload because of caching.\n    # http://bottlepy.org/docs/dev/tutorial.html#templates\n    bottle.debug(True)\n\n    app = Bottle()\n    server = Server(app)\n    # server.watch\n    server.serve()\n\nSecurity Report\n---------------\n\nTo report a security vulnerability, please use the\n`Tidelift security contact <https://tidelift.com/security>`_.\nTidelift will coordinate the fix and disclosure.",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "Python LiveReload is an awesome tool for web developers",
    "version": "2.6.3",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "4b68646bf76c7be88f584dfe04288a91",
                "sha256": "776f2f865e59fde56490a56bcc6773b6917366bce0c267c60ee8aaf1a0959869"
            },
            "downloads": -1,
            "filename": "livereload-2.6.3.tar.gz",
            "has_sig": false,
            "md5_digest": "4b68646bf76c7be88f584dfe04288a91",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 25199,
            "upload_time": "2020-08-22T15:31:53",
            "upload_time_iso_8601": "2020-08-22T15:31:53.202849Z",
            "url": "https://files.pythonhosted.org/packages/bd/60/6640b819e858562ef6684abac60593b7369fe0a8a064df426d3ab0ab894d/livereload-2.6.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-08-22 15:31:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "lepture",
    "github_project": "python-livereload",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "livereload"
}
        
Elapsed time: 0.01239s