rizzler

Rizzler creates a parallel front-end dev-server using ViteJS for ASGI Frameworks


Keywords
asgi, blacksheep, fastapi, hmr, javascript, litestar, node, npm, pnpm, quart, sanic, starlette, uvicorn, vite
License
MIT
Install
pip install rizzler==0.1.6

Documentation

Rizzler

Package vesion Format Python version License Code size Top Languages Repository size Last commit Rizzler Banner

Installation

Install using pip

$ pip install rizzler
> ...

Usage

Integrate with lifespan protocol.

from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.requests impor Request
from fastapi.responses import HTMLResponse
from rizzler import RizzleTemplates, Rizzler
from typing import AsyncIterator, List, Tuple

@Rizzler.load_config
def rizzler_settings() -> List[Tuple[str, str]]:
  return [
    ("command", "pnpm"),
    ("framework", "vue")
  ]

@asynccontextmanager
async def lifespan(_: FastAPI) -> AsyncIterator[None, None]:
  await Rizzler.serve()
  yield
  Rizzler.shutdown()

app: FastAPI = FastAPI(lifespan=lifespan)
templates: RizzleTemplates = RizzleTemplates(directory="templates")

@app.get("/", response_class=HTMLResponse)
async def index(request: Request) -> HTMLResponse:
  return templates.TemplateResponse("index.html", {"request": request})

Templating

RizzleTemplates is an extension on top of Jinja2Templates class found under starlette However, has two overriding methods that must be placed inside the template HTML-file as such:

<!DOCTYPE html>
<html>
  <head><!-- ... --></head>
  <body>
    {{ vite_hmr_client() }}
    {{ vite_asset('pages/main.js') }}
  </body>
</html>

Build

This section talks about how to use Jinja2Templates in place of RizzleTemplates for built assets from the vite build command inside package.json.

To be determined.

Contributions

To be determined.

Acknowledgements

License

This project is licensed under the terms of the MIT license.