Parking Management System – Python MySQL Project


Parking management system Python MySQL project for class 12 computer science students. This project is designed as per the new reduced syllabus of class 12 computer science. The whole database is stored in MySQL in three tables. This project is designed to solve parking management. In this project, you can add as many parking types as well as as many spaces you want. with its powerful built-in searching facility, the current status of the parking can be checked.

Working of Parking Management System

Basic details of the Parking Management System 

  1. Front End:    Python
  2. Backend:    MySQL
  3. Total Tables used  : 3

Tables structures

This project is divided into three main tables  1.  parking_type   2. Parking_space  3. Transaction 4. Login

mysql> use parking_system;
Database changed
mysql> show tables;
+--------------------------+
| Tables_in_parking_system |
+--------------------------+
| login                    |
| parking_space            |
| parking_type             |
| transaction              |
+--------------------------+
4 rows in set (0.00 sec)

mysql> desc login;
+-------+----------+------+-----+---------+----------------+
| Field | Type     | Null | Key | Default | Extra          |
+-------+----------+------+-----+---------+----------------+
| id    | int(11)  | NO   | PRI | NULL    | auto_increment |
| name  | char(30) | YES  |     | NULL    |                |
| pwd   | char(30) | YES  |     | NULL    |                |
+-------+----------+------+-----+---------+----------------+
3 rows in set (0.01 sec)

mysql> select * from login;
+----+--------+------------+
| id | name   | pwd        |
+----+--------+------------+
|  1 | rakesh | ramji      |
|  2 | admin  | vidhyarthi |
+----+--------+------------+
2 rows in set (0.00 sec)

Login Table is used to store the login details of its users.

mysql> desc parking_type;
+-------+------------+------+-----+---------+----------------+
| Field | Type       | Null | Key | Default | Extra          |
+-------+------------+------+-----+---------+----------------+
| id    | int(11)    | NO   | PRI | NULL    | auto_increment |
| name  | char(20)   | YES  |     | NULL    |                |
| price | float(7,2) | YES  |     | NULL    |                |
+-------+------------+------+-----+---------+----------------+
3 rows in set (0.01 sec)

mysql> select * from parking_type;
+----+-------------+--------+
| id | name        | price  |
+----+-------------+--------+
|  1 | Two Wheelar |  30.00 |
|  2 | car         |  50.00 |
|  3 | bus         | 250.00 |
|  4 | Truck       | 350.00 |
|  5 | trolly      | 450.00 |
|  6 | Cycle       |  20.00 |
|  7 | cycle       |  20.00 |
|  8 | motor cycle |  20.00 |
|  9 | E-cycle     |  35.00 |
+----+-------------+--------+
9 rows in set (0.00 sec)

Parking_type Table contains the details of parking type available in this parking.

mysql> desc parking_space;
+---------+----------+------+-----+---------+----------------+
| Field   | Type     | Null | Key | Default | Extra          |
+---------+----------+------+-----+---------+----------------+
| id      | int(11)  | NO   | PRI | NULL    | auto_increment |
| type_id | int(11)  | YES  |     | NULL    |                |
| status  | char(20) | YES  |     | NULL    |                |
+---------+----------+------+-----+---------+----------------+
3 rows in set (0.01 sec)

mysql> select * from parking_space;
+----+---------+--------+
| id | type_id | status |
+----+---------+--------+
|  1 |       1 | full   |
|  2 |       2 | full   |
|  3 |       3 | open   |
|  4 |       4 | open   |
|  5 |       5 | open   |
|  6 |       1 | open   |
|  7 |       1 | open   |
|  8 |       1 | open   |
|  9 |       1 | open   |
| 10 |       1 | open   |
| 11 |       1 | open   |
| 12 |       1 | open   |
| 13 |       2 | open   |
| 14 |       2 | open   |
| 15 |       2 | open   |
| 16 |       2 | open   |
| 17 |       2 | open   |
| 18 |       2 | open   |
| 19 |       2 | open   |
| 20 |       3 | open   |
| 21 |       3 | open   |
| 22 |       3 | open   |
| 23 |       3 | open   |
| 24 |       3 | open   |
| 25 |       4 | open   |
| 26 |       4 | open   |
| 27 |       5 | open   |
| 28 |       5 | open   |
| 29 |       9 | open   |
| 30 |       9 | open   |
+----+---------+--------+
30 rows in set (0.00 sec)

Parking_space Table holds the details of all parking type space available in this parking.

