Inventory Management System in Python with Source Code

Inventory Management System in Python

In today’s fast-paced business environment, managing inventory effectively is crucial for maintaining smooth operations, especially for businesses that deal with physical goods. An Inventory Management System (IMS) can streamline stock handling, provide accurate data on available items, and optimize supply chain operations. In this blog post, we’ll walk through creating an Inventory Management System using Python, offering both source code and insights to build this essential tool.

Inventory Management System

Inventory is often referred to as the backbone of a business, as it ensures that products are available when needed, without overspending on stock that may not sell. An efficient system will help businesses:

  • Avoid overstocking and understocking, which can result in financial loss.
  • Track inventory in real-time, helping make data-driven decisions.
  • Forecast demand, improving operational efficiency.
  • Reduce human errors, leading to better stock management and increased profitability.

Features

  1. Add New Inventory Items: Users can add new items with details such as product name, quantity, price, and supplier.
  2. Update Inventory: Track stock levels and update them as items are sold or restocked.
  3. Delete Inventory: Remove obsolete or sold-out products.
  4. View Inventory: Display all current stock, making it easy to manage.
  5. Search Functionality: Search for specific products by their name or ID.
See also  E-Commerce Website Using Django Framework with Free Code

Step 1: Setting Up the Environment

New Project :-https://www.youtube.com/@Decodeit2

pip install pandas

We’ll use Pandas to handle the data in a tabular format.

Step 2: The Core Code

Here’s the main part of the Inventory Management System in Python:

import pandas as pd

class InventoryManagementSystem:
    def __init__(self):
        self.inventory = pd.DataFrame(columns=['Product ID', 'Product Name', 'Quantity', 'Price', 'Supplier'])

    def add_item(self, product_id, product_name, quantity, price, supplier):
        new_item = {'Product ID': product_id, 'Product Name': product_name, 'Quantity': quantity, 'Price': price, 'Supplier': supplier}
        self.inventory = self.inventory.append(new_item, ignore_index=True)
        print(f"{product_name} has been added to inventory.")

    def update_item(self, product_id, new_quantity):
        if product_id in self.inventory['Product ID'].values:
            self.inventory.loc[self.inventory['Product ID'] == product_id, 'Quantity'] = new_quantity
            print(f"Product ID {product_id}'s quantity updated to {new_quantity}.")
        else:
            print(f"Product with ID {product_id} not found.")

    def delete_item(self, product_id):
        if product_id in self.inventory['Product ID'].values:
            self.inventory = self.inventory[self.inventory['Product ID'] != product_id]
            print(f"Product ID {product_id} has been removed from inventory.")
        else:
            print(f"Product with ID {product_id} not found.")

    def view_inventory(self):
        if self.inventory.empty:
            print("Inventory is empty.")
        else:
            print("Current Inventory:")
            print(self.inventory)

    def search_item(self, product_name):
        result = self.inventory[self.inventory['Product Name'].str.contains(product_name, case=False)]
        if result.empty:
            print(f"No products found with the name '{product_name}'.")
        else:
            print(f"Search results for '{product_name}':")
            print(result)

# Example usage:
inventory_system = InventoryManagementSystem()

# Adding items
inventory_system.add_item(1, 'Laptop', 10, 800, 'TechSupplier')
inventory_system.add_item(2, 'Mouse', 50, 15, 'TechSupplier')

# Viewing inventory
inventory_system.view_inventory()

# Updating item quantity
inventory_system.update_item(1, 8)

# Deleting an item
inventory_system.delete_item(2)

# Searching for an item
inventory_system.search_item('laptop')

# Viewing updated inventory
inventory_system.view_inventory()
Screenshot-2024-10-04-171747 Inventory Management System in Python with Source Code
Inventory Management System in Python
Screenshot-2024-10-04-171758 Inventory Management System in Python with Source Code
Inventory Management System in Python
Screenshot-2024-10-04-171806 Inventory Management System in Python with Source Code
Inventory Management System in Python

PHP PROJECT:- CLICK HERE

Step 3: Explanation of Code

  • Initialization: The system uses a pandas DataFrame to store product information, including ID, name, quantity, price, and supplier.
  • Add Item: Adds new items to the inventory by appending them to the DataFrame.
  • Update Item: Updates the quantity of a product when it’s restocked or sold.
  • Delete Item: Removes a product from the inventory if it’s no longer available.
  • View Inventory: Displays the current state of the inventory.
  • Search Item: Allows searching for products by name, making it easier to locate specific items.
See also  Insurance Management System In Python Free Source Code

How to Run the Program

  1. Copy the code into your Python editor or IDE (such as PyCharm, Visual Studio Code, or Jupyter Notebook).
  2. Run the code: You can test it by adding, updating, and viewing inventory items.
  3. Modify: Customize it as per your business needs—whether for retail, warehouse management, or any other sector dealing with physical goods.

Future Enhancements

This basic inventory management system can be extended with more advanced features:

  • GUI Integration: Using frameworks like Tkinter or PyQt to create a user-friendly graphical interface.
  • Database Integration: Storing data in MySQL or SQLite instead of a DataFrame for better scalability.
  • Inventory Alerts: Automatic alerts when stock levels are low.
  • Reports Generation: Adding functionality to export inventory data to Excel or CSV for analysis.

2 comments

Post Comment