Skip to main content

Automatic browser reload plugin for Litestar, designed for development use.

Project description

litestar-browser-reload

PyPI - Version PyPI - Python Version


[!IMPORTANT] This plugin currently contains minimal features and is a work-in-progress

Automatic browser reload plugin for Litestar, designed for development use.

Table of Contents

Installation

pip install litestar-browser-reload

Usage

Parameters of BrowserReloadPlugin:

  • watch_paths: Sequence[Union[str, Path]]: Paths to watch for changes.
  • watch_filter: BaseFilter | None = None: A filter to exclude certain directories or patterns.
from pathlib import Path

from litestar import Litestar
from litestar.contrib.jinja import JinjaTemplateEngine
from litestar.template.config import TemplateConfig
from litestar_browser_reload import BrowserReloadPlugin
from watchfiles import DefaultFilter

templates_path = Path("templates")
browser_reload = BrowserReloadPlugin(
    watch_paths=(Path("templates"),),
    watch_filter=DefaultFilter(ignore_dirs=(".git", ".hg", ".svn", ".tox")),
)

app = Litestar(
    route_handlers=[],
    debug=True,
    plugins=[browser_reload],
    template_config=TemplateConfig(
        directory=templates_path,
        engine=JinjaTemplateEngine,
    ),
)

Add the following to your base template:

<head>
    ...
    {% if request.app.debug %}
    <script
        src="/__reload__/static/reload-listener.js"
        data-worker-script-path="/__reload__/static/reload-worker.js"
        data-ws-path="/__reload__"
        defer
    ></script>
    {% endif %}
 </head>

License

litestar-browser-reload is distributed under the terms of the MIT license.

Credits

Much of this was copied from django-browser-reload and foxglove

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

litestar_browser_reload-0.3.0.tar.gz (83.0 kB view details)

Uploaded Source

Built Distribution

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

litestar_browser_reload-0.3.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file litestar_browser_reload-0.3.0.tar.gz.

File metadata

File hashes

Hashes for litestar_browser_reload-0.3.0.tar.gz
Algorithm Hash digest
SHA256 85fa3dab9ed9d00a2f6a880914e1184fa5553812728c47cb20e42a489c1f14c7
MD5 f0fa632a9486e302240b4580d274edff
BLAKE2b-256 f79b6cdc16dfba59732ef87ced9aceba9be839c0d250e8a7a7136ae6df124726

See more details on using hashes here.

File details

Details for the file litestar_browser_reload-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for litestar_browser_reload-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 379c59973711d7ce8c75f09789b779684973b982f119c76fa29b2543127ea242
MD5 79dbde54d2b70750720786791557a664
BLAKE2b-256 fca2b7051a7d2382adade95a29bcd597a6971123b33d783bcf9e548a2f3d8fb0

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