Parking Management System in Python with Source Code

Parking Management System

In this blog post, we delve into the creation of a Parking Management System using Python. Managing parking spaces efficiently is a challenge for many facilities, and this system automates the process, allowing for easy vehicle allocation, exit management, and fee calculation. With a step-by-step guide and source code, this post aims to help you build a functional system, providing a scalable solution for real-world parking problems, all while simplifying the user experience.


Importance

Imagine pulling into a busy shopping mall or office complex, where finding a parking spot feels like searching for a needle in a haystack. Time ticks away, stress builds, and you end up circling the lot, frustrated. It’s a daily experience for many.

A Parking Management System addresses this problem by organizing and automating the parking process. It ensures that parking spaces are utilized efficiently, reducing the stress and confusion associated with finding a spot. For parking facility operators, it’s a lifesaver—automating the allocation of spaces, tracking vehicle entries and exits, and generating reports that keep operations running smoothly.

Download New Real Time Projects :-Click here



Core Features

A well-constructed Parking Management System should include several essential features:

  1. Parking Space Allocation – Efficiently assign available parking spots to incoming vehicles.
  2. Vehicle Entry and Exit Management – Record vehicle entry and exit times, ensuring accurate billing and tracking.
  3. Fee Calculation – Calculate parking fees based on the duration of the stay.
  4. Real-Time Monitoring – Provide real-time status updates on parking space availability.
  5. Reports and Logs – Generate logs and reports for daily operations and management.
See also  Inventory Management System in Python with Source Code

https://updategadh.com/category/php-project


Building

To help you get started, here’s a step-by-step guide to creating a basic Parking Management System. The source code provided below covers essential features like vehicle entry and exit, parking space allocation, and fee calculation.

1. Setting Up the Environment

Ensure you have Python installed on your machine, along with an Integrated Development Environment (IDE) like PyCharm or VS Code. You will also need the SQLite library to store vehicle and parking data.

2. Designing the Database

We’ll use SQLite to create a database for managing vehicle records and parking space allocation.

import sqlite3

def create_database():
    conn = sqlite3.connect('parking_management.db')
    c = conn.cursor()
    c.execute('''CREATE TABLE IF NOT EXISTS parking_spots
                 (spot_id INTEGER PRIMARY KEY, is_occupied INTEGER)''')
    c.execute('''CREATE TABLE IF NOT EXISTS vehicles
                 (vehicle_id INTEGER PRIMARY KEY, vehicle_number TEXT, 
                 entry_time TEXT, exit_time TEXT, spot_id INTEGER)''')
    conn.commit()
    conn.close()

create_database()

3. Allocating Parking Spaces

We’ll implement a function that assigns a parking spot to an incoming vehicle. It checks for the first available spot and updates the database.

import datetime

def allocate_parking(vehicle_number):
    conn = sqlite3.connect('parking_management.db')
    c = conn.cursor()

    # Find the first available spot
    c.execute("SELECT spot_id FROM parking_spots WHERE is_occupied = 0 LIMIT 1")
    available_spot = c.fetchone()

    if available_spot:
        spot_id = available_spot[0]
        entry_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')

        # Assign the spot to the vehicle
        c.execute("INSERT INTO vehicles (vehicle_number, entry_time, spot_id) VALUES (?, ?, ?)", 
                  (vehicle_number, entry_time, spot_id))
        c.execute("UPDATE parking_spots SET is_occupied = 1 WHERE spot_id = ?", (spot_id,))

        print(f"Vehicle {vehicle_number} has been allocated to spot {spot_id}.")
    else:
        print("No parking spots available.")

    conn.commit()
    conn.close()

# Example usage:
allocate_parking("ABC123")

4. Managing Vehicle Exits

When a vehicle exits, we’ll record the exit time and calculate the total parking duration and fee.

def vehicle_exit(vehicle_number):
    conn = sqlite3.connect('parking_management.db')
    c = conn.cursor()

    # Find the vehicle and update exit time
    exit_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    c.execute("UPDATE vehicles SET exit_time = ? WHERE vehicle_number = ? AND exit_time IS NULL", 
              (exit_time, vehicle_number))

    # Calculate fee based on parking duration
    c.execute("SELECT entry_time, spot_id FROM vehicles WHERE vehicle_number = ? AND exit_time = ?", 
              (vehicle_number, exit_time))
    vehicle_info = c.fetchone()

    if vehicle_info:
        entry_time = datetime.datetime.strptime(vehicle_info[0], '%Y-%m-%d %H:%M:%S')
        spot_id = vehicle_info[1]
        parking_duration = (datetime.datetime.now() - entry_time).total_seconds() / 3600  # in hours
        fee = parking_duration * 10  # assuming $10 per hour

        print(f"Vehicle {vehicle_number} parked for {parking_duration:.2f} hours. Fee: ${fee:.2f}")

        # Free up the parking spot
        c.execute("UPDATE parking_spots SET is_occupied = 0 WHERE spot_id = ?", (spot_id,))
    else:
        print(f"Vehicle {vehicle_number} not found.")

    conn.commit()
    conn.close()

# Example usage:
vehicle_exit("ABC123")

Screenshot-2024-10-10-175852-1024x620 Parking Management System in Python with Source Code
Parking Management System
Screenshot-2024-10-10-175919-1024x521 Parking Management System in Python with Source Code
Parking Management System
Screenshot-2024-10-10-175931-1024x627 Parking Management System in Python with Source Code
Parking Management System
Parking Management System

Emotional Impact of Parking Management

Imagine the relief of driving into a parking lot, knowing exactly where to park. No circling the lot, no anxiety over finding a space. This is the emotional benefit of a well-built Parking Management System. It eliminates the uncertainty and stress that often accompany parking, giving drivers and operators peace of mind.

See also  Instagram Clone Using HTML, CSS with Free Code

For parking managers, this system automates daily tasks, reduces errors, and provides real-time insights into parking operations. It’s not just a software solution; it’s a way to improve efficiency, reduce frustration, and enhance the overall experience for everyone involved.


Post Comment