All Projects → florimondmanca → arel

florimondmanca / arel

Licence: MIT license
Lightweight browser hot reload for Python ASGI web apps

Programming Languages

python
139335 projects - #7 most used programming language
Makefile
30231 projects
Jinja
831 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to arel

fastapi-zeit-now
A simple example of deploying FastAPI as a Zeit Serverless Function
Stars: ✭ 24 (-65.22%)
Mutual labels:  asgi, starlette, fastapi
msgpack-asgi
Drop-in MessagePack support for ASGI applications and frameworks
Stars: ✭ 100 (+44.93%)
Mutual labels:  asgi, starlette, fastapi
inboard
🚢 Docker images and utilities to power your Python APIs and help you ship faster. With support for Uvicorn, Gunicorn, Starlette, and FastAPI.
Stars: ✭ 106 (+53.62%)
Mutual labels:  asgi, starlette, fastapi
serverless-mangum-examples
Example ASGI applications and Serverless Framework configurations using Mangum
Stars: ✭ 26 (-62.32%)
Mutual labels:  asgi, starlette, fastapi
starlette-graphene3
An ASGI app for using Graphene v3 with Starlette / FastAPI
Stars: ✭ 52 (-24.64%)
Mutual labels:  asgi, starlette, fastapi
fastapi-azure-auth
Easy and secure implementation of Azure AD for your FastAPI APIs 🔒 B2C, single- and multi-tenant support.
Stars: ✭ 174 (+152.17%)
Mutual labels:  asgi, fastapi
hypercorn-fastapi-docker
Docker image with Hypercorn for FastAPI apps in Python 3.7, 3.8, 3.9. Ready for HTTP2 and HTTPS
Stars: ✭ 18 (-73.91%)
Mutual labels:  asgi, fastapi
webargs-starlette
Declarative request parsing and validation for Starlette with webargs
Stars: ✭ 36 (-47.83%)
Mutual labels:  asgi, starlette
mongox
Familiar async Python MongoDB ODM
Stars: ✭ 113 (+63.77%)
Mutual labels:  asgi, starlette
spectree
API spec validator and OpenAPI document generator for Python web frameworks.
Stars: ✭ 190 (+175.36%)
Mutual labels:  asgi, starlette
starlette-context
Middleware for Starlette that allows you to store and access the context data of a request. Can be used with logging so logs automatically use request headers such as x-request-id or x-correlation-id.
Stars: ✭ 320 (+363.77%)
Mutual labels:  starlette, fastapi
fastapi-project
FastAPI application without global variables(almost) =)
Stars: ✭ 26 (-62.32%)
Mutual labels:  asgi, fastapi
TikTokDownloader PyWebIO
🚀「Douyin_TikTok_Download_API」是一个开箱即用的高性能异步抖音|TikTok数据爬取工具,支持API调用,在线批量解析及下载。
Stars: ✭ 919 (+1231.88%)
Mutual labels:  asgi, fastapi
starlite
Light, Flexible and Extensible ASGI API framework
Stars: ✭ 1,525 (+2110.14%)
Mutual labels:  asgi, starlette
starlette-opentracing
Opentracing support for Starlette and FastApi
Stars: ✭ 62 (-10.14%)
Mutual labels:  starlette, fastapi
fastAPI-aiohttp-example
How to use and test fastAPI with an aiohttp client
Stars: ✭ 69 (+0%)
Mutual labels:  asgi, fastapi
Fastapi
FastAPI framework, high performance, easy to learn, fast to code, ready for production
Stars: ✭ 39,588 (+57273.91%)
Mutual labels:  starlette, fastapi
Awesome Fastapi
A curated list of awesome things related to FastAPI
Stars: ✭ 3,033 (+4295.65%)
Mutual labels:  starlette, fastapi
async-asgi-testclient
A framework-agnostic library for testing ASGI web applications
Stars: ✭ 123 (+78.26%)
Mutual labels:  asgi, starlette
fastapi-websocket-broadcast
Websocket 'broadcast' demo using FastAPI/Starlette
Stars: ✭ 106 (+53.62%)
Mutual labels:  starlette, fastapi

arel

Build Status Coverage Python versions Package version

Browser hot reload for Python ASGI web apps.

Overview

What is this for?

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.

How does it work?

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.

Installation

pip install 'arel==0.2.*'

Quickstart

For a working example using Starlette, see the Example section.

Although 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:

  1. 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:

    import arel
    
    async def reload_data():
        print("Reloading server data...")
    
    hotreload = arel.HotReload(
        paths=[
            arel.Path("./server/data", on_reload=[reload_data]),
            arel.Path("./server/static"),
        ],
    )
  2. Mount the hot reload endpoint, and register its startup and shutdown event handlers. If using Starlette, this can be done like this:

    from starlette.applications import Starlette
    from starlette.routing import WebSocketRoute
    
    app = Starlette(
        routes=[WebSocketRoute("/hot-reload", hotreload, name="hot-reload")],
        on_startup=[hotreload.startup],
        on_shutdown=[hotreload.shutdown],
    )
  3. Add the JavaScript code to your website HTML. If using Starlette with Jinja templates, you can do this by updating the global environment, then injecting the script into your base template:

    templates.env.globals["DEBUG"] = os.getenv("DEBUG")  # Development flag.
    templates.env.globals["hotreload"] = hotreload
    <body>
      <!-- Page content... -->
    
      <!-- Hot reload script -->
      {% if DEBUG %}
        {{ hotreload.script(url_for('hot-reload')) | safe }}
      {% endif %}
    </body>

Example

The example directory contains an example Markdown-powered website that uses arel to refresh the browser when Markdown content or HTML templates change.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].