rizzler


Namerizzler JSON
Version 0.1.9 PyPI version JSON
download
home_pagehttps://github.com/aekasitt/rizzler
SummaryRizzler creates a parallel front-end dev-server using ViteJS for ASGI Frameworks
upload_time2024-07-10 09:39:28
maintainerNone
docs_urlNone
authorSitt Guruvanich
requires_python<4.0,>=3.9
licenseMIT
keywords asgi blacksheep fastapi hmr javascript litestar node npm pnpm quart sanic starlette uvicorn vite
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Rizzler

[![Package vesion](https://img.shields.io/pypi/v/rizzler)](https://pypi.org/project/rizzler)
[![Format](https://img.shields.io/pypi/format/rizzler)](https://pypi.org/project/rizzler)
[![Python version](https://img.shields.io/pypi/pyversions/rizzler)](https://pypi.org/project/rizzler)
[![License](https://img.shields.io/pypi/l/rizzler)](https://pypi.org/project/rizzler)
[![Code size](https://img.shields.io/github/languages/code-size/aekasitt/rizzler)](.)
[![Top](https://img.shields.io/github/languages/top/aekasitt/rizzler)](.)
[![Languages](https://img.shields.io/github/languages/count/aekasitt/rizzler)](.)
[![Repository size](https://img.shields.io/github/repo-size/aekasitt/rizzler)](.)
[![Last commit](https://img.shields.io/github/last-commit/aekasitt/rizzler/master)](.)
[![Rizzler Banner](./static/rizzler-banner.svg)](https://github.com/aekasitt/rizzler/blob/master/static/rizzler-banner.svg)

## Installation

Install using pip

```sh
$ pip install rizzler
> ...
```

## Usage

Integrate with `lifespan` protocol.

```python
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](starlette.io)
However, has two overriding methods that must be placed inside the template HTML-file as such:

```html
<!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.

```sh
rzl build
```

<details>
  <summary>Example outputs for `rzl build`</summary>

  ```sh
  $ rzl build
  > INFO     ⚡Building Rizzler front-end…
  > INFO
  > INFO     > rzl-tmp@0.0.0 build /Users/mackasitt/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
  ```
</details>

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

```python
#!/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")
```

Voila! 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 

## Contributions

To be determined.

## Acknowledgements

* [fastapi-vite](https://github.com/cofin/fastapi-vite)
* [django-vite](https://github.com/MrBin99/django-vite)

## License

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

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/aekasitt/rizzler",
    "name": "rizzler",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": "asgi, blacksheep, fastapi, hmr, javascript, litestar, node, npm, pnpm, quart, sanic, starlette, uvicorn, vite",
    "author": "Sitt Guruvanich",
    "author_email": "aekazitt+github@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/b0/2f/a9f990ad6b5a4730c5b31716a439b54b7376e9c4d37fafbb51b0c818563e/rizzler-0.1.9.tar.gz",
    "platform": null,
    "description": "# Rizzler\n\n[![Package vesion](https://img.shields.io/pypi/v/rizzler)](https://pypi.org/project/rizzler)\n[![Format](https://img.shields.io/pypi/format/rizzler)](https://pypi.org/project/rizzler)\n[![Python version](https://img.shields.io/pypi/pyversions/rizzler)](https://pypi.org/project/rizzler)\n[![License](https://img.shields.io/pypi/l/rizzler)](https://pypi.org/project/rizzler)\n[![Code size](https://img.shields.io/github/languages/code-size/aekasitt/rizzler)](.)\n[![Top](https://img.shields.io/github/languages/top/aekasitt/rizzler)](.)\n[![Languages](https://img.shields.io/github/languages/count/aekasitt/rizzler)](.)\n[![Repository size](https://img.shields.io/github/repo-size/aekasitt/rizzler)](.)\n[![Last commit](https://img.shields.io/github/last-commit/aekasitt/rizzler/master)](.)\n[![Rizzler Banner](./static/rizzler-banner.svg)](https://github.com/aekasitt/rizzler/blob/master/static/rizzler-banner.svg)\n\n## Installation\n\nInstall using pip\n\n```sh\n$ pip install rizzler\n> ...\n```\n\n## Usage\n\nIntegrate with `lifespan` protocol.\n\n```python\nfrom contextlib import asynccontextmanager\nfrom fastapi import FastAPI\nfrom fastapi.requests impor Request\nfrom fastapi.responses import HTMLResponse\nfrom rizzler import RizzleTemplates, Rizzler\nfrom typing import AsyncIterator, List, Tuple\n\n@Rizzler.load_config\ndef rizzler_settings() -> List[Tuple[str, str]]:\n  return [\n    (\"command\", \"pnpm\"),\n    (\"framework\", \"vue\")\n  ]\n\n@asynccontextmanager\nasync def lifespan(_: FastAPI) -> AsyncIterator[None, None]:\n  await Rizzler.serve()\n  yield\n  Rizzler.shutdown()\n\napp: FastAPI = FastAPI(lifespan=lifespan)\ntemplates: RizzleTemplates = RizzleTemplates(directory=\"templates\")\n\n@app.get(\"/\", response_class=HTMLResponse)\nasync def index(request: Request) -> HTMLResponse:\n  return templates.TemplateResponse(\"index.html\", {\"request\": request})\n```\n\n### Templating\n\n`RizzleTemplates` is an extension on top of `Jinja2Templates` class found under [starlette](starlette.io)\nHowever, has two overriding methods that must be placed inside the template HTML-file as such:\n\n```html\n<!DOCTYPE html>\n<html>\n  <head><!-- ... --></head>\n  <body>\n    {{ vite_hmr_client() }}\n    {{ vite_asset('pages/main.js') }}\n  </body>\n</html>\n```\n\n## Build\n\nYou can run the following command once you are done customizing the front-end code under `pages/` directory\nto your liking.\n\n```sh\nrzl build\n```\n\n<details>\n  <summary>Example outputs for `rzl build`</summary>\n\n  ```sh\n  $ rzl build\n  > INFO     \u26a1Building Rizzler front-end\u2026\n  > INFO\n  > INFO     > rzl-tmp@0.0.0 build /Users/mackasitt/workspaces/rzl-react\n  > INFO     > vite build                                       \n  > INFO                                                       \n  > INFO     vite v5.3.3 building for production...           \n  > INFO     transforming...                                 \n  > INFO     \u2713 32 modules transformed.                      \n  > INFO     rendering chunks...                           \n  > INFO     computing gzip size...                       \n  > INFO     dist/rizz.svg    4.13 kB \u2502 gzip:  2.14 kB   \n  > INFO     dist/rizz.css    1.39 kB \u2502 gzip:  0.72 kB  \n  > INFO     dist/rizz.js   142.63 kB \u2502 gzip: 45.74 kB \n  > INFO     \u2713 built in 390ms\n  ```\n</details>\n\nNow you can stop using `RizzleTemplates` and revert back to serving front-end with `Jinja2Templates`\nas such\n\n```python\n#!/usr/bin/env python3\nfrom fastapi import FastAPI\nfrom fastapi.requests import Request\nfrom fastapi.responses import HTMLResponse\nfrom fastapi.staticfiles import StaticFiles\nfrom fastapi.templating import Jinja2Templates\n\napp = FastAPI()\ntemplates = Jinja2Templates(directory=\"dist\")\n\n@app.get(\"/\", response_class=HTMLResponse)\ndef index(request: Request) -> HTMLResponse:\n  return templates.TemplateResponse(\"index.html\", {\"request\": request})\n\napp.mount(\"/\", StaticFiles(directory=\"dist\"), name=\"dist\")\n```\n\nVoila! Now you have a production front-end to go with your `FastAPI` application when you need.\nThere will probably be bugs when it comes to relative versus absolute paths in the future.\nBut this is good enough for many prototyping use-case and with a bit of tinkering, can replace \n\n## Contributions\n\nTo be determined.\n\n## Acknowledgements\n\n* [fastapi-vite](https://github.com/cofin/fastapi-vite)\n* [django-vite](https://github.com/MrBin99/django-vite)\n\n## License\n\nThis project is licensed under the terms of the MIT license.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Rizzler creates a parallel front-end dev-server using ViteJS for ASGI Frameworks",
    "version": "0.1.9",
    "project_urls": {
        "Homepage": "https://github.com/aekasitt/rizzler",
        "Repository": "https://github.com/aekasitt/rizzler"
    },
    "split_keywords": [
        "asgi",
        " blacksheep",
        " fastapi",
        " hmr",
        " javascript",
        " litestar",
        " node",
        " npm",
        " pnpm",
        " quart",
        " sanic",
        " starlette",
        " uvicorn",
        " vite"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "42f175be8ce23a472b1bf204de53c4d2029d6e82c87947e10bee7fcd1ac3bc87",
                "md5": "9666fcea2f421899f3ed0f1b6635f60a",
                "sha256": "122672a5142e4ffa6c05e581fed414f379dbe37358aa3abc0999e2dbf82fc4d1"
            },
            "downloads": -1,
            "filename": "rizzler-0.1.9-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9666fcea2f421899f3ed0f1b6635f60a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 17756,
            "upload_time": "2024-07-10T09:38:56",
            "upload_time_iso_8601": "2024-07-10T09:38:56.721093Z",
            "url": "https://files.pythonhosted.org/packages/42/f1/75be8ce23a472b1bf204de53c4d2029d6e82c87947e10bee7fcd1ac3bc87/rizzler-0.1.9-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b02fa9f990ad6b5a4730c5b31716a439b54b7376e9c4d37fafbb51b0c818563e",
                "md5": "b43c4a19b1df77a50c2765732188e709",
                "sha256": "49c72300bf023d5db19a2e256c3df79c16ef59bc8b2d732235d4fd9ddd517fd8"
            },
            "downloads": -1,
            "filename": "rizzler-0.1.9.tar.gz",
            "has_sig": false,
            "md5_digest": "b43c4a19b1df77a50c2765732188e709",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 12179,
            "upload_time": "2024-07-10T09:39:28",
            "upload_time_iso_8601": "2024-07-10T09:39:28.301643Z",
            "url": "https://files.pythonhosted.org/packages/b0/2f/a9f990ad6b5a4730c5b31716a439b54b7376e9c4d37fafbb51b0c818563e/rizzler-0.1.9.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-10 09:39:28",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "aekasitt",
    "github_project": "rizzler",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "rizzler"
}
        
Elapsed time: 0.39327s