Skip to main content

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 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.2.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

fastapi_vue-0.2.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_vue-0.2.0.tar.gz
  • Upload date:
  • Size: 4.4 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.2.0.tar.gz
Algorithm Hash digest
SHA256 1c26c3fd0fb9a603823d4341c658204c691024d843f04b295983d50cfe088b33
MD5 a37486941fc5088ba89478ef85529654
BLAKE2b-256 a05710900a0c54a39bda2b74786e868617da4c947b17e0ed6dd50ee495015586

See more details on using hashes here.

File details

Details for the file fastapi_vue-0.2.0-py3-none-any.whl.

File metadata

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

Hashes for fastapi_vue-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5ca164466c880712128595456e56444c9f15f3f90b3cd3f100669ab262e1879f
MD5 458c1dcbf169b7826eb8c1999dd59c49
BLAKE2b-256 0c5315864f4922b0471e7983a8431d9ab00fd8fded31c0aeac8563d7408a7907

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