5 Hidden Gem Python Libraries You Should Know About!

explore five lesser-known but powerful Python libraries that can enhance your coding efficiency and productivity.

5 Hidden Gem Python Libraries You Should Know About!
Photo by Michael Dziedzic on Unsplash

TIRED OF THE SAME OLD PYTHON LIBRARIES?

5 Hidden Gem Python Libraries You Should Know About!

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 5 underrated Python libraries that you should definitely know about!

1. Pendulum — Simplified DateTime Handling

Pendulum is great library specially if you are working with timezones, durations, and date manipulations easier.

Docs : https://pypi.org/project/pendulum/

Installation

pip install pendulum

Example

Here is the simple examples to work with pendulum library :

import pendulum 
 
now_in_paris = pendulum.now('Europe/Paris') 
print(now_in_paris) # '2016-07-04T00:49:58.502116+02:00' 
 
# Seamless timezone switching 
print(now_in_paris.in_timezone('UTC') # '2016-07-03T22:49:58.502116+00:00' 
tomorrow = pendulum.now().add(days=1) 
last_week = pendulum.now().subtract(weeks=1) 
past = pendulum.now().subtract(minutes=2) 
print(past.diff_for_humans()) # '2 minutes ago' 
delta = past - last_week 
print(delta.hours) # 23 
print(delta.in_words(locale='en')) # '6 days 23 hours 58 minutes' 
 
# Proper handling of datetime normalization 
print(pendulum.datetime(2013, 3, 31, 2, 30, tz='Europe/Paris')) # '2013-03-31T03:30:00+02:00' 
 
# Proper handling of dst transitions 
just_before = pendulum.datetime(2013, 3, 31, 1, 59, 59, 999999, tz='Europe/Paris') 
print(just_before.add(microseconds=1)) # '2013-03-31T03:00:00+02:00'

2. Colorama — Add Colors to Console Output

colorama is a Python library that allows you to add colored text and styles (like bold or underline) to terminal output. It works on Windows, macOS, and Linux, making it easy to format command-line output with colors.

Docs : https://pypi.org/project/colorama/

Installation

pip install colorama

Example

Basic usage of colorama library :

from colorama import Fore, Back, Style, init 
 
# Initialize colorama (needed for Windows) 
init() 
 
# Foreground colors 
print(Fore.RED + "This is red text") 
print(Fore.GREEN + "This is green text") 
print(Fore.BLUE + "This is blue text") 
 
# Background colors 
print(Back.YELLOW + "This text has a yellow background") 
print(Back.CYAN + "This text has a cyan background") 
 
# Text styles 
print(Style.BRIGHT + "This text is bright") 
print(Style.DIM + "This text is dim") 
 
# Reset styles 
print(Style.RESET_ALL + "Back to normal text"

3. SymPy — Symbolic Mathematics in Python

SymPy is a powerful Python library for symbolic mathematics, enabling algebraic manipulation, equation solving, calculus, and more.

Docs : https://docs.sympy.org/latest/index.html

Installation

pip install sympy

Example

Basic usage of SymPy library :

import sympy as sp 
 
# Define a symbol (variable) 
x = sp.Symbol('x') 
 
# Define an expression 
expr = x**2 + 3*x + 2 
 
# Differentiate the expression 
derivative = sp.diff(expr, x) 
 
# Integrate the expression 
integral = sp.integrate(expr, x) 
 
# Solve an equation (x^2 + 3x + 2 = 0) 
solutions = sp.solve(expr, x) 
 
print("Expression:", expr)        # Expression: x**2 + 3*x + 2 
print("Derivative:", derivative)  # Derivative: 2*x + 3 
print("Integral:", integral)      # Integral: x**3/3 + 3*x**2/2 + 2*x 
print("Solutions:", solutions)    # Solutions: [-2, -1]

4. Shapely — Work with Geospatial Data

Shapely is a Python library used for geometric operations such as creating, analyzing, and manipulating geometric shapes like points, lines, and polygons etc.

Docs : https://shapely.readthedocs.io/en/stable/

Installation

pip install shapely

Example

Basic usage of Shapely library :

from shapely.geometry import Point, LineString, Polygon 
 
# Create a point 
point = Point(2, 3) 
# Create a line 
line = LineString([(0, 0), (2, 2), (3, 3)]) 
# Create a polygon 
polygon = Polygon([(0, 0), (4, 0), (4, 4), (0, 4)]) 
print("Point:", point)     # Point: POINT (2 3) 
print("Line:", line)       # Line: LINESTRING (0 0, 2 2, 3 3) 
print("Polygon:", polygon) # Polygon: POLYGON ((0 0, 4 0, 4 4, 0 4, 0 0))

Calculate Area & Perimeter of a Polygon

print("Polygon Area:", polygon.area)         # Output: 16 
print("Polygon Perimeter:", polygon.length)  # Output: 16

Check If a Point is Inside a Polygon

point1 = Point(1, 1) 
point2 = Point(4, 5) 
print("Distance:", point1.distance(point2))  # Output: 5.0

Find Intersection Between Shapes

line1 = LineString([(0, 0), (2, 2)]) 
line2 = LineString([(0, 2), (2, 0)]) 
 
intersection = line1.intersection(line2) 
print("Intersection Point:", intersection)  # POINT (1 1)

5. Typer: Build CLI Applications in Python

Typer is a Python library for building command-line interfaces (CLI) with minimal code. It is based on Python's type hints and provides an easy way to create user-friendly CLI applications.

Docs : https://typer.tiangolo.com

Installation

pip install typer

Example

Basic example to create a CLI command using Typer library :

# script.py 
import typer 
 
app = typer.Typer() 
@app.command() 
def greet(name: str): 
    """Simple function to greet the user.""" 
    typer.echo(f"Hello, {name}!") 
if __name__ == "__main__": 
    app()

Running the command:

python script.py greet Aashish

Output:

Hello, Aashish!

Final Thoughts

These 5 Python libraries are game changer that will supercharge your workflow in 2025.

Which library is your favorite? Let me know in the comments!