How to Create a FastAPI / Uvicorn Server Windows Service

Manpreet Singh Minhas
CodeX
Published in
7 min readMar 21, 2022

--

Photo by Inês Pimentel on Unsplash

Recently, I found myself in a position where I wanted to create a Windows service that would be responsible for starting up a FastAPI server automatically on boot up. However, I couldn’t find any article or tutorial that covers it in a structured and detailed manner. Since I got it working so wanted to share it with the community so that if anyone else wants to do the same it would be easier.

Introduction

Let us look at what a Windows Service is briefly. In a broader context, a daemon is a computer program that runs in the background without being under the control of an active user. Windows services arewhat performs the functions of a daemon on Windows OS. [1] These allow the creation of long running executable applications that run in their own Windows sessions. [2] These services can be set up to automatically start when the system starts or boots up, can be paused and restarted and do not have any user interface. It is because of all these features that Windows services are ideal in cases where one requires long running functionality which does not interfere with user activities.

There is extensive documentation for how to create a Windows service in .NET from Microsoft. However, for python the opposite is true i.e. there is no documentation available for creating Windows services…

--

--