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 Single-Page-App serving at site root with FastAPI, that the standard StaticFiles module cannot handle. This also caches and zstd compresses the files for lightning-fast operation. This is primarily meant for use with Vue frontend, but technically can host any static files in a similar manner.

Installation

Script fastapi-vue-setup should normally be used to convert or create a project with connection between FastAPI and Vue. The target project will depend on this package to serve its static files.

uvx fastapi-vue-setup --help

Refer to instructions below for further configuration.

Usage

from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi_vue import Frontend

frontend = Frontend(
    Path(__file__).with_name("frontend-build"),
    spa=True,
    cached=["/assets/"],
)

@asynccontextmanager
async def lifespan(app: FastAPI):
    await frontend.load()
    yield

app = FastAPI(lifespan=lifespan)

# Add API routes here...

# 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 (browser won't check for changes)
  • favicon: Path to serve at /favicon.ico (e.g., "/logo.png" will be served as image/png)
  • zstdlevel: Compression level (default: 18)

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.5.1.tar.gz (5.6 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.5.1-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_vue-0.5.1.tar.gz
  • Upload date:
  • Size: 5.6 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.5.1.tar.gz
Algorithm Hash digest
SHA256 e331f025cd209c39aa90d8c04199e1d60fda84b58599ab4c3c9665d945b90277
MD5 55bbcb0bb2d22eaf6d03ae4d68136c19
BLAKE2b-256 e09ec8b51afee553374661b6eefc9de92ac3e2ac4070dbdec9714a8baeb60fbe

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fastapi_vue-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 6.6 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.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2700971d6ad358adc19afa9c2d0cec789ba74cba884aa0fd0b0a7e08632f4891
MD5 b4d2d1d8d53a160b97e12052bf0dc00b
BLAKE2b-256 2dde69033118f56f9b0d0d6f3cb8d448686a8e35d8e7d81e93a4f6d107b457c0

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