Fundamentals 9 min read

12 Must‑Know Python Utility Libraries to Supercharge Your Code

This guide showcases twelve compact yet powerful Python packages—loguru, rich, typer, pydantic, sh, glom, boltons, dateparser, icecream, tqdm, pyperclip, and deepdiff—that replace bulky standard tools, streamline logging, CLI creation, data validation, shell integration, debugging, and more, complete with practical code snippets.

DevOps Coach
DevOps Coach
DevOps Coach
12 Must‑Know Python Utility Libraries to Supercharge Your Code

The article presents a curated toolbox of twelve lesser‑known Python libraries that can replace heavyweight or missing functionality in everyday projects, offering concise APIs for logging, command‑line interfaces, data validation, shell interaction, nested‑data handling, debugging, and other common tasks.

loguru – Simplified Logging

loguru acts as a drop‑in replacement for the built‑in logging module, removing boilerplate, adding automatic formatting, log rotation, and readable stack traces.

from loguru import logger
logger.add("debug.log", rotation="1 MB")
logger.info("This is too easy.")

rich – Beautiful Command‑Line Output

rich enables colourful, formatted terminal output, including tables, progress bars, markdown rendering, tracebacks, and syntax‑highlighted code.

from rich import print
print("[bold magenta]Python is powerful[/bold magenta] and [green]rich[/green]!")

Combining rich with argparse or click yields a polished CLI.

typer – Type‑Hint‑Driven CLI Builder

typer leverages Python type hints to auto‑generate a professional‑looking command‑line interface, backed by the same author of FastAPI.

import typer

def greet(name: str):
    print(f"Hello {name}!")

typer.run(greet)

pydantic – Robust Data Validation

pydantic provides fast, type‑checked data models that validate and parse input, forming the core of FastAPI.

from pydantic import BaseModel

class User(BaseModel):
    id: int
    name: str
    email: str

u = User(id=123, name="John", email="[email protected]")

It is faster than dataclasses with validation and ideal for API development.

sh – Pythonic Shell Commands

sh lets you call shell commands as if they were Python functions, capturing stdout and stderr cleanly.

import sh
print(sh.ls("-l"))

It also supports piping commands just like in Bash.

glom – One‑Line Nested Data Extraction

glom simplifies accessing deeply nested structures, turning multi‑level dict.get() chains into a single readable expression.

from glom import glom

target = {"a": {"b": {"c": "hello"}}}
print(glom(target, "a.b.c"))  # → hello

boltons – Extended Standard‑Library Utilities

boltons offers a Swiss‑army‑knife collection of utilities missing from the standard library, such as flatten for iterables.

from boltons.iterutils import flatten
print(flatten([[1, 2], [3, 4]]))  # → [1, 2, 3, 4]

It includes over 40 small tools for dict handling, file utilities, and more.

dateparser – Human‑Friendly Date Parsing

dateparser parses natural‑language date strings in many locales, formats, and time zones, replacing cumbersome datetime.strptime calls.

from dateparser import parse
print(parse("2 weeks ago"))

It correctly handles inputs like “last Tuesday at 9pm”.

icecream – Smart Debug Printing

icecream provides concise, informative debug prints that show both the expression and its value, with an easy on/off switch.

from icecream import ic
a = 5
b = 10
ic(a + b)  # prints: ic| a + b: 15

tqdm – Instant Progress Bars

tqdm adds a visual progress bar to any iterable with zero configuration, supporting Pandas and notebooks.

from tqdm import tqdm
for i in tqdm(range(10000000)):
    pass

pyperclip – Clipboard Interaction

pyperclip lets Python copy to and paste from the system clipboard, useful for small automation scripts.

import pyperclip
pyperclip.copy("Copied to clipboard!")
text = pyperclip.paste()
print(text)

deepdiff – Precise Difference Detection

deepdiff compares complex dictionaries or nested structures and reports exact paths of differences.

from deepdiff import DeepDiff
a = {"x": 1, "y": {"z": 3}}
b = {"x": 1, "y": {"z": 4}}
print(DeepDiff(a, b))
# → {'values_changed': {"root['y']['z']": {'new_value': 4, 'old_value': 3}}}

It is valuable for debugging API responses and ensuring data integrity.

librariesdata validationUtilities
DevOps Coach
Written by

DevOps Coach

Master DevOps precisely and progressively.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.