DEV Community 👩‍💻👨‍💻

Cover image for Automating WhatsApp with python!
Sachit71
Sachit71

Posted on

Automating WhatsApp with python!

Hello there!

Today we'll be talking about this awesome Python package that lets you Automate WhatsApp.

Package intro

PYPI project link

Installation: pip3 install pywhatkit

Apart from being a WhatsApp API kinda package it also has a lot of other features, it is also a very light weight package and ideal for production usage.

More details can be found in it's wiki page.

Basic usage and interesting functions

Some important functions we'll be seeing in this review blog are:

  1. Send automated messages in WhatsApp.
  2. Send automated images in WhatsApp.
  3. Play a video on YouTube using PyWhatkit.
  4. Convert text to handwritten texts.

Sending messages using Pywhatkit

import pywhatkit as pw

pw.sendwhatmsg("+XXxxxxxxxxxx","Your message here",'hour','min')

Enter fullscreen mode Exit fullscreen mode

Explanation:

The first argument("+XXxxxxxxxxxx") is the phone number of the recipient, the second parameter("Your message here") is the message parameter where you enter the content of the text.

The 3rd parameter('hour') is the hour at which the message is to be sent, and the 4th('min') one is the minute of the hour at which it should be sent.

Note that the hour should be in the 24 hour format.

Example

Sending images using PyWhatkit

import pywhatkit as pw

pw.sendwhats_image(phone_no="enter phone number with country code", img_path="C:/Users/user/desktop/image.jpg", caption="Example image sent!")
Enter fullscreen mode Exit fullscreen mode

Explanation:

The first parameter is the phone number of the recipient(phone_no="phone number with country code").

The second parameter is the path of the image that is to be sent(img_path="C:/Users/user/desktop/image.jpg").

The third parameter is the caption text for the image that is to be sent (caption="Example image sent!").

Image description

Playing a video on YouTube

import pywhatkit as pw
pw.playonyt("Your topic or video here")
Enter fullscreen mode Exit fullscreen mode

Explanation:

The top most video related to that topic will play on YouTube.

Convert Text to Handwritten Text in Image format

import pywhatkit as pw
pw.text_to_handwriting("Your text here!")
Enter fullscreen mode Exit fullscreen mode

Explanation:

The only parameter here is the text parameter, the given input is then converted into handwritten text.

example-2

This it for this tutorial!

Misc links related to PyWhatkit

GitHub
Discord support server

Hope this tutorial helped you gain some insight on WhatsApp automation using Python! Stay tuned for more awesome tutorials and packages.

Top comments (2)

Collapse
 
dogendranath profile image
doge ( Miso/Gynist )

i'm getting error
File "d:\1 Savyasachi\1 Real projects\gbfiles3\send.py", line 1, in
import pywhatkit as pw
File "C:\Users\TheDeveloper\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pywhatkit_init_.py", line 29, in
from pywhatkit.remotekit import start_server
File "C:\Users\TheDeveloper\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pywhatkit\remotekit.py", line 6, in
from flask import Flask, request
ModuleNotFoundError: No module named 'flask'

Collapse
 
cyber profile image
Sachit71 Author

Hi, sorry for the delayed response, try pip install flask and that should solve the error

👀 Just want to lurk?

You can still create an account and turn on features like 🌚 dark mode.