mysql> desc transaction;
+------------+-------------+------+-----+---------+----------------+
| Field      | Type        | Null | Key | Default | Extra          |
+------------+-------------+------+-----+---------+----------------+
| id         | int(11)     | NO   | PRI | NULL    | auto_increment |
| vehicle_id | char(20)    | YES  |     | NULL    |                |
| parking_id | int(11)     | YES  |     | NULL    |                |
| entry_date | date        | YES  |     | NULL    |                |
| exit_date  | date        | YES  |     | NULL    |                |
| amount     | float(10,2) | YES  |     | NULL    |                |
+------------+-------------+------+-----+---------+----------------+
6 rows in set (0.00 sec)

mysql> select * from transaction;
+----+-------------+------------+------------+------------+--------+
| id | vehicle_id  | parking_id | entry_date | exit_date  | amount |
+----+-------------+------------+------------+------------+--------+
|  1 | dl14cb-1087 |          1 | 2021-03-08 | 2021-03-08 |  30.00 |
|  2 | dl13cb-1090 |         29 | 2021-03-09 | 2021-03-09 |  35.00 |
|  3 | dlcb-1090   |          1 | 2021-03-09 | NULL       |   NULL |
|  4 | dl13cd-1020 |          2 | 2021-03-09 | NULL       |   NULL |
+----+-------------+------------+------------+------------+--------+
4 rows in set (0.00 sec)

Transaction table actually store all the login and logout vehicle. The Null in exit_date defines that the vehicle is still in the parking.

The whole project is divided into 7 major parts.
1. Additon of Parking Type
2. Addition of Parking Space
3. Modification in parking Type and Parking Space
4. Login of Vehicle
5. Logout of vehicle
6. Search Parking
7. Reports

Download Parking Management System

Source code of Parking System in Python and MySQL

import mysql.connector 
import time
from datetime import date


global conn,cursor
conn = mysql.connector.connect(
    host='localhost', database=' parking_system', user='root', password='')
cursor = conn.cursor()


def clear():
  for _ in range(65):
     print()


def introduction():
    msg = '''
          PARKING MANAGEMENT  S Y S T E M 
          
          - An Introduction
          
          Parking is a very big problem in the matro cities, Day by day basis parking system are coming up with new technologoes to 
          solve this issue.  

          This project is also trying to solve this simple but very useful information for the parking management. The whole 
          database is store in MySQL table ParkingSystem that stores their parking slot information as well as how long a vehicle is parked in thier
          parking area and how much he/she need to pay for that. 

          Besides all these features it also track the total money collected during the period of time with its extensive searching and reporting
          system

          The whole project is divided into four major parts ie addition of data, modification, searching and 
          reporting. all these part are further divided into menus for easy navigation

          NOTE: Python is case-SENSITIVE so type exact Column Name wherever required.

          If you have any query or suggestions please contact me at rakesh@binarynote.com \n\n\n\n'''
    for x in msg:
        print(x, end='')
        time.sleep(0.002)
    wait = input('Press any key to continue.....')


def made_by():
    msg = ''' 
            Parking Management system made by           : xyx
            Roll No                                     : 1234
            School Name                                 : Your school name
            session                                     : 2020-21
            
            Thanks for evaluating my Project.
            \n\n\n
        '''

    for x in msg:
        print(x, end='')
        time.sleep(0.002)

    wait = input('Press any key to continue.....')

def display_parking_type_records():
    cursor.execute('select * from parking_type;')
    records = cursor.fetchall()
    for row in records:
        print(row)

def login():
    while True:
        clear()
        uname = input('Enter your id :')
        upass = input('Enter your Password :')
        cursor.execute('select * from login where name="{}" and pwd ="{}"'.format(uname,upass))
        cursor.fetchall()
        rows = cursor.rowcount
        if rows!=1:
            print('Invalid Login details..... Try again')
        else:
            print('You are eligible for operating this system............')
            print('\n\n\n')
            print('Press any key to continue...............')
            break


def add_parking_type_record():
    clear()
    name = input('Enter Parking Type( 1. Two wheelar 2. Car 3. Bus 4. Truck 5. Trolly ) : ')
    price =  input('Enter Parking Price per day : ')
    sql = 'insert into parking_type(name,price) values("{}",{});'.format(name,price)
    cursor.execute(sql)
    print('\n\n New Parking Type added....')
    cursor.execute('select max(id) from parking_type')
    no = cursor.fetchone()
    print(' New Parking Type ID is : {} \n\n\n'.format(no[0]))
    wait= input('\n\n\nPress any key to continue............')


