Skip to content

Riteshatri/todoBackendPythonMonolithic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

🐍 PyTodo Backend (Monolith) – FastAPI + SQL Server on Azure VM

A simple and powerful Python ToDo backend built with FastAPI, connected to SQL Server via PyODBC, and deployable on an Azure Ubuntu VM.


🚀 Features

✨ FastAPI-based REST API
🛠️ CRUD operations on tasks
🗄️ SQL Server integration (ODBC Driver 17)
☁️ Azure VM deployment-ready (Ubuntu 20.04)


✅ Prerequisites

Before starting, ensure you have:

🔹 Azure Virtual Machine (Ubuntu 20.04)
🔹 Python 3.x installed
🔹 pip installed
🔹 SQL Server instance & credentials

Sample Azure Image Configuration:

source_image_reference = {
  publisher = "Canonical"
  offer     = "0001-com-ubuntu-server-focal"
  sku       = "20_04-lts"
  version   = "latest"
}

📦 Getting Started

🔧 Step 1: Clone the Repository

git clone https://github.com/Riteshatri/todoBackendPythonMonolithic.git
cd todoBackendPythonMonolithic

🔑 Step 2: Update Database Connection

Edit the app.py file with your SQL Server connection:

connection_string = (
  "DRIVER={ODBC Driver 17 for SQL Server};"
  "SERVER=<your-server>;"
  "DATABASE=<your-database>;"
  "UID=<your-username>;"
  "PWD=<your-password>"
)
**for example** :-
connection_string = "Driver={ODBC Driver 17 for SQL Server};Server=tcp:riteshserver.database.windows.net,1433;Database=riteshdatabase;Uid=ritserver;Pwd=admin@1234;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;"

✅ Ensure you're using ODBC Driver 17.


🔑 Step 3: Secure copy (scp) this updated code, after entered connected string correctly, to your backend vm...

scp -rf <vm User Name> @ <public IP Address>:"user'sHomeDirectory"

📝 for ex: - scp -r * [email protected]:"/home/rit/"

and then.......

⚙️ Step 4: Install Dependencies

Run these commands on your Ubuntu VM , Where you copy your code (user'sHomeDirectory):

sudo su
apt-get update && apt-get install -y unixodbc unixodbc-dev
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list
apt-get update
ACCEPT_EULA=Y apt-get install -y msodbcsql17
apt install python3-pip
pip install -r requirements.txt

▶️ Step 5: Run the Application

uvicorn app:app --host 0.0.0.0 --port 8000

🌐 Access the Application

You can now access the app via:

🔸 http://<your-vm-public-ip>:8000
🔸 http://localhost:8000 (local access)

📘 Swagger Docs:
Access Swagger UI at: http://<your-ip>:8000/docs


🔗 API Endpoints

Method Endpoint Description
GET /api/tasks List all tasks
GET /api/tasks/{task_id} Retrieve task by ID
POST /api/tasks Create a new task
PUT /api/tasks/{task_id} Update task by ID
DELETE /api/tasks/{task_id} Delete task by ID

✅ Conclusion

You've successfully deployed a modern Python backend using FastAPI and Microsoft SQL Server on an Azure VM.
Now it's ready for customization, scaling, and production!


👨‍💻 Author

Ritesh Sharma
🔗 My LinkedIn Profile

About

FastAPI-based Python ToDo backend with SQL Server integration, ready to deploy on Azure VM (Ubuntu 20.04).

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages