Serves Vue assets on a FastAPI app. Use fastapi-vue-setup tool to add Vue build to your package.
Project description
fastapi-vue
Implements static files routing with caching, compression and SPA support. Can be mounted at site root, unlike the built-in module.
- Automatic zstd compression
- ETag-based caching with immutable headers for hashed assets
- SPA (Single Page Application) support
- Favicon handling from hashed assets
- Dev mode integration with Vite
Installation
uv add fastapi-vue
Usage
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi_vue import Frontend
# Point to your built frontend assets
frontend = Frontend(
"path/to/frontend-build",
spa=True,
favicon="/assets/favicon.ico",
cached=["/assets/"],
)
@asynccontextmanager
async def lifespan(app: FastAPI):
await frontend.load()
yield
app = FastAPI(lifespan=lifespan)
# All your other routes...
# Final catch-all route for frontend files (keep at end of file)
frontend.route(app, "/")
Configuration
directory: Path to static files directoryspa: Enable SPA mode (serve index.html for unknown routes)cached: Path prefixes for immutable cache headers (e.g.,["/assets/"])favicon: Path prefix to serve at/favicon.ico(e.g.,"/assets/favicon.webp")zstdlevel: Compression level (default: 18)
See also
Script fastapi-vue-setup to create a project with statically built Vue using this module, and Vite devmode support.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastapi_vue-0.0.2.tar.gz.
File metadata
- Download URL: fastapi_vue-0.0.2.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55c8327da4ca8146cf15d3035266808b345dc0bacb609aff7967aff56a2f9e64
|
|
| MD5 |
7c34a77fc9910811ad2f02ecc8165798
|
|
| BLAKE2b-256 |
8f89c06f7376dff66572178154d3693fc55d57e5282c82e22d7bd81acfe78fa1
|
File details
Details for the file fastapi_vue-0.0.2-py3-none-any.whl.
File metadata
- Download URL: fastapi_vue-0.0.2-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aee5b5e955c07ca78d88272a0d1fc765666bca9994a3a9f56896d2b6d90a2433
|
|
| MD5 |
ef92b686e362f44cdac6666fd9ab4464
|
|
| BLAKE2b-256 |
01359cfbdcf6e41e7394eaa0e5d34cd92dbe6203a32e1981228310f7ddea4239
|