{"id":13501289,"url":"https://github.com/florimondmanca/arel","last_synced_at":"2025-04-05T15:05:19.176Z","repository":{"id":38436739,"uuid":"252835840","full_name":"florimondmanca/arel","owner":"florimondmanca","description":"Lightweight browser hot reload for Python ASGI web apps","archived":false,"fork":false,"pushed_at":"2024-04-26T12:41:50.000Z","size":74,"stargazers_count":151,"open_issues_count":6,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-29T14:06:34.864Z","etag":null,"topics":["asgi","browser","fastapi","hot-reload","python","starlette","websockets"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/arel","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/florimondmanca.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-03T20:39:06.000Z","updated_at":"2025-02-14T21:41:07.000Z","dependencies_parsed_at":"2024-01-16T10:35:22.727Z","dependency_job_id":"a47f63f3-7f17-4b34-b3f7-98eb4c781843","html_url":"https://github.com/florimondmanca/arel","commit_stats":{"total_commits":35,"total_committers":5,"mean_commits":7.0,"dds":0.2571428571428571,"last_synced_commit":"379017868dd0856f867413df6dceff02e79a54b7"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/florimondmanca%2Farel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/florimondmanca%2Farel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/florimondmanca%2Farel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/florimondmanca%2Farel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/florimondmanca","download_url":"https://codeload.github.com/florimondmanca/arel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247353729,"owners_count":20925329,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asgi","browser","fastapi","hot-reload","python","starlette","websockets"],"created_at":"2024-07-31T22:01:31.749Z","updated_at":"2025-04-05T15:05:19.144Z","avatar_url":"https://github.com/florimondmanca.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# arel\n\n[![Build Status](https://dev.azure.com/florimondmanca/public/_apis/build/status/florimondmanca.arel?branchName=master)](https://dev.azure.com/florimondmanca/public/_build/latest?definitionId=6\u0026branchName=master)\n[![Coverage](https://codecov.io/gh/florimondmanca/arel/branch/master/graph/badge.svg)](https://codecov.io/gh/florimondmanca/arel)\n![Python versions](https://img.shields.io/pypi/pyversions/arel.svg)\n[![Package version](https://badge.fury.io/py/arel.svg)](https://pypi.org/project/arel)\n\nBrowser hot reload for Python ASGI web apps.\n\n![](https://media.githubusercontent.com/media/florimondmanca/arel/master/docs/demo.gif)\n\n## Overview\n\n**What is this for?**\n\n`arel` can be used to implement development-only hot-reload for non-Python files that are not read from disk on each request. This may include HTML templates, GraphQL schemas, cached rendered Markdown content, etc.\n\n**How does it work?**\n\n`arel` watches changes over a set of files. When a file changes, `arel` notifies the browser (using WebSocket), and an injected client script triggers a page reload. You can register your own reload hooks for any extra server-side operations, such as reloading cached content or re-initializing other server-side resources.\n\n## Installation\n\n```bash\npip install 'arel==0.3.*'\n```\n\n## Quickstart\n\n_For a working example using Starlette, see the [Example](#example) section._\n\nAlthough the exact instructions to set up hot reload with `arel` depend on the specifics of your ASGI framework, there are three general steps to follow:\n\n1. Create an `HotReload` instance, passing one or more directories of files to watch, and optionally a list of callbacks to call before a reload is triggered:\n\n   ```python\n   import arel\n\n   async def reload_data():\n       print(\"Reloading server data...\")\n\n   hotreload = arel.HotReload(\n       paths=[\n           arel.Path(\"./server/data\", on_reload=[reload_data]),\n           arel.Path(\"./server/static\"),\n       ],\n   )\n   ```\n\n2. Mount the hot reload endpoint, and register its startup and shutdown event handlers. If using Starlette, this can be done like this:\n\n   ```python\n   from starlette.applications import Starlette\n   from starlette.routing import WebSocketRoute\n\n   app = Starlette(\n       routes=[WebSocketRoute(\"/hot-reload\", hotreload, name=\"hot-reload\")],\n       on_startup=[hotreload.startup],\n       on_shutdown=[hotreload.shutdown],\n   )\n   ```\n\n3. Add the JavaScript code to your website HTML. If using [Starlette with Jinja templates](https://www.starlette.io/templates/), you can do this by updating the global environment, then injecting the script into your base template:\n\n   ```python\n   templates.env.globals[\"DEBUG\"] = os.getenv(\"DEBUG\")  # Development flag.\n   templates.env.globals[\"hotreload\"] = hotreload\n   ```\n\n   ```jinja\n   \u003cbody\u003e\n     \u003c!-- Page content... --\u003e\n\n     \u003c!-- Hot reload script --\u003e\n     {% if DEBUG %}\n       {{ hotreload.script(url_for('hot-reload')) | safe }}\n     {% endif %}\n   \u003c/body\u003e\n   ```\n\n## Example\n\nThe [`example` directory](https://github.com/florimondmanca/arel/tree/master/example) contains an example Markdown-powered website that uses `arel` to refresh the browser when Markdown content or HTML templates change.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflorimondmanca%2Farel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflorimondmanca%2Farel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflorimondmanca%2Farel/lists"}