0% found this document useful (0 votes)
18 views

Windows - Flask API Automation

This document provides instructions for automating a Flask API in Windows by creating .sh and .bat files to run the API on startup. The .sh file contains commands to activate the Python environment, navigate to the project directory, source the config file, run the API as a background process, print a success message, and close the terminal. The .bat file uses the Git Bash executable to run the .sh file. Both files are placed in the Windows startup folder so that the API runs automatically each time the system starts. This allows the API to be deployed without manually starting it after each restart.

Uploaded by

brian
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Windows - Flask API Automation

This document provides instructions for automating a Flask API in Windows by creating .sh and .bat files to run the API on startup. The .sh file contains commands to activate the Python environment, navigate to the project directory, source the config file, run the API as a background process, print a success message, and close the terminal. The .bat file uses the Git Bash executable to run the .sh file. Both files are placed in the Windows startup folder so that the API runs automatically each time the system starts. This allows the API to be deployed without manually starting it after each restart.

Uploaded by

brian
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Automating Flask API in windows

STEP 1 : BAT and SH File creation

To create a sh file open a fresh text file and save it as with .sh extension. In that file paste the below.

# To activate the python environment


source E:/ML_APIs/Python_Environment/python3.8.10_kollectcall/Scripts/activate
# To navigate to project directory
cd E:/ML_APIs/API/TeraKollect_call_preferredSessionV1
# To set the environment variables
source config/config.sh
# To run python application as background process
nohup python Kollect_preferredSession_app.py &
# Successful deployment
echo "ML Application deployed Successfully"
# To wait terminal for 5 sec
sleep 5s
# To logout and close the terminal
logout

Remember you need the prior experience in deploying things manually earlier. In below explained
the above commands functionality

1) First we need to activate our environment. For that as per the windows deployment document we
navigate to created environment first and then will activate it. Here we follow all together which
means the same.

2 ) Navigate to project directory

3) To set the environment variable values in local

4) To run the python application as background process

5) For a success full deployment It will print the successful message


Automating Flask API in windows

6) Terminal waits 5 seconds after the successful deployment since we need to check the successful
deployment message to confirm ourself

7) To logout the session and close the the terminal

For reference purpose the above commands manipulated with sample directory. Note it will change
as per the individual /server systems

Next is to create a bat file, open a fresh text file and save is as .bat extension & paste the below

@echo off

title ML_autostart_API

start "C:\Program Files\Git\git-bash.exe" ML_autostart_API_sh.sh

1) In title whatever title required name it.

2) In start mention the git-bash executable file path followed by the sh file created earlier, with the
respective name

2) In start mention the git-bash executable file path followed by the sh file created earlier with the
respective name. To find the executable file folder go to operating system drive and search for git

Remember both files should be in the same directory else it won’t work at all.
Automating Flask API in windows

If you’re worrying to follow the commands in further deployments you may create the executable
file using above guidance and by simply clicking the bat file execute the application further

STEP 2 : Automating In a system Startup

To automate the application in system startup do follow the bellow

1) Go to run using Winows+R or else search for run in windows start

2) Type shell:startup and press enter

3) It will open a specific folder in file explorer, Paste the both sh and bat file in that path now the
above commands what we’ve done is automatically executed in system startup. In every restart we
don’t need to start the application further

You might also like