def add_parking_slot_record():
    clear()
    parking_type_id = input(
        'Enter Parking Type( 1. Two wheelar 2. Car 3. Bus 4. Truck 5. Trolly ) :')
    status = input('Enter current Status ( Open/Full ) :')
    sql = 'insert into parking_space(type_id,status) values \
            ("{}","{}");'.format(parking_type_id,status) 
    cursor.execute(sql)
    print('\n\n New Parking Space Record added....')

    cursor.execute('select max(id) from parking_space;')
    no = cursor.fetchone()
    print(' Your Parking ID is : {} \n\n\n'.format(no[0]))
    display_parking_type_records()
    wait = input('\n\n\nPress any key to continue............')


def modify_parking_type_record():
    clear()
    print(' M O D I F Y   P A R K I N G   T Y P E  S C R E E N ')
    print('-'*100)
    print('1.  Parking Type Name \n')
    print('2.  Parking Price  \n')
    choice = int(input('Enter your choice :'))
    field=''
    if choice==1:
        field='name'
    if choice==2:
        field='price'
    
    park_id = input('Enter Parking Type ID :')
    value = input('Enter new values :')
    sql = 'update parking_type set '+ field +' = "' + value +'" where id ='+ park_id +';'
    cursor.execute(sql)
    print('Record updated successfully................')
    display_parking_type_records()
    wait = input('\n\n\nPress any key to continue............')



def modify_parking_space_record():
    clear()
    print(' M O D I F Y  P A R K I N G   S P A C E   R E C O R D ')
    print('-'*100)
    print('1.  Parking Type ID(1-Two Wheelar, 2: Car 3.Bus etc ):  ')
    print('2.  status  \n')
    choice = int(input('Enter your choice :'))
    field = ''
    if choice == 1:
        field = 'type_id'
    if choice ==2:
        field = 'status'
    print('\n\n\n')
    crime_id = input('Enter Parking Space ID  :')
    value = input('Enter new values :')
    sql = 'update parking_space set ' + field + \
        ' = "' + value + '" where id =' + crime_id + ';'
    cursor.execute(sql)
    print('Record updated successfully................')
    wait = input('\n\n\nPress any key to continue............')


def add_new_vehicle():
    clear()
    print('Vehicle Login Screen ')
    print('-'*100)
    vehicle_id = input('Enter Vehicle Number :' )
    parking_id = input('Enter parking ID :')
    entry_date = date.today()
    sql = 'insert into transaction(vehicle_id,parking_id,entry_date) values \
           ("{}","{}","{}");'.format(vehicle_id,parking_id,entry_date)
    cursor.execute(sql)
    cursor.execute('update parking_space set status ="full" where id ={}'.format(parking_id))
    print('\n\n\n Record added successfully.................')
    wait= input('\n\n\nPress any key to continue.....')


def remove_vehicle():
    clear()
    print('Vehicle Logout Screen')
    print('-'*100)
    vehicle_id = input('Enter vehicle No :')
    exit_date = date.today()
    sql = 'select parking_id,price,entry_date from transaction tr,parking_space ps, parking_type pt \
           where tr.parking_id = ps.id and ps.type_id = pt.id and \
           vehicle_id ="'+vehicle_id+'" and exit_date is NULL;'
    cursor.execute(sql)
    record = cursor.fetchone()
    days = (exit_date-record[2]).days 
    if days ==0:
        days = days+1
    amount = record[1]*days
    clear()
    print('Logout Details ')
    print('-'*100)
    print('Parking ID : {}'.format(record[0]))
    print('Vehicle ID : {}'.format(vehicle_id))
    print('Parking Date : {}'.format(record[2]))
    print('Current Date : {}'.format(exit_date))
    print('Amount Payable : {}'.format(amount))
    wait = input('press any key to continue......')
    # update transaction and parking space tables
    sql1 = 'update transaction set exit_date ="{}" , amount ={} where vehicle_id ="{}" \
            and exit_date is NULL;'.format(exit_date,amount, vehicle_id)
    sql2 =  'update parking_space set status ="open" where id = {}'.format(record[0])
    cursor.execute(sql1)
    cursor.execute(sql2)
    wait = input('Vehicle Out from our System Successfully.......\n Press any key to continue....')


def search_menu():
    clear()
    print(' S E A R C H  P A R K I N G  M E N U ')
    print('1.  Parking ID \n')
    print('2.  Vehicle Parked  \n')
    print('3.  Free Space \n')
    choice = int(input('Enter your choice :'))
    field = ''
    if choice == 1:
        field = 'id'
    if choice == 2:
        field = 'vehicle No'
    if choice == 3:
        field = 'status'
    value = input('Enter value to search :')
    if choice == 1 or choice==3:
        sql = 'select ps.id,name,price, status \
          from parking_space ps , parking_type pt where ps.id = pt.id AND ps.id ={}'.format(value)
    else:
        sql = 'select id,vehicle_id,parking_id,entry_date from transaction where exit_date is NULL;'

    cursor.execute(sql)
    results = cursor.fetchall()
    records = cursor.rowcount
    for row in results:
        print(row)
    if records < 1:
        print('Record not found \n\n\n ')
    wait = input('\n\n\nPress any key to continue......')


