DEV Community

Mate Technologies
Mate Technologies

Posted on

πŸš€ Build a Real-Time Python Auction App (Beginner Guide)

In this tutorial, we’ll walk through building a real-time auction system using Python sockets, Tkinter GUIs, and SQLite. You’ll learn how the server works, how clients connect, and how auctions and bids update live.

πŸ‘‰ Full repository: https://github.com/rogers-cyber/auction-management-system

GitHub

πŸ“Œ What You’ll Build

βœ”οΈ A server that manages auctions and bid storage
βœ”οΈ An Admin app to create and manage auctions
βœ”οΈ A Bidder app to see auctions and place bids
βœ”οΈ Real-time updates across all apps via sockets

🧱 1. Initialize the Database

Inside server.py, we create an SQLite database that stores auctions and bids.

def init_db():
    conn = sqlite3.connect(DB_FILE)
    c = conn.cursor()

    c.execute("""
    CREATE TABLE IF NOT EXISTS auctions (
        item_id INTEGER PRIMARY KEY AUTOINCREMENT,
        name TEXT,
        ...
        status TEXT DEFAULT 'ACTIVE'
    )
    """)

    c.execute("""
    CREATE TABLE IF NOT EXISTS bids (
        bid_id INTEGER PRIMARY KEY AUTOINCREMENT,
        item_id INTEGER,
        bidder TEXT,
        amount REAL,
        timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
    )
    """)

    conn.commit()
    conn.close()
Enter fullscreen mode Exit fullscreen mode

🎯 This ensures the tables exist when the server starts.

πŸ”Œ 2. Start the Socket Server

The server listens for connections and handles JSON requests:

def start_server():
    init_db()
    server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    server.bind((HOST, PORT))
    server.listen()
    print(f"[SERVER] Listening on {HOST}:{PORT}")

    while True:
        conn, addr = server.accept()
        threading.Thread(target=handle_client, args=(conn, addr), daemon=True).start()
Enter fullscreen mode Exit fullscreen mode

πŸ“‘ Each client connection gets a new thread so multiple users can interact simultaneously.

πŸ“ 3. Handle Client Requests

When a client sends a JSON command, the server parses it:

data = conn.recv(65536)
request = json.loads(data.decode())
action = request.get("action")
Enter fullscreen mode Exit fullscreen mode

Depending on "action", the server performs:

βœ”οΈ get_auctions
βœ”οΈ place_bid
βœ”οΈ create_auction
βœ”οΈ start_auto_bid
βœ”οΈ and more…

Each action updates the DB and sends back a JSON response.

πŸ’Έ 4. Placing a Bid

The core logic ensures a bid is valid:

if amount < current_bid + min_inc:
    return False, "Bid must be at least ..."

UPDATE auctions SET current_bid=?, highest_bidder=? ...
INSERT INTO bids (item_id, bidder, amount) ...
Enter fullscreen mode Exit fullscreen mode

βœ… This ensures bids are incremental and correctly logged.

πŸ€– 5. Auto-Bid Loop

Auto-bidding lets a user set a maximum bid:

def auto_bid_loop(item_id):
    while True:
        time.sleep(REFRESH_INTERVAL)

        if current_bid >= max_bid:
            auto_bids[item_id]["active"] = False
            return

        if highest_bidder != bidder:
            new_bid = min(current_bid + min_inc, max_bid)
Enter fullscreen mode Exit fullscreen mode

🧠 This thread checks periodically and automatically increases the bid.

πŸ–₯️ 6. Build the Admin GUI

Admins can create auctions from the desktop app using Tkinter + ttkbootstrap:

payload = {
    "name":      item_name.get(),
    "starting_bid": float(starting_bid.get()),
    "min_increment": float(min_increment.get()),
    ...
}

send_request({"action": "create_auction", "payload": payload})
Enter fullscreen mode Exit fullscreen mode

The GUI collects form data and sends it to the server with "create_auction".

πŸ“Š 7. Live Auction Display

The Admin panel also displays running auctions:

res = send_request({"action": "get_auctions"})
items = sorted(res["auctions"], ...)
Enter fullscreen mode Exit fullscreen mode

Each auction line shows:

βœ”οΈ Current bid
βœ”οΈ Highest bidder
βœ”οΈ Start & end times
βœ”οΈ Buttons to close, make public/private, delete

πŸ‘€ 8. Bidder App

The Bidder GUI shows only public auctions:

if not item.get("public"):
    continue
Enter fullscreen mode Exit fullscreen mode

Bidders can enter:

πŸ“ Item ID
πŸ’° Bid amount

send_request({"action": "place_bid", ...})
Enter fullscreen mode Exit fullscreen mode

πŸŽ‰ When an auction closes, bidders are notified if they won.

πŸ› οΈ 9. Refresh Loop

Both GUIs use a background thread to refresh every few seconds:

while True:
    time.sleep(REFRESH_INTERVAL)
    res = send_request({"action": "get_auctions"})
Enter fullscreen mode Exit fullscreen mode

This makes the app feel real-time even over sockets.

πŸš€ Final Thoughts

You now understand how:

πŸ“Œ A socket server accepts JSON commands
πŸ“Œ Clients interact via simple GUI forms
πŸ“Œ Auctions and bids update live
πŸ“Œ Auto-bidding is handled in a loop

This project is a great starting point for real-time apps using Python networking and desktop UI.

Auction Admin Panel

Auction Open Account (Login, Register)

Bid Auction is Close Not Allow

Active Bidder - Live Auctions

Auction Won - Live Auctions

Top comments (0)