14 Hidden Gem Python Libraries You Can’t Afford to Miss! 🚀

Discover 14 underrated Python libraries that can save you time and boost productivity.

14 Hidden Gem Python Libraries You Can’t Afford to Miss! 🚀
Photo by Iñaki del Olmo on Unsplash

SUPERCHARGE YOUR PYTHON PROJECTS WITH THESE HIDDEN GEMS!

14 Hidden Gem Python Libraries You Can’t Afford to Miss! 🚀

While exploring Python libraries for my projects, I came across some hidden gems that don’t seem to get much attention. These libraries are incredibly useful, yet underrated.

In this guide, I’ll be revealing 14 underrated Python libraries that you should definitely know about!

1. PyFilesystem — Fil System Abstraction

fs library provides a virtual filesystem abstraction layer to work with local, cloud, and in-memory filesystems using the same API.
Docs : https://www.pyfilesystem.org/

Installation

pip install fs

Example

from fs.memoryfs import MemoryFS 
 
fs = MemoryFS() 
fs.writetext('hello.txt', 'Hello, PyFilesystem!') 
print(fs.readtext('hello.txt'))  # Output: Hello, PyFilesystem!

2. PyShorteners — URL Shortening

Pyshorteners is an amazing hidden gem, that help to quick and easy url shortening. It support multiple services like TinyURL, Bitly, and others.
Docs : https://pyshorteners.readthedocs.io/en/latest/

Installation

pip install pyshorteners

Example

A simple and quick example to shortening url by using TinyURL :

import pyshorteners 
 
s = pyshorteners.Shortener() 
print(s.tinyurl.short("https://www.python.org"))

A simple and quick example to shortening url by using Bitly :

import pyshorteners 
s = pyshorteners.Shortener(api_key='YOUR_KEY') 
s.bitly.short('http://www.google.com') # 'http://bit.ly/TEST' 
s.bitly.expand('https://bit.ly/TEST') # 'http://www.google.com' 
s.bitly.total_clicks('https://bit.ly/TEST') # 10

3. DeepDiff — Object Comparison

DeepDiff compares Python objects and shows differences at a deep level.
Docs : https://pypi.org/project/deepdiff/

Installation

pip install deepdiff

Example

from deepdiff import DeepDiff 
 
d1 = {"name": "John", "age": 25} 
d2 = {"name": "John", "age": 30} 
print(DeepDiff(d1, d2))   
# Output: {'values_changed': {'root['age']': {'old_value': 25, 'new_value': 30}}}

4. Yaspin — Terminal Spinners

Yaspin adds stylish loading spinners to terminal output.
Docs : https://github.com/pavdmyt/yaspin

Installation

pip install yaspin

Example

A basic example to add loading spinners to terminal output :

import time 
from random import randint 
from yaspin import yaspin 
 
with yaspin(text="Loading", color="yellow") as spinner: 
    time.sleep(2)  # time consuming code 
    success = randint(0, 1) 
    if success: 
        spinner.ok("✅ ") 
    else: 
        spinner.fail("💥 ")
Isn’t that cool.

5. PyPDF2 — PDF Editing

PyPDF2 is an amazing library for any kind of PDF works. I used a lot in many projects. It provides the features like extract text, merge PDFs, add watermarks, splits PDFs and modify PDFs.
Docs : https://pypdf2.readthedocs.io/en/3.x/index.html

Installation

pip install pypdf2

Example

A basic example to extract text from pdf :

import PyPDF2 
 
with open("example.pdf", "rb") as f: 
    reader = PyPDF2.PdfReader(f) 
    print(reader.pages[0].extract_text())  # Read first page

6. rapidfuzz — Rapid Fuzzy String Matching

rapidfuzz is amazing library that compares and finds similarity between strings.
Docs : https://github.com/rapidfuzz/RapidFuzz

Installation

pip install rapidfuzz

Example

>> from rapidfuzz import fuzz 
>> fuzz.ratio("this is a test", "this is a test!") 
96.55172413793103

7. TextBlob — NLP Made Easy

TextBlob provides simple NLP functionalities like sentiment analysis and text translation.
Docs : https://textblob.readthedocs.io/en/dev/

Installation

pip install textblob

Example

