Employee Management System Project in Python Source Code

What is Employee Management System Project in Python?

The Employee Management System Project in Python is a beginner-friendly Python project that will teach them how to create web-based Python projects.

We will supply you with the complete source code and database for the Python project so that you can quickly install it on your machine and begin learning Python programming.

Employee Management System Project in Python: Project Details and Technology

Project Name:Employee Management System Project in Python
AbstractAn employee management system is a software, that helps your employees to give their best efforts every day to achieve the goals of your organization.
Language/s Used:Python
Python version (Recommended):3.8/3.9
Database:MySQL
Type:Desktop Application
Developer:Source Code Hero
Updates:0
Employee Management System Project in Python With Source Code – Project Information

Why is Employee Management System in Python Important?

Why is Employee Management System in Python Important?


Employee Management System aids in the automation of manual processes, saving both time and money. This system safeguards the professional and personal information of employees and the firm.

HR and business managers are relieved of their burdens and pressures thanks to the personnel management system.

Employee Management System Project in Python

A Employee Management System Project in Python is created in Python Programming Language using PyCharm Community IDE.

This Simple Project was developed using console based and connected into MySQL Database as the system’s Back-end.

Goal of the Simple Employee Management System Project in Python with Source Code

The goal is to construct a Python-based database-driven Employee Management System that stores data in a MySQL database.

The following operations will be included in the script from Employee Management System Project Report in Python:

  • Add Employee
  • Remove Employee
  • Promote Employee
  • Display Employees

The idea is that we use different functions to perform different changes in our Employee Record, for example, the Add Employee function will insert a new row in our Employee table, and we will also create a Remove Employee Function that will delete the record of any existing employee in our Employee table.

This system is based on the concepts of retrieving data from a database, making necessary modifications to the obtained data, and applying the changes to the record, as seen in our Promote Employee System.

We can also use the Display Employee function to get information about all of the current employees. The biggest benefit of linking our software to the database is that the information is preserved even after we close it several times.

How do you create an employee management system in Python?

How do you create an employee management system in Python?

We need to link Python to MySQL in order to create an Employee Management System in Python that uses MySQL as a database.

Create Database

First create database named “emp“.

Create Database Table

Second after creating database, create a table named “empd” and table fields : “id“, “name“, “post“, “salary“.

after that copy all the code given below.

The code given below is for the connection under Python and MySQL

import mysql.connector

# making Connection
con = mysql.connector.connect(
host="localhost", user="root", password="", database="emp")

Check Employee Function

The check employee function accepts an employee id as an argument and examines whether the employee details record contains any employees with that id.

It uses the cursor.rowcount() function to check this, which counts the number of rows that match the specified details. It is a utility function that will be used in later operations such as the Add employee function, among others.

Program:

# Function To Check if Employee with
# given Id Exist or Not
def check_employee(employee_id):
    # Query to select all Rows f
    # rom employee Table
    sql = 'select * from empd where id=%s'

    # making cursor buffered to make
    # rowcount method work properly
    c = con.cursor(buffered=True)
    data = (employee_id,)

    # Executing the SQL Query
    c.execute(sql, data)

    # rowcount method to find
    # number of rows with given values
    r = c.rowcount
    if r == 1:
        return True
    else:
        return False

Add Employee Function

The Add Employee function will ask for the Employee Id and then use the check employee function to see if the employee to be added already exists in our database or not.

If the employee details do not already exist, the Add Employee function will ask for the employee’s name, job title, and salary.

Now, after receiving all of these facts from the system’s user, it simply enters the data into our Employee details table.

Program:

# Function to mAdd_Employee
def Add_Employ():
    Id = input("Enter Employee Id : ")

    # Checking if Employee with given Id
    # Already Exist or Not
    if (check_employee(Id) == True):
        print("Employee aready exists\nTry Again\n")
        menu()

    else:
        Name = input("Enter Employee Name : ")
        Post = input("Enter Employee Post : ")
        Salary = input("Enter Employee Salary : ")
        data = (Id, Name, Post, Salary)

        # Inserting Employee details in
        # the Employee Table
        sql = 'insert into empd values(%s,%s,%s,%s)'
        c = con.cursor()

        # Executing the SQL Query
        c.execute(sql, data)

        # commit() method to make changes in
        # the table
        con.commit()
        print("Employee Added Successfully ")
        menu()

Remove Employee Function

Because Id is the primary key in our Employee Details Record, the Remove Employee Function will simply ask for the Id of the employee to be deleted.

