fastapi_vite_dara


Namefastapi_vite_dara JSON
Version 0.3.4 PyPI version JSON
download
home_pagehttps://github.com/causalens/fastapi-vite
SummaryFork of fastapi-vite to support wider range of jinja2 version.
upload_time2024-12-17 15:22:04
maintainerNone
docs_urlNone
authorcausaLens
requires_python<4,>=3.8
licenseMIT
keywords fastapi starlette vite dara
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # fastapi-vite

Integration for FastAPI and Vite JS

## what?

This package is designed to make working with javascript assets easier.

fastapi-vite enables the jinja filters required to render asset URLs to jinja templates

Inspired by `django-vite` @ [https://github.com/MrBin99/django-vite]

## installation

Install using pip

```shell
pip install fastapi-vite
```

## Usage

Configure Jinja templating for FastAPI

```python
import fastapi_vite_dara

templates = Jinja2Templates(directory='templates')
templates.env.globals['vite_hmr_client'] = fastapi_vite_dara.vite_hmr_client
templates.env.globals['vite_asset'] = fastapi_vite_dara.vite_asset

```

### Configure Vite

Here is an example used to test this plugin

```javascript
import { defineConfig } from "vite";
import reactRefresh from "@vitejs/plugin-react-refresh";
const Dotenv = require("dotenv");
import path from "path";
Dotenv.config({ path: path.join(__dirname, ".env") });

const STATIC_URL = process.env.STATIC_URL;
// https://vitejs.dev/config/
export default defineConfig({
  base: `${STATIC_URL}`,
  clearScreen: false,
  plugins: [reactRefresh()],
  build: {
    target: "esnext",
    outDir: "./static/",
    emptyOutDir: true,
    assetsDir: "",
    manifest: true,
    rollupOptions: {
      input: "./assets/javascript/main.tsx",
    },
  },

  root: ".", // You can change the root path as you wish
});
```

### Configure Static Assets

### Configure Templates

\*render_vite_hmr no-op when in production.

```html
{{ render_vite_hmr_client() }}

<script
  type="text/javascript"
  defer
  src="{{ asset_url('javascript/main.tsx') }}"
></script>
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/causalens/fastapi-vite",
    "name": "fastapi_vite_dara",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4,>=3.8",
    "maintainer_email": null,
    "keywords": "fastapi, starlette, vite, dara",
    "author": "causaLens",
    "author_email": "support@causalens.com",
    "download_url": "https://files.pythonhosted.org/packages/13/25/be9e9a24cb4bf83b988b5045cb865d9a10cb0943f4951d976749e09bdf1c/fastapi_vite_dara-0.3.4.tar.gz",
    "platform": null,
    "description": "# fastapi-vite\n\nIntegration for FastAPI and Vite JS\n\n## what?\n\nThis package is designed to make working with javascript assets easier.\n\nfastapi-vite enables the jinja filters required to render asset URLs to jinja templates\n\nInspired by `django-vite` @ [https://github.com/MrBin99/django-vite]\n\n## installation\n\nInstall using pip\n\n```shell\npip install fastapi-vite\n```\n\n## Usage\n\nConfigure Jinja templating for FastAPI\n\n```python\nimport fastapi_vite_dara\n\ntemplates = Jinja2Templates(directory='templates')\ntemplates.env.globals['vite_hmr_client'] = fastapi_vite_dara.vite_hmr_client\ntemplates.env.globals['vite_asset'] = fastapi_vite_dara.vite_asset\n\n```\n\n### Configure Vite\n\nHere is an example used to test this plugin\n\n```javascript\nimport { defineConfig } from \"vite\";\nimport reactRefresh from \"@vitejs/plugin-react-refresh\";\nconst Dotenv = require(\"dotenv\");\nimport path from \"path\";\nDotenv.config({ path: path.join(__dirname, \".env\") });\n\nconst STATIC_URL = process.env.STATIC_URL;\n// https://vitejs.dev/config/\nexport default defineConfig({\n  base: `${STATIC_URL}`,\n  clearScreen: false,\n  plugins: [reactRefresh()],\n  build: {\n    target: \"esnext\",\n    outDir: \"./static/\",\n    emptyOutDir: true,\n    assetsDir: \"\",\n    manifest: true,\n    rollupOptions: {\n      input: \"./assets/javascript/main.tsx\",\n    },\n  },\n\n  root: \".\", // You can change the root path as you wish\n});\n```\n\n### Configure Static Assets\n\n### Configure Templates\n\n\\*render_vite_hmr no-op when in production.\n\n```html\n{{ render_vite_hmr_client() }}\n\n<script\n  type=\"text/javascript\"\n  defer\n  src=\"{{ asset_url('javascript/main.tsx') }}\"\n></script>\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Fork of fastapi-vite to support wider range of jinja2 version.",
    "version": "0.3.4",
    "project_urls": {
        "Homepage": "https://github.com/causalens/fastapi-vite",
        "Repository": "https://github.com/causalens/fastapi-vite"
    },
    "split_keywords": [
        "fastapi",
        " starlette",
        " vite",
        " dara"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "edfed77cbd5ee70188b52d7f704bbb83143579628db8faefc7fb00d95d9d1d63",
                "md5": "9fb4caf594c8dbcf76d08bcc495a86ca",
                "sha256": "0c204d7097a1b29f83ce4ba2ca9271c474633abf3ea1f83ad7e336f53aea8ec8"
            },
            "downloads": -1,
            "filename": "fastapi_vite_dara-0.3.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9fb4caf594c8dbcf76d08bcc495a86ca",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4,>=3.8",
            "size": 6931,
            "upload_time": "2024-12-17T15:22:02",
            "upload_time_iso_8601": "2024-12-17T15:22:02.299384Z",
            "url": "https://files.pythonhosted.org/packages/ed/fe/d77cbd5ee70188b52d7f704bbb83143579628db8faefc7fb00d95d9d1d63/fastapi_vite_dara-0.3.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1325be9e9a24cb4bf83b988b5045cb865d9a10cb0943f4951d976749e09bdf1c",
                "md5": "e857267d037c955473fd06076c41a765",
                "sha256": "542518631f0b0c09db1a88189abcf8aed3838fe6806937401ce7323fc3fd01bc"
            },
            "downloads": -1,
            "filename": "fastapi_vite_dara-0.3.4.tar.gz",
            "has_sig": false,
            "md5_digest": "e857267d037c955473fd06076c41a765",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4,>=3.8",
            "size": 5872,
            "upload_time": "2024-12-17T15:22:04",
            "upload_time_iso_8601": "2024-12-17T15:22:04.664091Z",
            "url": "https://files.pythonhosted.org/packages/13/25/be9e9a24cb4bf83b988b5045cb865d9a10cb0943f4951d976749e09bdf1c/fastapi_vite_dara-0.3.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-17 15:22:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "causalens",
    "github_project": "fastapi-vite",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "fastapi_vite_dara"
}
        
Elapsed time: 0.38141s