from textblob import TextBlob 
 
text = """ 
The titular threat of The Blob has always struck me as the ultimate movie 
monster: an insatiably hungry, amoeba-like mass able to penetrate 
virtually any safeguard, capable of--as a doomed doctor chillingly 
describes it--"assimilating flesh on contact. 
Snide comparisons to gelatin be damned, it's a concept with the most 
devastating of potential consequences, not unlike the grey goo scenario 
proposed by technological theorists fearful of 
artificial intelligence run rampant. 
""" 
blob = TextBlob(text) 
blob.tags  # [('The', 'DT'), ('titular', 'JJ'), ('threat', 'NN'), ('of', 'IN'), ...] 
blob.noun_phrases  # WordList(['titular threat', 'blob', 'ultimate movie monster', 'amoeba-like mass', ...]) 
for sentence in blob.sentences: 
    print(sentence.sentiment.polarity)  
     
# 0.060 
# -0.341

8. pyWhat — Identify anything

pyWhat easily lets you identify emails, IP addresses, and more. Feed it a .pcap file or some text and it’ll tell you what it is!
Docs : https://github.com/bee-san/pyWhat

Installation

pip3 install pywhat # Using pip 
brew install pywhat # On Mac

Example

With what all you have to do is ask and it will tell what is this:

what "0x52908400098527886E0F7030069857D2E4169EE7"

9. PrettyErrors — Enhanced Error Messages

PrettyErrors makes Python error messages more readable.
Docs : https://github.com/onelivesleft/PrettyErrors

Installation

pip install pretty-errors

Example

import pretty_errors 
1 / 0  # Throws a ZeroDivisionError with a well-formatted message

10. Delorean — Simple Time Calculations

Delorean is a python library that simplifies working with dates and timezones.
Docs : https://pypi.org/project/Delorean/

Installation

pip install delorean

Example

from delorean import Delorean 
 
d = Delorean() 
d = d.shift('US/Eastern') 
return d

11. Hupper — Auto-reload Python Scripts

Hupper is python library that automatically reloads your Python application when you make changes.
Docs : https://pypi.org/project/hupper/

Installation

pip install hupper

Example

Command-line Usage

Hupper can load any Python code by using the hupper -m <module> program.

$ hupper -m myapp 
Starting monitor for PID 23982.

12. Lark — Super Fast Parsers

Lark is a python library that Parses and processes structured text like programming languages.
Docs : https://github.com/lark-parser/lark

Installation

pip install lark

Example

Here is a little program to parse “Hello, World!”

from lark import Lark 
 
l = Lark('''start: WORD "," WORD "!" 
            %import common.WORD   // imports from terminal library 
            %ignore " "           // Disregard spaces in text 
         ''') 
print( l.parse("Hello, World!") ) 
# output : Tree(start, [Token(WORD, 'Hello'), Token(WORD, 'World')])

13. Scapy — Network Packet Manipulation

Scapy is a python library that captures, manipulates, and sends network packets.
Docs : https://scapy.readthedocs.io/en/latest/introduction.html

Installation

pip install scapy

Example

A simple example to build a packet and play with it:

from scapy.all import IP 
 
a=IP(ttl=10) 
print(a) # output : < IP ttl=10 |> 
print(a.src) # output : '127.0.0.1' 
a.dst="192.168.1.1" 
print(a) # output : < IP ttl=10 dst=192.168.1.1 |> 
print(a) # output : '192.168.8.14' 
del(a.ttl) 
print(a) # output : < IP dst=192.168.1.1 |> 
print(a.ttl) # output : 64

14. SoundFile — Audio File Processing

SoundFile is a python library that Reads and writes audio files (WAV, FLAC, OGG, etc.).
Docs : https://pypi.org/project/soundfile/

Installation

pip install soundfile

Example

A simple example to read and write audio files :

import soundfile as sf 
 
data, samplerate = sf.read('existing_file.wav') # Read Audio Files 
sf.write('new_file.flac', data, samplerate)     # Write Auido Files

Final Thoughts

These 9 Python libraries might be the underrated, but they can save you time, boost your productivity, and make development easier. Try them out and see how they can enhance your Python projects! 🚀

Which library are you excited to try? Let me know in the comments! 🚀