Site icon Console Flare Blog

5 Interesting Libraries In Python

Welcome

What makes Python Interesting? Answer in a single word.

Well as a developer, I don’t rely on unknown sources or any random person holding a comment card. Let me ask google.

I knew it anyway. Python offers 1,37,000 libraries as of now, and if you haven’t explored many of them and only used ‘Useful‘ libraries. Believe me, you’re on a treat. This blog will cover some of the interesting libraries that I came across recently.

Google Search (googlesearch)

googlesearch-python 1.0.1 is an interesting Python library for scraping the Google search engine.

Installation(Type in terminal) :

pip install googlesearch-python

How to use :

To get results for a search term, simply use the search function in googlesearch. For example, to get results for “Console Flare” in Google, just run the following program:

from googlesearch import search
for i in search("Console Flare"):
    print(i)

Result :

Additional Options :

googlesearch supports a few additional options. By default, googlesearch returns 10 results. This can be changed. To get 100 results on Google, for example, run the following program.

from googlesearch import search
for i in search("Console flare", num_results=100):
      print(i)

 

You can also change the language google searches in. For example, to get results in Hindi, run the following program:

from googlesearch import search
for i in search("Console flare", lang = 'hi'):
      print(i)

Documentation :

You can find documentation of this library and additional help on googlesearch.

numerizer:

numerizer is an interesting library to convert natural language numerics into ints and floats.

Installation :

pip install numerizer

How to use :

>>> from numerizer import numerize
>>> numerize('forty two')
'42'
>>> numerize('forty-two')
'42'
>>> numerize('four hundred and sixty two')
'462'
>>> numerize('one fifty')
'150'
>>> numerize('twelve hundred')
'1200'
>>> numerize('twenty one thousand four hundred and seventy three')
'21473'
>>> numerize('one million two hundred and fifty thousand and seven')
'1250007'
>>> numerize('one billion and one')
'1000000001'
>>> numerize('nine and three quarters')
'9.75'
>>> numerize('platform nine and three quarters')
'platform 9.75'

Documentation :

You can find documentation of this library and additional help on numerizer.

pywhatkit :

PyWhatKit is a Simple and Powerful WhatsApp Automation Library with many useful features. You can automate your WhatsApp as well as send scheduled messages and many more things.

Installation :

pip install pywhatkit

Features of pywhatkit :

How to use :

import pywhatkit

# Send a WhatsApp Message to a Contact at 1:30 PM
pywhatkit.sendwhatmsg("+910123456789", "Hi, This is an automated message", 13, 30)

# Same as above but Closes the Tab in 2 Seconds after Sending the Message
pywhatkit.sendwhatmsg("+910123456789", "Hi, This is an automated message", 13, 30, 15, True, 2)

# Send an Image to a Group with the Caption as Hello
pywhatkit.sendwhats_image("AB123CDEFGHijklmn", "Images/Hello.png", "Hello")

# Send an Image to a Contact with the no Caption
pywhatkit.sendwhats_image("+910123456789", "Images/Hello.png")

# Send a WhatsApp Message to a Group at 12:00 AM
pywhatkit.sendwhatmsg_to_group("AB123CDEFGHijklmnopqrstuv", "Hey All!", 0, 0)

# Play a Video on YouTube
pywhatkit.playonyt("console flare")

Documentation :

You can find documentation of this interesting library and additional help on pywhatkit.

Not only WhatsApp, but you can also automate Instagram through python, Here are how.

Automate Instagram : Find how to use it on Instagram-py.

wikipedia :

Wikipedia is an interesting Python library that makes it easy to access and parse data from Wikipedia.

Installation :

pip install wikipedia

How to use :

>>> import wikipedia
>>> print wikipedia.summary("Wikipedia")
# Wikipedia (/ˌwɪkɨˈpiːdiə/ or /ˌwɪkiˈpiːdiə/ WIK-i-PEE-dee-ə) 
is a collaboratively edited, multilingual, 
free Internet encyclopedia supported by the non-profit Wikimedia Foundation...

>>> wikipedia.search("Barack")
# [u'Barak (given name)', 
u'Barack Obama', u'Barack (brandy)', 
u'Presidency of Barack Obama', u'Family of Barack Obama', 
u'First inauguration of Barack Obama', 
u'Barack Obama presidential campaign, 2008', 
u'Barack Obama, Sr.', 

>>> ny = wikipedia.page("New York")
>>> ny.title

# u'New York'

>>> ny.url

# u'http://en.wikipedia.org/wiki/New_York'

>>> ny.content

# u'New York is a state in the Northeastern region of the United States.
 New York is the 27th-most exten'...

>>> ny.links[0]

# u'1790 United States Census'

>>> wikipedia.set_lang("hi")
>>> wikipedia.summary("data science")

# आँकड़ा विज्ञान (Data Science) आँकड़ों का विश्लेषण करके उनसे जानकारी निकालने का विज्ञान है। 
यह कंप्यूटर विज्ञान का एक भाग है। आँकड़ा विज्ञान गणित, सांख्यिकी, सूचना सिद्धान्त, 
सूचना प्रौद्योगिकी आदि अनेकों क्षेत्रों के सिद्धान्तों तथा तकनीकों का प्रयोग करता है। 
वे विधियाँ जो विशाल आँकड़ों के लिये भी काम करती हैं वे आँकड़ा विज्ञान के क्षेत्र में विशेष महत्व रखतीं हैं। 
कृत्रिम बुद्धि की मशीन अधिगम (Machine Learning) नामक शाखा के विकास से इस क्षेत्र के विकास को नयी गति और महत्व मिला है।

Documentation :

You can find documentation of this library and additional help on Wikipedia.

pyttsx3 (Python Text – to – Speech) :

pyttsx3 is a text-to-speech conversion library in Python. Unlike alternative libraries, it works offline.

Installation :

pip install pyttsx3

Note :

If you receive errors such as No module named win32com.client, No module named win32, or No module named win32api, you will need to additionally install pypiwin32.

How to use :

import pyttsx3
engine = pyttsx3.init()
engine.say("I will speak this text")
engine.runAndWait()

Additional Options : Change Voice , Volume and Rate

import pyttsx3
engine = pyttsx3.init() # object creation

""" RATE"""
rate = engine.getProperty('rate')   # getting details of current speaking rate
print (rate)                        #printing current voice rate
engine.setProperty('rate', 125)     # setting up new voice rate


"""VOLUME"""
volume = engine.getProperty('volume')   #getting to know current volume level (min=0 and max=1)
print (volume)                          #printing current volume level
engine.setProperty('volume',1.0)    # setting up volume level  between 0 and 1

"""VOICE"""
voices = engine.getProperty('voices')       #getting details of current voice
#engine.setProperty('voice', voices[0].id)  #changing index, changes voices. o for male
engine.setProperty('voice', voices[1].id)   #changing index, changes voices. 1 for female

engine.say("Hello World, How are you!")
engine.say('My current speaking rate is ' + str(rate))
engine.runAndWait()
engine.stop()

"""Saving Voice to a file"""
# On linux make sure that 'espeak' and 'ffmpeg' are installed
engine.save_to_file('Hello World', 'test.mp3')
engine.runAndWait()

Documentation :

Find full documentation of this library on pyttsx3.

interesting libraries interesting libraries interesting libraries interesting libraries interesting libraries interesting libraries interesting libraries

So these were some of the libraries that are useful as well as interesting in many ways. But I have only touched the tip of an iceberg. Explore python libraries and who knows what you may find !!.

If you liked this blog, do comment and feel free to ask any queries. To learn Python, You can find our course on ConsoleFlare. Good day.

Exit mobile version