Skip to main content

Serves Vue static files / SPA on a FastAPI app. Use fastapi-vue-setup to install.

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 directory
  • spa: 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


Download files

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

Source Distribution

fastapi_vue-0.0.1.tar.gz (4.5 kB view details)

Uploaded Source

File details

Details for the file fastapi_vue-0.0.1.tar.gz.

File metadata

  • Download URL: fastapi_vue-0.0.1.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

Hashes for fastapi_vue-0.0.1.tar.gz
Algorithm Hash digest
SHA256 8eb78a66d2044ceceece95e85f5bf96caedb4192064c8304394375e64ee100ed
MD5 1e1ec8a0b5d8694e0d1aa157b168c909
BLAKE2b-256 f54177b75bba222a2fb1f2b76fe6295a931693a65162631476ae02306566df26

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