0% found this document useful (0 votes)
13 views22 pages

Python SQL Inventory Management System

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views22 pages

Python SQL Inventory Management System

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

INDEX

[Link] CONTENT PAGE NO.

1 PREFACE 2

2 AIM OF THE PROJECT 3

3 HARDWARE AND SOFTWARE REQUIREMENT 4

4 INTRODUCTION OF PYTHON 5

5 INTRODUCTION OF SQL 7

6 SOURCE CODE 10

7 SAMPLE OUTPUT 14

8 FUTURE IMPLEMENTATION 19

9 CONCLUSION 20

21
10 BIBLIOGRAPHY

PREFACE

1
In today’s world, computer technology is used in almost every field to make work

faster, easier, and more accurate. One such important area is Inventory

Management, which means keeping a record of all the goods and materials that a

business owns — such as their quantity, price, and availability.

Managing inventory manually using paper or spreadsheets can be time-consuming

and may lead to errors. To overcome these problems, computerized systems are

developed using programming languages and databases.

This project — “Inventory Management System using Python and SQL” — is designed to

maintain and organize stock records efficiently. It helps in storing, updating, deleting, and

displaying product information such as product ID, name, quantity, and price. The system

makes it easy for users to check the availability of items, add new products, update

quantities when stock changes, and remove items that are no longer available.

AIM

2
To design a python-based Inventory management system that connects with a MySQL
database to store, update, delete, and view product details efficiently.

Objectives of the Project


1. To maintain records of all products in a database with details such as
product ID, name, quantity, and price.
2. To automate inventory management so that adding, updating, deleting,
and viewing data becomes faster and easier.
3. To use Python and MySQL connectivity for storing and managing data
safely.
4. To provide a user-friendly interface where the user can perform operations
easily through menu options.
5. To ensure data accuracy and reliability by storing information in a
structured format.
6. To reduce manual errors that commonly occur during paper-based
recordkeeping.
7. To demonstrate the practical use of database connectivity in real-life
applications.

3
HARDWARE AND SOFTWARE REQURIMENT

Hardware Requirements

1. Computer/Laptop – with any basic processor (like Intel i3 or above)

2. RAM: Minimum 4 GB

3. Hard Disk Space: Around 500 MB free space

4. Monitor, Keyboard, and Mouse – for typing and viewing output

5. Printer (optional) – for printing your project report

Software Requirements

1. Operating System: Windows 10 or above (or Linux/Mac)

2. Python: Version 3.8 or higher

3. MySQL Server: Version 5.7 or 8.0

4. MySQL Connector for Python: mysql-connector-python

5. Editor/IDE: IDLE, VS Code, or PyCharm (any one)

6. MySQL Workbench or Command Line – to manage database

4
INTRODUCTION OF PYTHON

PYTHON:
Python is a high-level, interpreted scripting language developed in the late 1980s by

Guido van Rossum at the National Research Institute for Mathematics and Computer

Science in the Netherlands. The initial version was published at the alt. sources

newsgroup in 1991, and version was released in 1994.

Python 2.0 was released in 2000, and the 2.x versions were the prevalent releases until

December 2008. At that time, the development team made the decision to release version

3.0, which contained a few relatively small but significant changes that were not

backward compatible with the 2.x versions. Python 2 and 3 are very similar, and some

features of Python 3 have been backported to Python 2. But in general, they remain not

quite compatible. Python is Simple As programming languages go, Python is relatively

uncluttered, and the developers have deliberately kept it that way. A rough estimate of the

complexity of a language can be gleaned from the number of keywords or reserved words

in the language. These are words that are reserved for special meaning by the compiler or

interpreter because they designate specific built-in functionality of the language. Python 3

has 33 keywords, and Python 2 has 31. By contrast, C++ has 62, Java has 53, and Visual

5
Basic has more than 120, though these latter examples probably vary somewhat by

implementation or dialect.

Python Functions & Methods

 Function: A block of code that performs a specific task (e.g., def

add_product():).

 Method: A function that belongs to an object (e.g., [Link]()).

 Built-in functions: Ready-made functions like print(), input(), int(), etc.

6
INTODUCTION OF MYSQL

MYSQL:
Database Management System & Types of DBMS: A Database Management
System (DBMS) is a software application that interacts with the user, applications and the
database itself to capture and analyse data. The data stored in the database can be
modified, retrieved and deleted, and can be of any type like strings, numbers, images etc.

Types of DBMS:

There are mainly 4 types of DBMS, which are Hierarchical, Relational, Network, and
Object-Oriented DBMS.

Hierarchical DBMS : As the name suggests, this type of DBMS has a style of
predecessor- successor type of relationship. So, it has a structure similar to that of a tree,
wherein the nodes represent records and the branches of the tree represent fields.

