DEV Community

Cover image for โ˜From Code to Cloud: A Step-by-Step Guide to Building and Deploying Python Flask Applications ๐Ÿ‘จ๐Ÿฝโ€๐Ÿ’ป
BAKRE JAMIU
BAKRE JAMIU

Posted on

1

โ˜From Code to Cloud: A Step-by-Step Guide to Building and Deploying Python Flask Applications ๐Ÿ‘จ๐Ÿฝโ€๐Ÿ’ป

โ˜ Cloud-Based Development: A Beginner's Guide to Building Python Flask Applications with Deployment.โ˜

Getting Started ๐Ÿ‘จ๐Ÿฝโ€๐Ÿ’ป

To begin, ensure you have a Linux environment set up. If you're using Windows 10, install Windows Subsystem for Linux (WSL) and configure an instance, as outlined in my previous article.

File Extensions Overview

Familiarize yourself with common file extensions:

๐Ÿ”ต Python: .py
๐Ÿ”ต JavaScript: .js
๐Ÿ”ต C#: .cs
๐Ÿ”ต Ruby: .rb
๐Ÿ”ต PHP: .php

Our Focus

In this tutorial, we'll concentrate on building and deploying Python application, utilizing .py

Deployment Guide: Python Application.

Section A

Create an Instance

Follow the detailed instructions in my previous article to create an instance on AWS EC2: Post

Refer to Section A for the step-by-step guide ๐Ÿค“.

Section B

Connect to Your Server ๐Ÿคญ

Once your instance is set up, connect to your server by following Section B in the same article: Post

Stay Tuned ๐Ÿ˜ฏ

For the pictorial deployment guide of Python application.

Section C

Deployment Phase

Step: Update Virtual Server๐Ÿ˜Œ๐Ÿ˜Š.

Image description

Step 2: Verify Python Installation - Check Version.

Image description

Step 3: Create 'apps' Directory and Verify.

Image description

Step 4: Access 'apps' Folder, Create a New File and Open for Editing.

Image description

Step 5: Add Your Code to the Newly Created File

Image description

Step 6: Save & Exit Nano Editor (Ctrl x, Y, Enter)

Image description

Step 7: Review File Contents.

Image description

Step 8: Execute Python Code.

Image description

Step 9: Set Up Virtual Environment.
(1. You can see itโ€™s not install) (2. You can see it is not install) (3. Install virtual environment {venv})

Check if Virtual Environment is Installed.

python3 -m venv
Enter fullscreen mode Exit fullscreen mode

If not installed:

sudo apt-get install python3-venv
Enter fullscreen mode Exit fullscreen mode

Image description

Step 10: Run and Activate venv

To activate:

Source Jamiu/bin/activate
Enter fullscreen mode Exit fullscreen mode

Image description

Step 11: Install Flask framework Using pip.

pip install flask
Enter fullscreen mode Exit fullscreen mode

Image description

Step 12: List packages installed in the virtual environment.

Image description

Step 13: Create app.py and Open in Nano Editor.

Insert this code:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello_world():
    return "<p>Hello, This is my first Live Python Flask app!</p>"
Enter fullscreen mode Exit fullscreen mode

Image description

Step 14: Execute app.py with Python and Start Flask Server.

Image description

Flask app is running, but only accessible internally.

Step 15: Go Live - Make Application Accessible to External Users.

Image description

Step 16: Verify Application Status - Running and Active.

Image description

Congratulations! ๐ŸŽ‰ You've Successfully Deployed Your First Flask Application in Python. ๐Ÿ•บ๐Ÿฝ๐Ÿ•บ๐Ÿฝ๐Ÿ•บ๐Ÿฝ

Conclusion:
We've reached the end of this installment. Keep an eye out for my upcoming article, arriving in the next few days๐Ÿ˜Š๐Ÿ™‚๐Ÿ˜Œ.

Image of Timescale

๐Ÿš€ pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applicationsโ€”without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more โ†’

Top comments (0)

๐Ÿ‘‹ Kindness is contagious

Please leave a โค๏ธ or a friendly comment on this post if you found it helpful!

Okay