def parking_status(status):
    clear()
    print('Parking Status :',status)
    print('-'*100)
    sql ="select * from parking_space where status ='{}'".format(status)
    cursor.execute(sql)
    records = cursor.fetchall()
    for row in records:
        print(row)
    wait =input('\n\n\nPress any key to continue.....')

def vehicle_status_report():
    clear()
    print('Vehicle Status - Currently Parked')
    print('-'*100)
    sql='select * from transaction where exit_date is NULL;'
    cursor.execute(sql)
    records = cursor.fetchall()
    for row in records:
        print(row)
    wait =input('\n\n\nPress any key to continue.....')

def money_collected():
    clear()
    start_date = input('Enter start Date(yyyy-mm-dd): ')
    end_date = input('Enter End Date(yyyy-mm-dd): ')
    sql = "select sum(amount) from transaction where \
          entry_date ='{}' and exit_date ='{}'".format(start_date,end_date)
    cursor.execute(sql)
    result = cursor.fetchone()
    clear()
    print('Total money Collected from {} to {}'.format(start_date,end_date))
    print('-'*100)
    print(result[0])
    wait =input('\n\n\nPress any key to continue.....')


def report_menu():
    while True:
        clear()
        print(' P A R K I N G    R E P O R T S  ')
        print('-'*100)
        print('1.  Parking Types \n')
        print('2.  Free Space  \n')
        print('3.  Ocupied Space  \n')
        print('4.  Vehicle Status  \n')
        print('5.  Money Collected  \n')
        print('6.  Exit  \n')
        choice = int(input('Enter your choice :'))
        field = ''
        if choice == 1:
            display_parking_type_records()
        if choice == 2:
            parking_status("open")
        if choice == 3:
            parking_status("full")
        if choice == 4:
            vehicle_status_report()
        if choice == 5:
            money_collected()
        if choice ==6: 
            break
        



def main_menu():
    clear()
    login()
    clear()
    introduction()
    
    while True:
      clear()
      print(' P A R K I N G   M A N A G E M E N T    S Y S T E M')
      print('*'*100)
      print("\n1.  Add New Parking Type")
      print("\n2.  Add New Parking Slot")
      print('\n3.  Modify Parking Type Record')
      print('\n4.  Modify Parking Slot Record')
      print('\n5.  Vehicle Login ')
      print('\n6.  Vehicle Logout')
      print('\n7.  Search menu')
      print('\n8.  Report menu')
      print('\n9.  Close application')
      print('\n\n')
      choice = int(input('Enter your choice ...: '))

      if choice == 1:
        add_parking_type_record()

      if choice == 2:
        add_parking_slot_record()

      if choice == 3:
        modify_parking_type_record()
      
      if choice == 4:
        modify_parking_space_record()

      if choice == 5:
        add_new_vehicle()
      
      if choice == 6:
        remove_vehicle()

      if choice == 7:
        search_menu()
      
      if choice == 8:
        report_menu()
      
      if choice == 9:
        break
    made_by()


if __name__ == "__main__":
    main_menu()

Modules used in Parking System

The parking system uses two Python modules for connecting MySQL with python( MySQl.connector) and fetching the current date (date) from the system. Install Python correctly may help you to install any Python module on your system.

How to Run this project on Your System

The download file contains two files. 1

  1. Python Source code
  2. MySQL dump file

You are required to unzip the file in a folder and then using the command line client restore MySQL backup in your system. Now you need to open Python source code file and make necessory changes in this line

conn = mysql.connector.connect( host=’localhost’, database=’ parking_system’, user=’root’, password=”)

Since My System does not have any Password thus it is blank. You need to supply an appropriate MySQL password here in order to run this project succe

Conclusion of Parking management system

Though it is a small project and uses a command-line interface for basic functioning, I think, it can teach you the basics of the python project and how to manage multiple tables from python. If you want to improve its functioning, it’s yours all the way. Just download it and make changes as per your wish. In case if you find any bug then that is mine, but do not forget to tag me.

Print Friendly, PDF & Email

Related Posts

If you like CBSEToaday and would like to contribute, you can also write an article using submit article or mail your article to contribute@cbsetoday.com See your article appearing on the cbsetoday.com main page and help other students/teachers.