Relational DBMS (RDBMS): This type of DBMS, uses a structure that allows the users to
identify and access data in relation to another piece of data in the database.

Network DBMS: This type of DBMS supports many to many relations wherein multiple
member records can be linked.

Object-oriented DBMS: This type of DBMS uses small individual software called objects.
Each object contains a piece of data, and the instructions for the actions to be done with
the data.

7
Structured Query Language (SQL)

SQL is the core of a relational database which is used for accessing and managing the
database. By using SQL, you can add, update or delete rows of data, retrieve subsets of
information, modify databases and perform many actions. The different subsets of SQL
are as follows:

DDL (Data Definition Language) –It allows you to perform various operations on the
database such as CREATE, ALTER and DELETE objects.

DML (Data Manipulation Language)– It allows you to access and manipulate data. It
helps you to insert, update, delete and retrieve data from the database.

DCL (Data Control Language)– It allows you to control access to the database. Example –
Grant or Revoke access permissions.

TCL (Transaction Control Language) – It allows you to deal with the transaction of the
database. Example – Commit, Rollback, Savepoint, Set Transaction.

SQL Functions & Commands

 SQL Commands: Instructions to manage data in a database.

o DDL: Defines structure → CREATE, USE, SHOW.

o DML: Manages data → INSERT, SELECT, UPDATE, DELETE.

SQL Functions: Built-in operations like AUTO_INCREMENT, CURRENT_TIMESTAMP

8
Python MySQL Database Connection

Arguments required to connect MySQL from Python

You need to know the following detail of the MySQL server to perform the connection
from Python.

Username – i.e., the username that you use to work with MySQL Server. The default
username for the MySQL database is a root

Password – Password is given by the user at the time of installing the MySQL database. If
you are using root then you won’t need the password.

Host Name – is the server name or Ip address on which MySQL is running. if you are
running on localhost, then you can use localhost, or it’s IP, i.e. [Link]

Database Name – Database name to which you want to connect.

READ Operation: READ Operation on any database means to fetch some useful
information from the database.

Once our database connection is established, you are ready to make a query into this
database. You can use either

fetchone() method to fetch single record or fetchall() method to fetech multiple values
from a database table.

fetchone() − It fetches the next row of a query result set. A result set is an object that is
returned when a cursor object is used to query a table.

fetchall() − It fetches all the rows in a result set. If some rows have already been extracted
from the result set, then it retrieves the remaining rows from the results

9
PYTHON CODE

# Inventory Management System (Simple Version)


import [Link]

# ------------------- Database Connection -------------------


connection = [Link](
host="localhost",
user="root",
password="12345678"
)
cursor = [Link]()

# Create database if not exists


[Link]("CREATE DATABASE IF NOT EXISTS INVENTORY")
[Link]("USE INVENTORY")

# Create table for products


[Link]("""
CREATE TABLE IF NOT EXISTS stock (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
quantity INT,
price FLOAT

10
)
""")

print("\n✅ Database and Table Ready!\n")

# ------------------- Functions -------------------

def add_product():
name = input("Enter product name: ")
quantity = int(input("Enter quantity: "))
price = float(input("Enter price: "))

[Link]("INSERT INTO stock (name, quantity, price) VALUES (%s, %s, %s)",
(name, quantity, price))
[Link]()
print("✔ Product added successfully!\n")

def view_products():
[Link]("SELECT * FROM stock")
data = [Link]()
print("\n📦 Current Stock:")
for row in data:
print(f"ID: {row[0]} | Name: {row[1]} | Quantity: {row[2]} | Price: ₹{row[3]}")
print()

11
def update_product():
product_id = int(input("Enter product ID to update: "))
new_quantity = int(input("Enter new quantity: "))
[Link]("UPDATE stock SET quantity = %s WHERE id = %s", (new_quantity,
product_id))
[Link]()
print("✔ Product updated successfully!\n")

def delete_product():
product_id = int(input("Enter product ID to delete: "))
[Link]("DELETE FROM stock WHERE id = %s", (product_id,))
[Link]()
print("✔ Product deleted successfully!\n")

# ------------------- Menu -------------------


while True:
print("========== INVENTORY MENU ==========")
print("1. Add Product")
print("2. View Products")
print("3. Update Product Quantity")
print("4. Delete Product")
print("0. Exit")
print("====================================")

choice = input("Enter your choice: ")

12
if choice == '1':
add_product()
elif choice == '2':
view_products()
elif choice == '3':
update_product()
elif choice == '4':
delete_product()
elif choice == '0':
print("Exiting program. Thank you!")
break
else:
print("Invalid choice, please try again.\n")

# ------------------- Close Connection -------------------


[Link]()
[Link]()

