Metadata-Version: 2.4
Name: vite_fastapi
Version: 0.1.0
Summary: FastAPI helpers for serving Vite assets in development and production.
Author: thaske
License-Expression: MIT
License-File: LICENSE
Keywords: fastapi,frontend,jinja2,vite
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: FastAPI
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Requires-Dist: fastapi>=0.121.1
Requires-Dist: jinja2>=3.1.6
Requires-Dist: markupsafe>=3.0.0
Description-Content-Type: text/markdown

# vite_fastapi

`vite_fastapi` is a small library for using Vite with FastAPI, inspired by [django-vite](https://github.com/MrBin99/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

```bash
uv add vite_fastapi
```

## Basic usage

```python
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:

```python
{{ 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

```bash
uv sync
uv run pytest
```
