Automate WhatsApp Message using Python

Aman Keshari
2 min readAug 9, 2023

Hey there, tech enthusiasts! Today, I’m thrilled to introduce you to an incredibly handy Python library that will make your messaging life a breeze — PyWhatKit. If you’ve ever wished to send WhatsApp messages programmatically, whether it’s for personal or professional use, this library will become your new best friend.

Introducing PyWhatKit

PyWhatKit is a versatile Python library that allows you to automate various tasks on WhatsApp using Python scripts. From sending messages to generating QR codes, this library opens up a world of possibilities for interacting with WhatsApp in an automated fashion. In this article, we’ll focus on a common use case: sending instant WhatsApp messages.

Sending WhatsApp Messages Instantly

Have you ever been in a situation where you needed to send a quick WhatsApp message to someone but didn’t have the time to open the app and type it out? PyWhatKit has got you covered. Let’s dive into a quick tutorial on how to send an instant WhatsApp message using this library.

# pip install pywhatkit
import pywhatkit as kit

# Specify the phone number (with country code) and the message
phone_number = "+1234567890"
message = "Hello from Python! This is an instant WhatsApp message."

# Send the message instantly
kit.sendwhatmsg_instantly(phone_number, message)

In just a few lines of code, you can have Python automate the process of sending WhatsApp messages without any manual intervention. This can be incredibly useful for sending reminders, alerts, or even personalized greetings.

Breaking Down the Code

Let’s take a closer look at what’s happening in the code snippet:

1. We start by importing the `pywhatkit` module, which we’ve aliased as `kit` for brevity.

2. Next, we define the `phone_number` variable, specifying the recipient’s phone number along with the country code. Make sure you have the recipient’s consent before sending automated messages.

3. We set the `message` variable to the content of the message we want to send.

4. The `kit.sendwhatmsg_instantly()` function is where the magic happens. It takes the `phone_number` and `message` as arguments and sends the message instantly to the recipient on WhatsApp.

Wrapping Up

With PyWhatKit, automating WhatsApp messages is a walk in the park. Whether you want to send important alerts, personalized greetings, or timely reminders, this library has the potential to streamline your communication process.

However, it’s crucial to use this power responsibly and ethically. Always ensure you have proper consent from recipients before sending automated messages, and avoid using this for spam or unsolicited messages.

So, why not give PyWhatKit a spin? Experiment with its various features and let your creativity run wild. Happy coding, and until next time, tech aficionados!

--

--