Part 5: Building and deploying the application
Our voting application is now usable by several people at once. Polls and votes survive server restarts, and browsers receive updates as they happen. But so far, the application has been running on our development machine.
What would we need to give someone else a copy of our application, or to run it on a small server of our own? Do we need to install Node.js, copy our entire project directory and start the development server there too?
In this final part, we will see how the setup from Part 1 lets us distribute the whole application as an ordinary Python package.
1. Leaving the development server behind
Throughout the tutorial, we have been running:
uv run scripts/devserver.py
This starts two servers. Vite serves the Vue application and forwards API requests and WebSocket connections to FastAPI. Both sides watch our source files for changes, so we can see the effects of our edits as we work.
For someone using the finished application, rather than developing it, there is no need for any of this development machinery. The browser only needs the HTML, JavaScript and CSS resulting from the Vue build. FastAPI can serve those files alongside the API and WebSocket endpoints we have already written.
We briefly tried this with the generated example in Part 1. Now we can do the same with our completed application.
Stop the development server with Ctrl+C. From the voting-app directory, run:
uv build
Watch the build output. As part of building the Python package, the integration set up by fastapi-vue-setup also builds the Vue frontend. Vite bundles and minifies our JavaScript and prepares the other assets for distribution. The build places the resulting files alongside our Python application.
Now start the application with its own command:
uv run voting-app
Open http://localhost:3100. Create a poll, open another browser window and check that live updates still work.
The application should behave just as it did during development, but there is only one web server running. FastAPI, with the help of the fastapi-vue runtime, serves both the built frontend and our application endpoints. Our existing relative API and WebSocket URLs still work, even though there is no longer a Vite proxy between the browser and FastAPI.
There is one difference we can easily observe. Try temporarily changing some visible text in frontend/src/App.vue and reloading the page. Nothing changes. We are serving the JavaScript produced by the last build, not our Vue source files. Even restarting the production server will not rebuild the frontend. Python code is not automatically reloaded either.
Undo the temporary edit. Whenever we want to work on the application again, we can return to the development server. Whenever we want a new production build, we run uv build again.
2. Running the application with our own settings
What if port 3100 is already occupied by another application? We could change the source code, but choosing a port is something the person running the application should be able to do.
Stop the server and try:
uv run voting-app --help
This is the help for our own application. Open backend/voting_app/__main__.py and compare it with the options shown in the terminal. This is the entry point generated for our project, and it uses the fastapi-vue server runner to start FastAPI. The command is registered in pyproject.toml under [project.scripts].
One of the generated options lets us choose the address on which the server listens:
uv run voting-app -l localhost:8000
Visit http://localhost:8000. We did not have to change any source files or rebuild the frontend to run the application on a different port.
The -l (or --listen) option controls the server, but this command belongs to our project. Any arguments we add to our own __main__.py can be passed in exactly the same way.
An optional application-specific argument
In Part 4, we chose polls.kantadb as our database filename. Since it is a relative path, the database is created in the directory from which our application runs. This is fine for development, but we might want to run the same application with separate sets of polls, without changing the directory ourselves each time.
We can give the application a --data-dir option. The generated __main__.py already imports os and Path, which are the two names we need for this addition.
Find the existing argument parser and add this option before it parses the arguments (using the parserβs existing variable name):
parser.add_argument(
"--data-dir",
type=Path,
default=Path("."),
help="Directory in which to keep application data",
)
After parsing the arguments, but before starting the server with server.run(...), add the following (here args is the parsed argument namespace):
data_dir = args.data_dir.resolve()
data_dir.mkdir(parents=True, exist_ok=True)
os.chdir(data_dir)
Changing the working directory before FastAPI starts is enough for our small application. The database path is relative to that directory, while the generated frontend path is relative to the Python package itself.
Try running:
uv run voting-app -l localhost:8000 --data-dir demo-data
Our existing polls should be absent, apart from any example poll in the database initializer. Create a poll, stop the server and run the same command again. The new poll is still there. Start without --data-dir and we are back to our original database.
We now have an example of a server option and an application-specific option working together. Keep the generated --listen option intact, since the development server also uses it to tell our application where to listen.
3. Taking the application out of the project directory
So far, even in production mode, we have been running the application inside our development checkout. How do we know that it does not need all of those development files?
Run uv build once more after any changes to the application. Take a look inside dist/. We should find two files with names similar to these:
dist/
βββ voting_app-0.1.0.tar.gz
βββ voting_app-0.1.0-py3-none-any.whl
These are two distribution formats for the same Python project:
- The
.tar.gzis the source distribution, from which an installable package can be built. - The
.whlis the wheel, already built and ready to install. It contains our Python code and the production frontend assets.
The wheel is particularly convenient for deployment: we can install it without running the frontend build again. It declares the Python dependencies our application needs, and uv can install those for us. We do not need to copy node_modules, the Vue source directory or the development server scripts.
Letβs try running the wheel somewhere else on our own machine first. Stop the running application, then copy the wheel into a new directory outside our project. From the voting-app directory:
mkdir ../voting-deployment
cp dist/voting_app-0.1.0-py3-none-any.whl ../voting-deployment/
cd ../voting-deployment
Use the actual wheel filename if your project has a different version. Now run:
uv run --no-project --with ./voting_app-0.1.0-py3-none-any.whl voting-app
The --with option tells uv which package to make available, and --no-project lets us run it independently of a source project. Uv prepares an environment with our installed application and its Python dependencies.
Open http://localhost:3100 again. The application works even though our new directory has no frontend or backend source tree. We are running the application from the installed wheel.
Notice that our original polls are not there. The package contains the application, not its accumulated data. The new instance has created its own polls.kantadb. We can create some polls here and restart the application to see that this database is independent of the original one.
4. Running on another machine
Moving to a server is now much the same as our previous experiment. On a small production VM, install uv and transfer the wheel into a directory belonging to the account that will run the application. There is no need to install Node.js or npm. Uv can obtain a suitable Python interpreter and install the required dependencies.
The command we used above listens locally by default. That is useful while testing on the same machine, but it wonβt allow us to open the application directly from a browser on another computer.
From the deployment directory on the VM, run:
uv run --no-project --with ./voting_app-0.1.0-py3-none-any.whl voting-app -l 0.0.0.0:3100
Here 0.0.0.0 means listening on all IPv4 interfaces, rather than just the loopback interface. On a trusted private network, open http://SERVER_IP:3100 from another computer, replacing SERVER_IP with the VMβs address. The network and firewall need to permit the connection.
For a service on the public internet, we would normally keep the application listening locally and put an HTTPS reverse proxy such as Caddy in front of it. We would also use a service manager such as systemd to start it automatically and keep it running after logging out. Those are deployment topics of their own. Our tutorial application has no authentication or protection against vote manipulation, so do not expose it as a real public voting service.
Keep the serverβs database in a writable, permanent directory. If you want to move existing polls to the VM, stop the old application cleanly and copy its polls.kantadb separately. Keep only one running application process per database, as in Part 4.
When we make improvements later, we can build a new wheel, transfer it and restart the service with the new package while leaving its data directory in place. This also assumes the new version is compatible with the stored data.
5. Distributing through a package index (optional)
Instead of sending someone a wheel file, we can publish our package to a Python package index. This is the same mechanism by which uv obtained our dependencies in the first place.
If we want to publish on PyPI, we need an account with publishing credentials and an available package name. voting-app is just our tutorial name; choose a unique distribution name in pyproject.toml before publishing. The command under [project.scripts] can remain voting-app.
After setting the package metadata and version, rebuild it and publish the intended distributions:
uv build
uv publish dist/<your-wheel>.whl dist/<your-source-distribution>.tar.gz
Replace the two placeholder filenames with those actually produced by the build. See the uv publishing guide for authentication and package-index configuration. Publishing to PyPI makes the package publicly available; it is not required for private deployment.
Once published, someone can run the application with uv without downloading a wheel manually:
uvx --from your-unique-package-name voting-app -l localhost:8000
This is the same uvx mechanism we used in Part 1 to run fastapi-vue-setup. This time it is our own application that is being installed and executed.
Where we are now
We started with a generated Vue and FastAPI project, built a browser-local voting interface, connected browsers through a shared backend and made the data persistent. Now we can take the application out of its development environment and run it on another machine.
The development tools are still there when we need them, but they are not part of the running service. The finished application is distributed as a Python package containing its built frontend, and its data is kept independently of that package.
For more about the generated entry point and build integration, see fastapi-vue-setup and the fastapi-vue runtime. The uv tools guide covers running packaged commands without a project checkout.