Skip to main content

Integration utilities for FastAPI and ViteJS.

Project description

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

pip install fastapi-vite

Usage

Configure Jinja templating for FastAPI

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

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.

{{ render_vite_hmr_client() }}

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi_vite_dara-0.3.2.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_vite_dara-0.3.2-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_vite_dara-0.3.2.tar.gz.

File metadata

  • Download URL: fastapi_vite_dara-0.3.2.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.2 Darwin/24.1.0

File hashes

Hashes for fastapi_vite_dara-0.3.2.tar.gz
Algorithm Hash digest
SHA256 88be70b5c8b6939599871c1b4d4e200094772e34bcaebbe864671a7e7e12e52e
MD5 24015752516d917d8ce6e76b0dccb41d
BLAKE2b-256 6c3d7e31ac58422319c535a96617c4cdee53c498384190c9f05f656814f8cb00

See more details on using hashes here.

File details

Details for the file fastapi_vite_dara-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: fastapi_vite_dara-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.2 Darwin/24.1.0

File hashes

Hashes for fastapi_vite_dara-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 95810f9cd542534066c8bb37bcd17b9d9d52f175dcac874d236f179d4496acb1
MD5 d3df49a967991696914a9efaa9a72fe6
BLAKE2b-256 634052035a13afebc2f2a6d63becc17939c76f65c5cb57ed446acf84bc504d59

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page