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 directoryspa: 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 asimage/png)zstdlevel: Compression level (default: 18)
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.8.2.tar.gz.
File metadata
- Download URL: fastapi_vue-0.8.2.tar.gz
- Upload date:
- Size: 6.7 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 |
a7fdeac7f02f368aa3f3c42dc510bde7f93bfbd497008e394c08f518a8d2582d
|
|
| MD5 |
05d64ccc6d244fc23ebcdaf71b468ddf
|
|
| BLAKE2b-256 |
d566840b433789c212bd97b6b6a3d2b3b0af403154e3ad7a659e37d099338d36
|
File details
Details for the file fastapi_vue-0.8.2-py3-none-any.whl.
File metadata
- Download URL: fastapi_vue-0.8.2-py3-none-any.whl
- Upload date:
- Size: 8.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 |
17d2be5f0cf491dee2687caa291eb98bbb51f8275e1d260ff22d7fa42fd1b8dc
|
|
| MD5 |
63e969217630c5f120b9de572a6af79b
|
|
| BLAKE2b-256 |
0db1a695b819bdc886e04ea43028754be0c4591c7fb1148c64c1a2de68ff7391
|