{"id":25434427,"url":"https://github.com/prateekmaj21/students_db_sql","last_synced_at":"2026-05-16T22:03:40.775Z","repository":{"id":248253294,"uuid":"828197379","full_name":"prateekmaj21/students_db_sql","owner":"prateekmaj21","description":"An complete application that performs CRUD (Create, Read, Update, Delete) operations on a MySQL database using Python. ","archived":false,"fork":false,"pushed_at":"2024-07-23T07:06:22.000Z","size":51,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-04T19:52:49.346Z","etag":null,"topics":["postman","python","sql","sqldatabase"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/prateekmaj21.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-07-13T12:06:26.000Z","updated_at":"2024-07-23T07:06:25.000Z","dependencies_parsed_at":"2025-05-14T21:12:40.794Z","dependency_job_id":"cade1d37-f6ce-49a5-a57e-2760ffdc5d3c","html_url":"https://github.com/prateekmaj21/students_db_sql","commit_stats":null,"previous_names":["prateekmaj21/school_students_sql","prateekmaj21/students_db_sql"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/prateekmaj21/students_db_sql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prateekmaj21%2Fstudents_db_sql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prateekmaj21%2Fstudents_db_sql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prateekmaj21%2Fstudents_db_sql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prateekmaj21%2Fstudents_db_sql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prateekmaj21","download_url":"https://codeload.github.com/prateekmaj21/students_db_sql/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prateekmaj21%2Fstudents_db_sql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33120450,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-16T18:38:32.183Z","status":"ssl_error","status_checked_at":"2026-05-16T18:38:29.903Z","response_time":115,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["postman","python","sql","sqldatabase"],"created_at":"2025-02-17T06:16:49.284Z","updated_at":"2026-05-16T22:03:40.739Z","avatar_url":"https://github.com/prateekmaj21.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Students Database using FastAPI and MYSQL\nThe objective of this project is to develop a complete application that performs CRUD (Create, Read, Update, Delete) operations on a MySQL database using Python. \n\nVideo Implementation: [Youtube](https://youtu.be/xDrCJacrwo4?si=ChAg_KPDszRpmYB8)\n\n# Prerequisites\n\n## MySQL Database Setup\n\n1. Ensure you have MySQL Server installed and running.\n2. Create a database named `school` and a table named `students` with appropriate columns (`id`, `name`, `age`, `grade`). Refer to the instructions for setting up the database.\n\n## Python Environment\n\n1. Make sure you have Python installed on your system. You can download Python from [python.org](https://www.python.org) if not already installed.\n\n# Project Files\n\n1. **database.py**: Implement MySQL connection and CRUD operations.\n2. **main.py**: Implement FastAPI application with CRUD endpoints.\n3. **requirements.txt**: List the Python dependencies (fastapi, uvicorn, mysql-connector-python).\n\n---\n\n## requirements.txt\n\n```text\nfastapi==0.70.0\nuvicorn==0.15.0\nmysql-connector-python==8.0.28\n```\n\n# How to Use:\n\nCreate a new file named requirements.txt in your project directory.\nCopy the above dependencies into `requirements.txt`.\n\nInstall these dependencies using pip:\n\n```text\npip install -r requirements.txt\n```\nBy including these dependencies in your requirements.txt file, you ensure that anyone setting up your FastAPI project can easily install the necessary packages with a single command.\n\n# Install uvicorn Globally\n\nUVICORN is an ASGI (Asynchronous Server Gateway Interface) web server implementation tailored for Python.\n```text\npip install uvicorn\n```\nTo run it: \n```text\nuvicorn main:app --reload\n\npython -m uvicorn main:app --reload\n```\n\nOnce uvicorn starts your FastAPI application successfully, you should see output indicating that the server is running, usually on `http://127.0.0.1:8000` by default.\n\n### Terminate the Server:\n\nTo stop the FastAPI application, press `Ctrl + C` in the terminal or command prompt where the server is running.\n\n### MySQL Server\n\n```text\nimport mysql.connector\nfrom mysql.connector import Error\n\ndef create_connection():\n    connection = None\n    try:\n        connection = mysql.connector.connect(\n            host=\"localhost\",\n            user=\"root\",\n            password=\"1234\",\n            database=\"school\"\n        )\n        print(\"Connection to MySQL DB successful\")\n    except Error as e:\n        print(f\"The error '{e}' occurred\")\n    return connection\n```\n**host:** The hostname or IP address where your MySQL server is running. Typically, if it's on your local machine, you use \"localhost\".\n\n**user:** The username to authenticate with the MySQL server.\n\n**password:** The password corresponding to the username for authentication.\n\n**database:** The name of the database you want to connect to.\n\n### Create Database and Table:\n\n```text\nCREATE DATABASE school;\nUSE school;\nCREATE TABLE students (\n    id INT AUTO_INCREMENT PRIMARY KEY,\n    name VARCHAR(100) NOT NULL,\n    age INT NOT NULL,\n    grade VARCHAR(10) NOT NULL\n);\n```\n### Explanation:\n\n1. **CREATE DATABASE**: This SQL command creates a new database named school.\n2. **USE school**: Sets the school database as the current working database.\n3. **CREATE TABLE students**: Defines a table named students within the school database. It includes columns `id`(auto-incremented integer and primary key), `name` (string), `age` (integer), and `grade` (string).\n\n## CRUD:\n\nTo perform CRUD operations on your FastAPI application using Postman, you'll use HTTP methods (`POST`, `GET`, `PUT`, `DELETE`) to interact with your API endpoints. \n\nHere’s how you can set up and execute these commands in Postman:\n\n### Prerequisites:\n\nEnsure your FastAPI application is running using uvicorn as explained earlier.\n\n### 1. Create a Student (POST Request)\n\nMethod: **POST**\n\nURL: http://127.0.0.1:8000/students/\n\n#### Headers:\n\n- **Content-Type**: application/json\n\n- **Accept**: application/json\n\n```text\n{\n  \"name\": \"John Doe\",\n  \"age\": 21,\n  \"grade\": \"A\"\n}\n```\nClick `Send`. You should receive a response confirming the creation of the student.\n\n### 2. Get All Students (GET Request)\n\nMethod: **GET**\n\nURL: http://127.0.0.1:8000/students/\n\n#### Headers:\n\n- **Accept**: application/json\n\nClick `Send`. You should receive a response with a list of all students.\n\n\n### 3. Get a Student by ID (GET Request)\n\nMethod: **GET**\n\nURL: http://127.0.0.1:8000/students/{student_id}\n\nReplace `{student_id}` with the ID of the student you want to fetch.\n\n#### Headers:\n\n- **Accept**: application/json\n\nClick `Send`. You should receive a response with the student details if the student exists.\n\n\n### 4. Update a Student (PUT Request)\n\nMethod: **PUT**\n\nURL: http://127.0.0.1:8000/students/{student_id}\n\nReplace `{student_id}` with the ID of the student you want to update.\n\n#### Headers:\n\n- **Content-Type**: application/json\n\n- **Accept**: application/json\n\n```text\n{\n  \"name\": \"Jane Doe\",\n  \"age\": 22,\n  \"grade\": \"A+\"\n}\n```\n\n### 5. Delete a Student (DELETE Request)\n\nMethod: **DELETE**\n\nURL: http://127.0.0.1:8000/students/{student_id}\n\nReplace `{student_id}` with the ID of the student you want to delete.\n\n#### Headers:\n\n- **Accept**: application/json\n\nClick `Send`. You should receive a response confirming the deletion of the student.\n\n### Notes:\n- Ensure the FastAPI server `(uvicorn main:app --reload)` is running while testing with Postman.\n\n- Adjust the URL `(127.0.0.1:8000)` and endpoint paths `(/students/, /students/{student_id})` based on the FastAPI application's configuration.\n\n- Verify each operation's success through Postman's response and status codes `(200 OK, 201 Created, 204 No Content, 404 Not Found, etc.)`.\n\nBy following these steps, we can effectively test the FastAPI application's CRUD operations using Postman, ensuring that the API endpoints behave as expected when interacting with the MySQL database.\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprateekmaj21%2Fstudents_db_sql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprateekmaj21%2Fstudents_db_sql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprateekmaj21%2Fstudents_db_sql/lists"}