There can be two employees with the same name, but they must have a unique id. The Remove Employee function uses the check employee function to see if the employee to be deleted is already in our database.

If they are, the Remove Employee function gets a valid employee id and deletes the record corresponding to that id.

Program:

# Function to Remove Employee with given Id
def Remove_Employ():
    Id = input("Enter Employee Id : ")

    # Checking if Employee with given Id Exist
    # or Not
    if (check_employee(Id) == False):
        print("Employee does not  exists\nTry Again\n")
        menu()
    else:

        # Query to Delete Employee from Table
        sql = 'delete from empd where id=%s'
        data = (Id,)
        c = con.cursor()

        # Executing the SQL Query
        c.execute(sql, data)

        # commit() method to make changes in
        # the table
        con.commit()
        print("Employee Removed")
        menu()

Promote Employee Function

The Promote Employee function will ask for the employee’s id and then use the check employee function to see if the employee to be promoted already exists in our database.

If so, it will ask for the amount by which his salary will be increased. It increases the salary of the employee with the supplied id by the given amount after collecting the valid details.

Program:

# Function to Promote Employee
def Promote_Employee():
    Id = int(input("Enter Employ's Id"))

    # Checking if Employee with given Id
    # Exist or Not
    if (check_employee(Id) == False):
        print("Employee does not  exists\nTry Again\n")
        menu()
    else:
        Amount = int(input("Enter increase in Salary"))

        # Query to Fetch Salary of Employee
        # with given Id
        sql = 'select salary from empd where id=%s'
        data = (Id,)
        c = con.cursor()

        # Executing the SQL Query
        c.execute(sql, data)

        # Fetching Salary of Employee with given Id
        r = c.fetchone()
        t = r[0] + Amount

        # Query to Update Salary of Employee with
        # given Id
        sql = 'update empd set salary=%s where id=%s'
        d = (t, Id)

        # Executing the SQL Query
        c.execute(sql, d)

        # commit() method to make changes in the table
        con.commit()
        print("Employee Promoted")
        menu()

Display Employee Function

The Display Employees function is basically a SQL select query that retrieves and prints all of the records in the employee information table line by line.

Program:

# Function to Display All Employees
# from Employee Table
def Display_Employees():
    # query to select all rows from
    # Employee Table
    sql = 'select * from empd'
    c = con.cursor()

    # Executing the SQL Query
    c.execute(sql)

    # Fetching all details of all the
    # Employees
    r = c.fetchall()
    for i in r:
        print("Employee Id : ", i[0])
        print("Employee Name : ", i[1])
        print("Employee Post : ", i[2])
        print("Employee Salary : ", i[3])
        print("---------------------\
        -----------------------------\
        ------------------------------\
        ---------------------")

    menu()

Menu Function

The Menu function shows the user a menu and asks him to select an option for actions such as Add employee, Remove employee, and so on.

Program:

# menu function to display menu
def menu():
    print("Welcome to Employee Management Record")
    print("Press ")
    print("1 to Add Employee")
    print("2 to Remove Employee ")
    print("3 to Promote Employee")
    print("4 to Display Employees")
    print("5 to Exit")

    ch = int(input("Enter your Choice "))
    if ch == 1:
        Add_Employ()
    elif ch == 2:
        Remove_Employ()
    elif ch == 3:
        Promote_Employee()
    elif ch == 4:
        Display_Employees()
    elif ch == 5:
        exit(0)
    else:
        print("Invalid Choice")
        menu()

Complete Source Code

# importing mysql connector
import mysql.connector

# making Connection
con = mysql.connector.connect(
    host="localhost", user="root", password="", database="emp")


# Function to mAdd_Employee
def Add_Employ():
    Id = input("Enter Employee Id : ")

    # Checking if Employee with given Id
    # Already Exist or Not
    if (check_employee(Id) == True):
        print("Employee aready exists\nTry Again\n")
        menu()

    else:
        Name = input("Enter Employee Name : ")
        Post = input("Enter Employee Post : ")
        Salary = input("Enter Employee Salary : ")
        data = (Id, Name, Post, Salary)

        # Inserting Employee details in
        # the Employee Table
        sql = 'insert into empd values(%s,%s,%s,%s)'
        c = con.cursor()

        # Executing the SQL Query
        c.execute(sql, data)

        # commit() method to make changes in
        # the table
        con.commit()
        print("Employee Added Successfully ")
        menu()


