BookmarkSubscribeRSS Feed

360 Custom connectors: How to deploy a Python package as a Windows service on Production

Started 2 weeks ago by
Modified 2 weeks ago by
Views 196

Python package using Flask: What are the challenges?

 

Here we are considering a scenario where we have developed a custom connector logic using python technology and have used Flask as a development server.

 

It is ok to use flask in development environment to develop and test your connector. But as this was provided only for development, same time it has many disadvantages, like it is not designed to be particularly efficient, stable and secure.

For such reasons, we avoid direct use of python flask service for production environment.

Also, when we run python flask service it shows up a Warning message saying do not use this development server in a production environment.

 

 

ranjanasharma_0-1750923409419.png

 

So, the question comes that we have developed and tested the python package on development then how to deploy it on production without using WSGI server and which one to use?

 

Solution: WSGI Server for Production

 

The answer is to use production WSGI server instead of flask. These are Self-hosted as WSGI servers that has HTTP servers built in.

 

A WSGI server is used to run the application, converting incoming HTTP requests to the standard WSGI, and converting outgoing WSGI responses to HTTP responses.

There is a list of several Self hosted WSGI servers like Gunicorn, uWSGI, ASGI, gevent etc.

 

Waitress as WSGI Server

 

It is suggested to use Waitress, as it has many advantages like it is easy to configure, supports Windows as well as Linux, Secure and no dependencies, and once you installed waitress then you won’t need any other python library.

 

ranjanasharma_0-1750934933317.png

 

ranjanasharma_1-1750934943721.png

 

Now, let’s consider that we have developed and updated our python package using Waitress. The next challenge is, in the customer's Production environment, we need to deploy this package as a Windows Service.

 

NSSM: What it is?

 

It is recommended to use NSSM that stands for Non-Sucking Server Manager. This is a service helper that help run Flask application as a windows service.

 

ranjanasharma_2-1750934994133.png

 

 

There are many advantages in choosing NSSM for deploying Python package as Windows Service:

1. If the service stops because of unknown reason, then NSSM restart the service.

2. User can easily manage the service from Services.msc screen.

3. We can also use NSSM commands to run the application’s batch file as windows service.

4. The command line output can also be saved in log files as text.

 

NSSM to deploy Python package as a Windows service:

 

Now let's look at one of the examples of using NSSM commands for running python batch file as windows service.

Let’s assume we have server.py python file and we created its batch file named run_server.bat. Then we can use below given NSSM commands to run this batch file as background service on windows.

 

ranjanasharma_3-1750935565072.png

 

Once completed executing above commands, we could verify our service if it got deployed successfully from under Services.msc screen.

So, that’s how using NSSM one can deploy Python Flask application as a windows service on customer's environment.

 

 

Version history
Last update:
2 weeks ago
Updated by:
Contributors

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

SAS AI and Machine Learning Courses

The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.

Get started

Article Tags