Skip to main content

FastAPI-Vue Runtime

Runtime utilities for making FastAPI apps standalone, with their own CLI entry point and facilities that make the FastAPI + Vue stack pleasant to use.

ℹ️ Use fastapi-vue-setup to set up your project. Everything below is configured automatically by it.

Main Components

  • Frontend: Serves static files with proper caching, compression and SPA support
  • Server: Runs the FastAPI app from your own CLI entry point with uvicorn facilities vastly augmented

Quickstart

Serve built frontend assets from frontend-build/:

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

frontend = Frontend(Path(__file__).with_name("frontend-build"), spa=True)

@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, "/")

If SPA mode is disabled, we only route the paths that actually exist, leaving anything else to your own handlers that come after and may themselves wish to catch all that remains.

Frontend (fastapi_vue.Frontend)

  • Designed to serve at /, living together with your other routes
  • SPA routing: serves index.html for paths not otherwise handled
  • RAM caching with zstd compression
  • Browser caching with ETag, Last-Modified and immutable assets

With FastAPI(debug=True), frontend requests return HTTP 409 with a message directing you to the Vite dev server. This prevents accidentally serving an outdated frontend build during development.

  • directory: Path on local filesystem
  • index: Index file name (default: index.html)
  • spa: Serve index at any path (default: False)
  • catch_all: Register a single catch-all handler instead of a route to each file; default for SPA
  • cached: Path prefixes treated as immutable (default: /assets/)
  • favicon: Optional path or glob (e.g. /assets/logo*.png)
  • zstdlevel: Compression level (default: 18)

ℹ️ Browsers commonly request /favicon.ico even when another icon is specified in HTML. The favicon option lets you serve an SVG or PNG there instead. This also provides a convenient application default that a deployment reverse proxy such as Caddy or Nginx can override with company branding.

Server runner (fastapi_vue.server)

When you need more flexibility than the fastapi CLI provides—for example, to support arguments in your own CLI—you can use the bundled server runner.

It starts the FastAPI app, running directly in the current process when possible and delegating to Uvicorn supervisors for reloads and multiple workers. The server.run is modeled after uvicorn.run that you would otherwise have to use to run FastAPI.

from fastapi_vue import server

server.run("my_app.app:app", listen=["localhost:8000"])

Endpoints are plain strings: host:port, a bare port (localhost only), :port (all interfaces), or a unix socket path. Multiple endpoints can be served simultaneously. This also avoids Uvicorn's localhost limitation, where localhost may bind only to either 127.0.0.1 or ::1.

A single reload argument replaces Uvicorn's separate reload arguments and may directly specify paths to watch.

A startup box with the app name, version and connect URL is printed before serving. Pass a startup_box template ({name}, {version}, {listen}, {url}, ...) to customize it, None to disable, or use server.print_startup_box on its own.

Printed by server.run("my_app.app:app", listen=["localhost:3100"]):

╭──────────────────────────────────────────╮
│ My App 0.1.0 @ 127.0.0.1:3100 [::1]:3100 │
│ http://localhost:3100                    │
╰──────────────────────────────────────────╯

Logging is integrated as well: removes noisy uvicorn logging, replacing it with prettified log formatting, a colored access log and tracebacks rendered by tracerite. Note that HTTP responses also include tracerite formatting when FastAPI(debug=True) is used.

Other arguments are generally passed to uvicorn.run, although some like log_config receive our modifications.

As a deployment option, environment FORWARDED_ALLOW_IPS controls X-Forwarded trusted IPs (default: 127.0.0.1,::1 works for typical setups).

Environment (fastapi_vue.env)

We use environment variables to pass values between program components, from devserver script setting dev mode and telling backend and frontend URLs, to your CLI, which in turn runs the FastAPI app that may also need access to this information. The variables are prefixed by the current application name to avoid conflicts. The CLI entry point should set one like os.environ["FASTAPI_VUE"] = "MY_APP", before using server.run

The following properties read the environment and return None when variables haven't been set:

  • fastapi_vue.env.prefix — the prefix itself
  • fastapi_vue.env.dev — running in development mode, from e.g. MY_APP_DEV=1
  • fastapi_vue.env.vite_url, fastapi_vue.env.backend_url — URLs set by the devserver

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-1.6.0.tar.gz (20.3 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-1.6.0-py3-none-any.whl (24.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_vue-1.6.0.tar.gz
  • Upload date:
  • Size: 20.3 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":"26.04","id":"resolute","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-1.6.0.tar.gz
Algorithm Hash digest
SHA256 6be91b53c46d4c5eb9e6df07f184831f1f4d91d39fdea5ce8d2e903fa856b29e
MD5 4593ca1e564e15744cf50f88d4b81ef7
BLAKE2b-256 521012f63401ca7a0d478f99efa9190d34af1959e52e1ca61939a1182b4be04b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fastapi_vue-1.6.0-py3-none-any.whl
  • Upload date:
  • Size: 24.1 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":"26.04","id":"resolute","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-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f62b532e52f53a2c8d074bcee2afae6896537da60410f5d374b7712e3c0fbe9d
MD5 324c9905cf653e2602879455f9a8888e
BLAKE2b-256 98e1e1ecc33d0131f8a5a16d302a8efcfbf39acef147049b6adc0c6ae06cd1b5

See more details on using hashes here.

Release history Release notifications | RSS feed

1.6.1

2 files

This release

1.6.0 This release

2 files

1.5.0

2 files

1.4.2

2 files

1.4.1

2 files

1.4.0

2 files

1.3.1

2 files

1.3.0

2 files

1.2.0

2 files

1.1.1

2 files

1.1.0

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

0.9.3

2 files

0.9.2

2 files

0.9.1

2 files

0.8.3

2 files

0.8.2

2 files

0.8.1

2 files

0.8.0

2 files

0.7.1

2 files

0.7.0

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.4.0

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

0.0.2

2 files

0.0.1

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page