# Function to Promote Employee
def Promote_Employee():
    Id = int(input("Enter Employ's Id"))

    # Checking if Employee with given Id
    # Exist or Not
    if (check_employee(Id) == False):
        print("Employee does not  exists\nTry Again\n")
        menu()
    else:
        Amount = int(input("Enter increase in Salary"))

        # Query to Fetch Salary of Employee
        # with given Id
        sql = 'select salary from empd where id=%s'
        data = (Id,)
        c = con.cursor()

        # Executing the SQL Query
        c.execute(sql, data)

        # Fetching Salary of Employee with given Id
        r = c.fetchone()
        t = r[0] + Amount

        # Query to Update Salary of Employee with
        # given Id
        sql = 'update empd set salary=%s where id=%s'
        d = (t, Id)

        # Executing the SQL Query
        c.execute(sql, d)

        # commit() method to make changes in the table
        con.commit()
        print("Employee Promoted")
        menu()


# Function to Remove Employee with given Id
def Remove_Employ():
    Id = input("Enter Employee Id : ")

    # Checking if Employee with given Id Exist
    # or Not
    if (check_employee(Id) == False):
        print("Employee does not  exists\nTry Again\n")
        menu()
    else:

        # Query to Delete Employee from Table
        sql = 'delete from empd where id=%s'
        data = (Id,)
        c = con.cursor()

        # Executing the SQL Query
        c.execute(sql, data)

        # commit() method to make changes in
        # the table
        con.commit()
        print("Employee Removed")
        menu()


# Function To Check if Employee with
# given Id Exist or Not
def check_employee(employee_id):
    # Query to select all Rows f
    # rom employee Table
    sql = 'select * from empd where id=%s'

    # making cursor buffered to make
    # rowcount method work properly
    c = con.cursor(buffered=True)
    data = (employee_id,)

    # Executing the SQL Query
    c.execute(sql, data)

    # rowcount method to find
    # number of rows with given values
    r = c.rowcount
    if r == 1:
        return True
    else:
        return False


# Function to Display All Employees
# from Employee Table
def Display_Employees():
    # query to select all rows from
    # Employee Table
    sql = 'select * from empd'
    c = con.cursor()

    # Executing the SQL Query
    c.execute(sql)

    # Fetching all details of all the
    # Employees
    r = c.fetchall()
    for i in r:
        print("Employee Id : ", i[0])
        print("Employee Name : ", i[1])
        print("Employee Post : ", i[2])
        print("Employee Salary : ", i[3])
        print("---------------------\
        -----------------------------\
        ------------------------------\
        ---------------------")

    menu()


# menu function to display menu
def menu():
    print("Welcome to Employee Management Record")
    print("Press ")
    print("1 to Add Employee")
    print("2 to Remove Employee ")
    print("3 to Promote Employee")
    print("4 to Display Employees")
    print("5 to Exit")

    ch = int(input("Enter your Choice "))
    if ch == 1:
        Add_Employ()
    elif ch == 2:
        Remove_Employ()
    elif ch == 3:
        Promote_Employee()
    elif ch == 4:
        Display_Employees()
    elif ch == 5:
        exit(0)
    else:
        print("Invalid Choice")
        menu()


# Calling menu function
menu()

Project Output

Employee Management System Project in Python Output
Employee Management System Project in Python Output

To start executing Employment Management System Project in Python, make sure that you have installed Python 3.9 and PyCharm in your computer.

How to run Employee Management System Project in Python

These are the steps on how to run Employee Management System Project in Python With Source Code

Time needed: 5 minutes.

Employee Management System Project in Python

  • Step 1: Download the given source code below.

    First, download the given source code below and unzip the source code.
    movie ticket booking system in php

  • Step 2: Extract zip.

    Next, right click the zip file and extract file.

  • Step 3: Import the project to your PyCharm IDE

    Next, import the source code you’ve download to your PyCharm IDE.
    Blackjack Game In Python

  • Step 4: Run the project.

    Last, right click and click run.
    Space Invaders Game In Python

Download Source Code below

Summary

This Employee Management System Project in Python with MySQL is a easy console based machine that’s very clean to apprehend and use.

Talking approximately the gadget, it contains all of the basic functions which consist of creating a new employee, remove employee record, promote employee and display all employee records.

Inquiries

If you have any questions or suggestions about Employee Management System Project in Python With Source Code, please feel free to leave a comment below.

Leave a Comment