Could This Be The Weirdest Python Library Ever?

Photo by David Clode on Unsplash

Could This Be The Weirdest Python Library Ever?

Checking out the functionality of this multi-purpose python library

Table of contents

No heading

No headings in the article.

I got introduced to the world of computer programming with Python (I am a staunch member of the ‘HTML is not a programming language’ camp), and after I got wowed by the basics and stuff, I went to get the award winning Head First Python book for further studies. Perhaps that book shaped the way I use Python till today, which kinda explains why I still build web apps with Flask even when my people tell me Django is the real deal. In the book, they described Python as a language that came with “batteries included” because of all the modules and libraries that can help you do almost anything you want. Recently, I stumbled on a Python library that really embodies this concept of having “batteries included.”

PyWhatKit is a python library that you can use to perform multiple functions, from the normal, and maybe acts of sending WhatsApp messages and drawing information from Wikipedia, to the craazy and, in my opinion, unnecessary drawing ASCII art and playing YouTube videos. Let's go further by looking at some of the crazy things you can do with PyWhatKit.

Before you get started with the library, you would have to install it like you would any python library. Use the pip command on your command prompt for Windows devices to install the library.

pip install pywhatkit

I’m sure you already know that you’d have to import the library as soon as it’s installed.

import pywhatkit
  1. Converting text to handwriting

I don’t know why anyone would want to convert computer text to something that looks like physical handwriting, but in case you want to, you can use the PyWhatKit library to get it done. You use the text_to_handwriting() function to get this done. This function would take the following arguments: a string of characters you want to convert from text to handwriting, and a tuple of rgb colour codes to specify the colour style you want the handwriting document to be in. The output will be a png file, which would have the default name “pywhatkit.png.” However, you can change it by adding the name you would like to call the file as an argument.

import pywhatkit

# Convert text to handwriting with default color
pywhatkit.text_to_handwriting("Hello, world!")

# Convert text to handwriting with custom color (red)
pywhatkit.text_to_handwriting("Hello, world!", rgb=(255, 0, 0))

# Convert text to handwriting and specify filename
pywhatkit.text_to_handwriting("Hello, world!", save_to="handwriting.png")
  1. Sending emails

Perhaps you’re too lazy to open your email app to compose and send an email, or you are a developer that would like to take the longer and slightly unnecessary route, you could use the send_email() function to do this. This one takes the following arguments: your email address, your password, the subject of the email, the body of the email, and the recipient’s email address.

import pywhatkit

# Send email
pywhatkit.send_mail("your_email@gmail.com", "your_password", "Subject", "Body", "recipient_email@example.com")
  1. Getting information from Wikipedia

Wikipedia has a wealth of information to educate all of us, but some of us, like myself, get too lazy to read the whole article. The info() function can be used to solve your problems. This function takes 3 arguments: a string, which is the topic you would want to search for, the number of lines you want the function to return, and a boolean to declare whether or not you want the stuff returned.

import pywhatkit

# Get information from Wikipedia
info = pywhatkit.info("Python programming", lines=3, output_string=True)
print(info)
  1. Getting screenshots

I normally use the Snipping Tools program to take “screenshots” of things I want to keep on my computer (or I use the Opera Browser to save it as a PDF file if it’s on the web), but this library has the take_screenshot() function that you can use instead. It takes an image of the current screen and stores it as a png file. You use the filename you want to give to the screenshot as an argument.

import pywhatkit

# Take a screenshot
pywhatkit.take_screenshot("screenshot.png")
  1. Converting an image to ASCII art

I don’t know why anyone would want to turn any image to ASCII, but I guess it’s fun to do somehow. You would use the image_to_ascii_art() function with the file name (if it is in the same directory as the file) or the file path as argument.

import pywhatkit

# Convert image to ASCII art (assuming image.png is in the same directory)
pywhatkit.image_to_ascii_art("image.png")

And that's just the tip of the iceberg. This library can perform more unrelated functions, and I can't even point to one specific function the library can be used for, like how Flask is used for web development, or panda is used for data analysis. In fact, the name "pywhatkit" suggests it should be seen as more of a tool box or a multi-purpose library.

Do you think there is a benefit to a library having all these unrelated functions? You can share your thoughts about this in the comments. Have a nice day, and do check out the library for the full dose of all it is capable of.