Skip to main content

Rizzler

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

Installation

Install with the recommended Jinja2 engine:

pip install "rizzler[jinja2]"

Or use MiniJinja engine powered by Rust 🦀:

pip install "rizzler[minijinja]"

Usage

Integrate with lifespan protocol.

from collections.abc import AsyncIterator
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.requests import Request
from fastapi.responses import HTMLResponse
from rizzler import RizzleTemplates, Rizzler

@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(request, "index.html")

Templating

RizzleTemplates supports Jinja2 and MiniJinja. MiniJinja is selected when it is installed; otherwise, the Jinja2 backend is used. Both backends expose two Vite helpers that can be placed in an HTML template as follows:

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

Build

You can run the following command once you are done customizing the front-end code under pages/ directory to your liking.

rzl build
Example outputs for `rzl build`
$ rzl build
> INFO     ⚡Building Rizzler front-end…
> INFO
> INFO     > rzl-tmp@0.0.0 build /Users/user/workspaces/rzl-react
> INFO     > vite build                                       
> INFO                                                       
> INFO     vite v5.3.3 building for production...           
> INFO     transforming...                                 
> INFO     ✓ 32 modules transformed.                      
> INFO     rendering chunks...                           
> INFO     computing gzip size...                       
> INFO     dist/rizz.svg    4.13 kB │ gzip:  2.14 kB   
> INFO     dist/rizz.css    1.39 kB │ gzip:  0.72 kB  
> INFO     dist/rizz.js   142.63 kB │ gzip: 45.74 kB 
> INFO     ✓ built in 390ms

Now you can stop using RizzleTemplates and revert back to serving front-end with Jinja2Templates as such

#!/usr/bin/env python3
from fastapi import FastAPI
from fastapi.requests import Request
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates

app = FastAPI()
templates = Jinja2Templates(directory="dist")

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

app.mount("/", StaticFiles(directory="dist"), name="dist")

Now you have a production front-end to go with your FastAPI application when you need. There will probably be bugs when it comes to relative versus absolute paths in the future. But this is good enough for many prototyping use-case and with a bit of tinkering, can replace

Dependencies and Disclosures

This library relies on the following Python dependencies.

  • click - Python composable command line interface toolkit GitHub PyPI Docs
  • jinja2 - A very fast and expressive template engine GitHub PyPI Docs
  • minijinja - A Jinja-compatible template engine implemented in Rust GitHub PyPI
  • markupsafe - Safely add untrusted strings to HTML/XML markup GitHub PyPI Docs
  • pydantic - Data validation using Python type hints GitHub PyPI Docs
  • PyYAML - Full-featured YAML framework for the Python GitHub PyPI Docs
  • rich - Rich text and beautiful formatting in the terminal GitHub PyPI Docs
  • starlette - Lightweight ASGI framework / toolkit GitHub PyPI Docs
  • tree-sitter - An incremental parsing system for programming tools GitHub PyPI Docs
    • tree-sitter-html GitHub PyPI
    • tree-sitter-javascript GitHub PyPI

Contributions

Prerequisites

I recommend using uv as the preferred tool to managing dependencies and virtual environment in your development workflow.

  • uv - An extremely fast Python package and project manager, written in Rust. GitHub PyPI Uv

Setup development environment

To contribute to the project, fork the repository and clone to your local device and development dependencies including four extra libraries not included in final builds as such: Alternatively, run the following command on your terminal to do so:

uv sync --dev
  • ruff An extremely fast Python linter and code formatter, written in Rust. GitHub PyPI Docs

Acknowledgements

License

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

Metadata

Release files for rizzler 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rizzler 0.2.1
File Size Uploaded
rizzler-0.2.1.tar.gz 615.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rizzler 0.2.1
File Interpreter ABI Platform
rizzler-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 638.7 kB

Release files / rizzler-0.2.1.tar.gz

Download URL rizzler-0.2.1.tar.gz
Size 615.9 kB
Tags Source
SHA-256 checksum
How to use checksums
21753e5bbc70ced67fb256e529b3b1c1a7bc66d14c686cf18c5064ae25e50abe
BLAKE2b-256 checksum
How to use checksums
0af11af313e64e3c99cbac688a550d5419690b318163f25104fed03fa04e8939
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.20

Release files / rizzler-0.2.1-py3-none-any.whl

Download URL rizzler-0.2.1-py3-none-any.whl
Size 22.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
23f05d9aaaf2138ce34dd554f613ed465e843246c6ab9c77edfa11e994f78b93
BLAKE2b-256 checksum
How to use checksums
747f17447461fe6d77529ff48a105170448fe128283ece672cbcd2a9110cd04c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.20

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

1 release file

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page