Deployment
Package and deploy Poll Box as a self-contained Python distribution.
We will build the frontend into a Python wheel, verify that it runs outside the source checkout and install it as a systemd service. The deployed application needs neither Node.js nor the development tools.
Production build
Stop the development server with Ctrl+C. From poll-box/, run:
uv build
The build integration runs Vite and places the resulting frontend alongside the Python application. The files in dist/ contain the built frontend and backend. Node is only used for making these Python packages from your source repository, and your Vue sources are not being included even in the sdist Python package.
Running in repository
uv run poll-box
Notice it doesnβt run Vite now, just the backend. Open http://localhost:3100. FastAPI serves the built frontend and API from one server. Unlike the development server, this command serves the result of our last build: editing Vue or Python files does not update the running application, so rebuild and restart it after making changes.
Navigate to http://localhost:3100/new to make sure the SPA is also working correctly. FastAPI should be serving the application from any path that has no handler. When you chose to use Vue Router, the script automatically set your backend to serve Frontend(..., spa=True) to make this work.
Installing the application
To run the application independently of the repository, install the wheel as a uv tool:
uv tool install dist/poll_box-0.1.0-py3-none-any.whl
poll-box
We can now run poll-box from any directory (provided you have ~/.local/bin in path). This does not depend on uv, node or the source repository. The package does not include our existing database: The app creates polls.kantadb in the current working directory.
Production deployment
Any serious full stack application needs to run on some dedicated server or VPS, not only in your terminal. We will build a secure install that only requires that tiny whl file you built, that is managed by your ordinary user account and that stores its data in a secure systemd sandbox.
Install UV on server
Install uv on the server like you did on the local machine, as your ordinary user, or from package manager if your distro has it.
Create a user-writable and world-readable directory for app installs:
sudo install -d -m 0755 -o "$USER" /opt/uv
Install the wheel file as a standalone tool:
UV_TOOL_DIR=/opt/uv/tools UV_TOOL_BIN_DIR=/opt/uv/bin UV_PYTHON_INSTALL_DIR=/opt/uv/python \
uv tool install --managed-python ./poll_box-0.1.0-py3-none-any.whl
This does not depend on your system Python and doesnβt require uv to run, but everything is neatly in the /opt/uv folder. Use uv upgrade as needed with those same env options.
If you instead prefer
pip installas root or any other means of installation, feel free to customise. Nothing from here on requires uv.
Setup a systemd service
Create a new systemd unit, this will open your configured $EDITOR:
sudo systemctl edit --full --force poll-box.service
Paste the following and save:
[Unit]
Description=Poll Box
[Service]
DynamicUser=yes
StateDirectory=poll-box
WorkingDirectory=/var/lib/poll-box
ExecStart=/opt/uv/bin/poll-box
[Install]
WantedBy=multi-user.target
The service runs our installed app in a dynamic user sandbox. Kanta writes polls.kantadb in the systemd created persistent state directory /var/lib/poll-box, from where the app runs.
Start the service, enable it at boot and inspect its logs (Ctrl-C to quit viewing log):
sudo systemctl enable --now poll-box
journalctl -focat -u poll-box
The application listens locally on port 3100.
To upgrade, build and transfer a new wheel, install it with the same uv environment variables and run sudo systemctl restart poll-box. The state directory and database remain in place.
Running on Internet
With Caddy installed from the distribution, add a site to /etc/caddy/Caddyfile, replacing the example domain with one whose DNS points to the server:
vote.example.com {
reverse_proxy :3100
}
Caddy serves HTTPS and forwards requests to the application over HTTP. Reload Caddy after changing its configuration, typically with sudo systemctl reload caddy. If you just installed, you may also require sudo systemctl enable --now caddy.
You will not require static files serving at this layer, because fastapi-vue already serves them extremely quickly from RAM cache with zstd compression.
If you are using Nginx, Traefik, Apache or whatever else, you will find the config similar, although you may need manual configuration for certificates, HTTP pipelining, X-Forwarding headers and WebSockets. But if you are using them, you are probably already familiar with that.
Authorization
Our tutorial application has no authentication or protection against vote manipulation. When an application needs accounts and access control, Paskia provides authentication and permission management that can be integrated with the reverse proxy, or used by your app to determine who is using it.
Publish a Python package
Is your software open source and useful to others? Create an account at pypi.org and publish it for all to use. You may need to find a package name that is still not taken (please donβt upload poll-box).
rm -f dist/*
uv build
uv publish
See the uv publishing guide for more details. Once published, the application can be run anywhere directly from package repository:
uvx poll-box --help
Where we are now
The finished application is now a self-contained Python package with its frontend built in, ready to run independently or deploy to another machine.
The tutorial ends here. For now? Happy hacking!