Skip to content

NKCloudDevOps/python-backend-testing

 
 

Repository files navigation

####### Backend-flask project #############

process:: step-1 -->>Create rds with security group "port 3306 and all traffic enabled" -->>now connect sql work bench with your rds credentials --->>now create database and run through workbench

Python Backend Testing (Flask)

A small Flask backend used for testing MySQL/RDS connectivity and basic CRUD operations on a users table.

Overview

This repository contains a minimal Flask app (app.py) that demonstrates connecting to a MySQL-compatible database (local or AWS RDS) and exposes simple REST endpoints to manage users.

Prerequisites

  • Python 3.8 or newer
  • pip
  • MySQL / MariaDB server or AWS RDS instance
  • git (optional)

Quickstart (local)

  1. Clone the repository:
git clone https://github.com/CloudTechDevOps/python-backend-testing.git
cd python-backend-testing
  1. Create the database and table (example):
CREATE DATABASE dev;
USE dev;

CREATE TABLE users (
  id INT AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(100) NOT NULL,
  email VARCHAR(100) NOT NULL UNIQUE
);
  1. Configure database connection:

Edit app.py and set the db_config values, or export environment variables before running (example shown for Linux/macOS):

DB_HOST=your-db-host
DB_USER=your-db-user
DB_PASS=your-db-password
DB_NAME=dev
  1. Run the app:
python app.py

The app listens on port 5000 by default (http://127.0.0.1:5000).

API Endpoints

  • GET /users — return all users
  • GET /users/ — return user by id
  • POST /users/add — add a new user (JSON body: {"name":"..","email":".."})
  • PUT /users/update/ — update a user (JSON body with name and/or email)
  • DELETE /users/delete/ — delete a user

Examples:

curl -X GET http://localhost:5000/users

curl -X POST http://localhost:5000/users/add \
  -H "Content-Type: application/json" \
  -d '{"name":"John Doe","email":"[email protected]"}'

curl -X PUT http://localhost:5000/users/update/1 \
  -H "Content-Type: application/json" \
  -d '{"name":"John Updated","email":"[email protected]"}'

curl -X DELETE http://localhost:5000/users/delete/1

Running on a server (example notes)

  • Use a production WSGI server (gunicorn, uWSGI) behind a reverse proxy for production.
  • For AWS: run the Flask app on an EC2 instance and use an RDS MySQL instance for the DB. Ensure security groups allow the required traffic (DB port 3306 allowed from the app host).

To run the app in background on Linux:

# start
nohup python3 app.py > flask.log 2>&1 &
# check
ps aux | grep app.py
# stop
pkill -f app.py

Files

  • app.py — main Flask application
  • requirements.txt — Python dependencies
  • test.sql — example SQL (if present)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 65.8%
  • HTML 34.2%