SAMPLE OUTPUT

13
[Link] PRODUCT:
This option allows the user to add a new product to the inventory database.
When you choose this option, the program will ask for:

 Product Name
 Quantity (how many pieces are available)
 Price (price per item)

Once you enter the details, the product gets stored permanently in the database.

EXAMPLE:
PYTHON

SQL

[Link]
W PRODUCT:

14
This option displays all the products that are currently stored in the inventory.
It shows the product ID, Name, Quantity, and Price in a neat list.
It helps the user to:

 Check available stock


 See which items are low in quantity
 Verify if new items were added successfully

Example Output:

PYTHON

15
[Link] PRODUCT QUANTITY:
This option helps to change or increase the quantity of an existing product.
It’s useful when:

 New stock arrives

 You want to correct a wrong quantity

You just need to enter:

 The Product ID

 The New Quantity

The program updates the quantity directly in the database.

EXAPLE CODE:

PYTHON

SQL

4.D ELE
TE PRODUCT:

16
This option removes a product completely from the inventory. It is useful when:

 A product is no longer available in the shop

 A product was entered by mistake

You must enter the Product ID, and that product’s record will be deleted
permanently.

EXAMPLE OUTPUT:

PYTHON

SQL

[Link]:

17
This option is used to stop the program safely. It closes the database connection
and ends the menu loop.
It ensures that all changes made (additions, deletions, updates) are saved properly
before closing.

EXAMPLE OUTPUT:

PYTHON

18
Future Implementation
The current Inventory Management System is a basic version that allows adding,
viewing, updating, and deleting products. In the future, this system can be enhanced and
made more advanced with additional features to make it more useful for real shops or
businesses. Some possible improvements include:

1. Graphical User Interface (GUI):


Instead of the text-based menu, a user-friendly interface can be created using tools
like Tkinter or PyQt, making it easier for users to interact with the system.

2. Automatic Billing and Invoicing:


The system can generate professional bills and invoices automatically when a
customer makes a purchase. It could also save the bills in PDF format.

3. Stock Alerts:
Add a feature to notify the user when stock is low or about expired products,
helping in better inventory management.

4. Reports and Analytics:


The system can generate daily, weekly, or monthly sales reports, showing
revenue, best-selling products, and purchase trends.

5. Multi-User Access:
Different users, like a cashier and manager, can have separate login accounts
with restricted access to certain operations.

6. Integration with Barcode Scanners:


Adding support for barcode scanning will make adding and selling products faster
and reduce manual errors.

7. Cloud Database Storage:


Instead of a local MySQL database, the system can be connected to a cloud
database, allowing access from multiple devices and improving data security.

8. Mobile App Integration:


A mobile app version could allow shop owners to manage inventory remotely,
update stock, and check sales from their smartphones.

CONCLUSION

19
The Inventory Management System using Python and SQL is a practical and
efficient software solution designed to manage and organize stock records for
businesses, shops, or warehouses. Through this project, we have successfully
demonstrated the combination of Python programming and MySQL database
management to develop a system that is both user-friendly and reliable. The
system allows users to add new products, update existing records, search for
specific items, display all products, and delete unnecessary entries. By
automating these processes, the project significantly reduces the manual effort
required to maintain inventory records and minimizes the possibility of human
errors. This project demonstrates key concepts of database connectivity, CRUD
operations, and menu-driven programming, which are essential for real-world
applications. It shows how modern businesses can rely on computerized systems to
manage their stock efficiently rather than using traditional manual methods. The
project also provides a strong foundation for understanding the practical use of
programming in solving real-life problems. Additionally, the system is scalable and
can be enhanced with advanced features such as generating reports, automatic low-
stock alerts, sales tracking, and even a graphical user interface to improve usability.
By implementing this project, we gain valuable experience in designing a
functional software application, integrating Python with a database, and
understanding the importance of data management in business operations. In
conclusion, the Inventory Management System using Python and SQL is a useful,
reliable, and practical project that demonstrates how programming and databases
can be applied to real-world problems. It not only improves the accuracy and
efficiency of inventor management but also equips students with the knowledge
and skills to develop similar database-driven applications in the future.

Bibliography

20
1. Python Official Documentation – [Link] o Used

to understand Python syntax, functions, and modules like

[Link].

2. MySQL Official Documentation – [Link] o

Used to learn SQL commands such as CREATE, INSERT, SELECT,

UPDATE, and DELETE.

3. GeeksforGeeks, Python MySQL Database Connectivity –

[Link]

o Reference for connecting Python programs to MySQL database and

performing CRUD operations.

4. CBSE Class 12 Computer Science Practical Manual, NCERT, 2025.

o Used as a guide for project format and practical implementation.

21
22

You might also like