A simple and powerful Python ToDo backend built with FastAPI, connected to SQL Server via PyODBC, and deployable on an Azure Ubuntu VM.
✨ FastAPI-based REST API
🛠️ CRUD operations on tasks
🗄️ SQL Server integration (ODBC Driver 17)
☁️ Azure VM deployment-ready (Ubuntu 20.04)
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" }git clone https://github.com/Riteshatri/todoBackendPythonMonolithic.git cd todoBackendPythonMonolithicEdit 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 * rit@34.33.32.31:"/home/rit/"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.txtuvicorn app:app --host 0.0.0.0 --port 8000You 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
| 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 |
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!
Ritesh Sharma
🔗 My LinkedIn Profile