Table of contents
1.
Introduction
2.
Features of pywhatkit module
2.1.
1. Send WhatsApp messages
2.1.1.
Syntax
2.1.2.
Parameters
2.1.3.
Example
2.2.
2. Play a YouTube video
2.2.1.
Syntax
2.2.2.
Parameters
2.2.3.
Example
2.3.
3. Perform a Google Search
2.3.1.
Syntax
2.3.2.
Parameters
2.3.3.
Example
2.4.
4. Get information on a particular topic
2.4.1.
Syntax
2.4.2.
Parameters
2.4.3.
Example
3.
Frequently Asked Questions
3.1.
Can I send WhatsApp messages to multiple contacts using pywhatkit?
3.2.
Is it possible to schedule YouTube videos to play at a specific time?
3.3.
Can I customize the Google search results returned by pywhatkit?
4.
Conclusion
Last Updated: Aug 22, 2024
Medium

Introduction to Pywhatkit Module

Author Riya Singh
0 upvote

Introduction

Pywhatkit is a Python library that allows you to perform various tasks like sending WhatsApp messages, playing YouTube videos, performing Google searches, & getting information on specific topics. It simplifies the process of automating these actions using simple Python commands. 

Introduction to Pywhatkit Module

In this article, we will explain the features of the pywhatkit module & learn how to use them with the help of examples.

Features of pywhatkit module

1. Send WhatsApp messages

Pywhatkit makes it easy to send WhatsApp messages using Python. You can automate the process of sending messages to a specific contact or group at a scheduled time.

Syntax

pywhatkit.sendwhatmsg(phone_no, message, time_hour, time_min)

Parameters

- `phone_no`: The phone number of the recipient (with country code)

- `message`: The message you want to send

- `time_hour`: The hour at which you want to send the message (in 24-hour format)

- `time_min`: The minute at which you want to send the message

Example

import pywhatkit

pywhatkit.sendwhatmsg("+1234567890", "Hello, this is an automated message!", 10, 30)


This code will send the message "Hello, this is an automated message!" to the phone number "+1234567890" at 10:30 AM.

2. Play a YouTube video

With pywhatkit, you can play a YouTube video by providing the video URL or search query. It opens the video in your default web browser.

Syntax

pywhatkit.playonyt(video)

Parameters

- `video`: The URL or search query of the YouTube video you want to play

Example

import pywhatkit
pywhatkit.playonyt("https://www.youtube.com/watch?v=dQw4w9WgXcQ")


This code will open the YouTube video with the provided URL in your default web browser.

You can also use a search query instead of a URL:

pywhatkit.playonyt("Python tutorial for beginners")


This will perform a YouTube search for "Python tutorial for beginners" & play the first video from the search results.

3. Perform a Google Search

Pywhatkit allows you to perform a Google search using Python. It opens the search results in your default web browser.

Syntax

pywhatkit.search(query)

Parameters

- `query`: The search query you want to perform on Google

Example

import pywhatkit
pywhatkit.search("What is Python programming?")


This code will open the Google search results for "What is Python programming?" in your default web browser.

You can use this feature to quickly search for information or find relevant websites related to a specific topic.

4. Get information on a particular topic

Pywhatkit provides a convenient way to retrieve information on a specific topic using the `info()` function. It fetches the summary of the topic from Wikipedia.

Syntax

pywhatkit.info(topic, lines)

Parameters

- `topic`: The topic you want to get information about

- `lines`: The number of lines of information you want to retrieve (default is 4)

Example

import pywhatkit
pywhatkit.info("Python programming language", 5)


This code will retrieve 5 lines of information about the Python programming language from Wikipedia & display it in the console.


The `info()` function is useful when you need a quick summary or overview of a particular topic without having to search for it manually.

Frequently Asked Questions

Can I send WhatsApp messages to multiple contacts using pywhatkit?

Yes, you can send WhatsApp messages to multiple contacts by calling the sendwhatmsg() function multiple times with different phone numbers.

Is it possible to schedule YouTube videos to play at a specific time?

No, currently pywhatkit does not provide a feature to schedule YouTube videos. The playonyt() function plays the video immediately.

Can I customize the Google search results returned by pywhatkit?

No, pywhatkit uses the default Google search engine & does not provide options to customize the search results. It simply opens the search results page in your web browser.

Conclusion

In this article, we have learned about the pywhatkit module & its various features. We explained how to send WhatsApp messages, play YouTube videos, perform Google searches, & retrieve information on specific topics using simple Python commands. Pywhatkit simplifies the process of automating these tasks, saving time & effort.

You can also check out our other blogs on Code360.

Live masterclass