Why Automate WhatsApp with Python?
WhatsApp has over 2 billion users and is the most used messaging app in Pakistan, India, and most of the world. Automating it with Python opens up powerful use cases:
- Send daily reminders to yourself or your team
- Notify customers when their order ships
- Send bulk messages to a contact list
- Build a simple WhatsApp bot for your business
In this tutorial, we will cover three approaches from simplest to most advanced.
Method 1 — pywhatkit (Easiest, No Setup)
pywhatkit is the simplest way to send WhatsApp messages. It uses WhatsApp Web in your browser so you need to be logged in.
Install it:
pip install pywhatkit
Send a message at a specific time:
import pywhatkit
# Send a message to a number at 3:30 PM today
# Phone number must include country code: +92 for Pakistan
pywhatkit.sendwhatmsg(
phone_no="+923001234567",
message="Hello! This message was sent automatically with Python.",
time_hour=15, # 3 PM in 24-hour format
time_min=30, # 30 minutes
wait_time=15, # seconds to wait before sending
tab_close=True # close tab after sending
)
Send immediately (no scheduled time):
import pywhatkit
pywhatkit.sendwhatmsg_instantly(
phone_no="+923001234567",
message="This message was sent instantly!",
wait_time=10,
tab_close=True
)
How it works: pywhatkit opens WhatsApp Web in your browser, types the message, and sends it. You need to be logged into WhatsApp Web before running the script.
Limitations:
- Requires WhatsApp Web to be open
- Slow — has to wait for the browser to load
- Not suitable for sending hundreds of messages
Method 2 — Send Bulk Messages from a List
Here is how to send messages to multiple contacts from a CSV file:
import pywhatkit
import csv
import time
from datetime import datetime
def send_bulk_messages(csv_file: str, message: str):
"""
CSV file should have columns: name, phone
Example: Ahmed,+923001234567
"""
sent = []
failed = []
with open(csv_file, 'r') as f:
reader = csv.DictReader(f)
contacts = list(reader)
print(f"Sending messages to {len(contacts)} contacts...")
for contact in contacts:
name = contact['name']
phone = contact['phone']
personalized = message.replace('{name}', name)
try:
now = datetime.now()
# Send 2 minutes from now to give time between messages
pywhatkit.sendwhatmsg(
phone_no=phone,
message=personalized,
time_hour=now.hour,
time_min=now.minute + 2,
wait_time=20,
tab_close=True
)
sent.append(phone)
print(f"✓ Sent to {name} ({phone})")
time.sleep(30) # Wait 30 seconds between messages
except Exception as e:
failed.append(phone)
print(f"✗ Failed for {name}: {e}")
print(f"\nDone! Sent: {len(sent)}, Failed: {len(failed)}")
return sent, failed
# contacts.csv:
# name,phone
# Ahmed,+923001234567
# Sara,+923009876543
send_bulk_messages(
csv_file='contacts.csv',
message='Hi {name}! Your order has been shipped. Expected delivery: tomorrow.'
)
Method 3 — WhatsApp Business API (Production Ready)
For a real business application — sending hundreds or thousands of messages — you need the official WhatsApp Business API. The easiest way to access it is through Twilio.
Install:
pip install twilio
Setup:
- Create a free account at twilio.com
- Get a WhatsApp sandbox number
- Copy your Account SID and Auth Token
from twilio.rest import Client
import os
# Store these in environment variables, never in code
ACCOUNT_SID = os.environ['TWILIO_ACCOUNT_SID']
AUTH_TOKEN = os.environ['TWILIO_AUTH_TOKEN']
TWILIO_WHATSAPP = 'whatsapp:+14155238886' # Twilio sandbox number
client = Client(ACCOUNT_SID, AUTH_TOKEN)
def send_whatsapp(to_number: str, message: str) -> str:
"""Send WhatsApp message via Twilio. Returns message SID."""
msg = client.messages.create(
from_=TWILIO_WHATSAPP,
to=f'whatsapp:{to_number}',
body=message
)
return msg.sid
def send_order_notification(customer_phone: str, order_id: str, status: str):
"""Send order update to customer."""
message = (
f"Hi! Your order #{order_id} status has been updated.\n"
f"Status: {status}\n"
f"For help, reply to this message."
)
sid = send_whatsapp(customer_phone, message)
print(f"Message sent! SID: {sid}")
# Usage
send_order_notification(
customer_phone='+923001234567',
order_id='ORD-2026-001',
status='Shipped — arriving tomorrow'
)
Method 4 — Schedule Daily WhatsApp Reminders
Combine pywhatkit with Python's schedule library to send automatic daily reminders:
import schedule
import time
import pywhatkit
from datetime import datetime
MY_NUMBER = "+923001234567"
def send_morning_reminder():
pywhatkit.sendwhatmsg_instantly(
phone_no=MY_NUMBER,
message="Good morning! Remember to:\n✅ Check emails\n✅ Publish blog post\n✅ Reply to clients",
wait_time=10,
tab_close=True
)
print(f"Morning reminder sent at {datetime.now()}")
def send_evening_summary():
pywhatkit.sendwhatmsg_instantly(
phone_no=MY_NUMBER,
message="End of day checklist:\n✅ Did you publish today's post?\n✅ Client replies done?\n✅ Tomorrow's task planned?",
wait_time=10,
tab_close=True
)
# Schedule reminders
schedule.every().day.at("09:00").do(send_morning_reminder)
schedule.every().day.at("18:00").do(send_evening_summary)
print("Reminder bot running...")
while True:
schedule.run_pending()
time.sleep(60)
Run this script in the background and you'll get WhatsApp reminders every morning and evening automatically.
Which Method Should You Use?
| Method | Best for | Cost |
|---|---|---|
| pywhatkit | Personal use, small scale | Free |
| Bulk from CSV | Small business, under 50 contacts | Free |
| Twilio API | Business, 100+ messages/day | Paid (free trial) |
| Scheduled reminders | Personal productivity | Free |
Important Notes
- Never spam — sending bulk messages to people who did not opt in violates WhatsApp's terms and can get your number banned
- Use for legitimate purposes only — order notifications, reminders, alerts
- For production business use, always use the official WhatsApp Business API
- The pywhatkit method requires your computer to be on and WhatsApp Web to be logged in
Install all dependencies:
pip install pywhatkit schedule twilio python-dotenv
With these tools, you can automate your WhatsApp workflow and save hours every week.