✅ Step-by-step WhatsApp Message Sender with Python

1. Install the Required Library

pip install pywhatkit

2. Python Code to Send a Message

sendwhatsapp.py file code:-

import pywhatkit as kit
import time

# List of 10 contacts (use actual numbers with country codes as strings)
contacts = [
    "+919876543210",
    "+918888888888",
    "+917777777777",
    "+916666666666",
    "+915555555555",
    "+914444444444",
    "+913333333333",
    "+912222222222",
    "+911111111111",
    "+910000000000"
]

message = "Hello from pywhatkit!"

# Loop through contacts and send messages
for number in contacts:
    try:
        print(f"Sending to {number}...")
        kit.sendwhatmsg_instantly(phone_no=number, message=message, wait_time=10, tab_close=True)
        time.sleep(15)  # Wait before sending next message to allow for browser automation
    except Exception as e:
        print(f"Failed to send to {number}: {e}")

Here's a complete Python script that reads names, numbers, and messages from an Excel file and sends personalized WhatsApp messages using the pywhatkit library.

✅ Requirements

1. Install libraries:

pip install pywhatkit openpyxl pandas

2. Sample Excel Format (contacts.xlsx)
Name	Phone	Message
John	+14155552671	Hello John, how are you?
Alice	+14155559876	Hi Alice! Reminder...

sendwhatsapp.py file :-

import pandas as pd
import pywhatkit as kit
import time

# Read Excel file
# Your Excel file should have a column named 'Phone' with full phone numbers
df = pd.read_excel("contacts.xlsx")  # e.g., +919876543210 in 'Phone' column

# Message to send
message = "Hello from pywhatkit!"

# Loop through the contact numbers
for index, row in df.iterrows():
    number = row['Phone']
    try:
        print(f"Sending to {number}...")
        kit.sendwhatmsg_instantly(
            phone_no=str(number),
            message=message,
            wait_time=10,
            tab_close=True
        )
        time.sleep(15)  # Delay between messages to prevent overlap
    except Exception as e:
        print(f"Failed to send to {number}: {e}")

Notes:
Your system must be awake and connected to the internet.

WhatsApp Web will open in your browser — ensure you’re logged in.

Adjust time.sleep() and wait_time if sending many messages.

Using Tkinter :-

import pandas as pd
import pywhatkit as kit
import time
from tkinter import Tk
from tkinter.filedialog import askopenfilename

# Open file dialog to select the Excel file
Tk().withdraw()  # Hide the root Tkinter window
file_path = askopenfilename(
    title="Select Excel File",
    filetypes=[("Excel Files", "*.xlsx *.xls")]
)

if not file_path:
    print("No file selected. Exiting.")
    exit()

# Read the Excel file
try:
    df = pd.read_excel(file_path)
except Exception as e:
    print(f"Failed to read Excel file: {e}")
    exit()

# Ensure 'Phone' column exists
if 'Phone' not in df.columns:
    print("Excel file must contain a 'Phone' column.")
    exit()

# Message to send
message = "Hello from pywhatkit!"

# Loop through contacts and send messages
for index, row in df.iterrows():
    number = str(row['Phone']).strip()
    try:
        print(f"Sending to {number}...")
        kit.sendwhatmsg_instantly(
            phone_no=number,
            message=message,
            wait_time=10,
            tab_close=True
        )
        time.sleep(15)  # Delay between messages
    except Exception as e:
        print(f"Failed to send to {number}: {e}")