Skip to main content

FastAPI helpers for serving Vite assets in development and production.

Project description

vite_fastapi

vite_fastapi is a small library for using Vite with FastAPI, inspired by django-vite.

  • dev-mode helpers for Vite HMR and React refresh
  • production manifest loading for entrypoints, CSS, and recursive imports
  • Jinja globals for rendering asset tags from templates
  • support for multiple named Vite apps

Install

uv add vite_fastapi

Basic usage

from fastapi.templating import Jinja2Templates

from vite_fastapi import ViteConfig, register_vite

templates = Jinja2Templates(directory="templates")

register_vite(
    templates,
    {
        "default": ViteConfig(
            dev_mode=True,
            dev_server_url="http://127.0.0.1:5173",
            base_path="/static/",
            static_url="/static/",
            manifest_path="assets/manifest.json",
        )
    },
)

Then in your template:

{{ vite_react_refresh() }}
{{ vite_hmr_client() }}
{{ vite_asset("frontend/main.tsx") }}

In production, the same helpers resolve against the Vite manifest and emit CSS, modulepreload, and script tags.

Development

uv sync
uv run pytest

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

vite_fastapi-0.1.0.tar.gz (37.2 kB view details)

Uploaded Source

Built Distribution

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

vite_fastapi-0.1.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file vite_fastapi-0.1.0.tar.gz.

File metadata

  • Download URL: vite_fastapi-0.1.0.tar.gz
  • Upload date:
  • Size: 37.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for vite_fastapi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 149db4268d43e1c652fe2291ce98e0e1d98f97ab8a104b7650c81e2fc4cfb3c1
MD5 2cd864b6e07612ebfacf4c509387b756
BLAKE2b-256 00e6c7bf17a9fb1f6a937bfbd140d72e3fa15a6738825ebddda29d78ebf75783

See more details on using hashes here.

File details

Details for the file vite_fastapi-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: vite_fastapi-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for vite_fastapi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 184606e59d403237fd7182dd77363ecc60fe57a45aabf66c04cd13d9444a3bab
MD5 b70691f62ab4c9bdaa0730c759a05ed5
BLAKE2b-256 399c49132f6e92cf5f5ae91330ccb8650a94e20475c8ac7683b826defcadf71d

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