Python Libraries That Shocked Me With Their Power

Python Libraries That Shocked Me With Their Power

rich (Beautiful Console Apps With No Design Degree Required)

If your CLI output looks like a Windows 98 error screen, this is your fix.

>>> from rich.console import Console
>>> from rich.table import Table
>>>
>>> console = Console()
>>> table = Table(title="Crypto Prices")
>>>
>>> table.add_column("Coin", style="cyan")
>>> table.add_column("Price", justify="right", style="green")
>>>
>>> table.add_row("Bitcoin", "$43,210")
>>> table.add_row("Ethereum", "$3,210")
>>>
>>> console.print(table)
    Crypto Prices
┌──────────┬─────────┐
 Coin        Price 
├──────────┼─────────┤
 Bitcoin   $43,210 
 Ethereum   $3,210 
└──────────┴─────────┘

python rich tables example python rich tables example

boltons (Batteries You Didn’t Know Were Missing)

Think of boltons as the "secret drawer" of Python utilities.

boltons.iterutils.unique_iter(src, key=None)
unique docs
Yield unique elements from the iterable, src, based on key, in the order in which they first appeared in src.
By default, key is the object itself, but key can either be a callable or, for convenience, a string name of the attribute on which to uniqueify objects, falling back on identity when the attribute is not present.
import boltons

boltons.iterutils.unique([1,2,3,4,5,6,1,2])
# [1, 2, 3, 4, 5, 6]

list(boltons.iterutils.unique_iter(['hi', 'hello', 'ok', 'bye', 'yes'], key=lambda x: len(x)))
# ['hi', 'hello', 'bye']

1 > 2
# False
2 > 2
# False
# 3 > 2
True

boltons.iterutils.unique([1,2,3,4,5,6], key=lambda x : x > 2)
# [1, 3]
boltons.iterutils.redundant(src, key=None, groups=False)
The complement of unique()
redundant docs
By default returns non-unique/duplicate values as a list of the first redundant value in src. Pass groups=True to get groups of all values with redundancies, ordered by position of the first redundant value. This is useful in conjunction with some normalizing key function.
from boltons.iterutils import redundant

redundant([1, 2, 3, 4])
# []
redundant([1, 2, 3, 2, 3, 3, 4])
# [2, 3]
redundant([1, 2, 3, 2, 3, 3, 4], groups=True)
# [[2, 2], [3, 3, 3]]


# An example using a key function to do case-insensitive redundancy detection.

redundant(['hi', 'Hi', 'HI', 'hello'], key=str.lower)
# ['Hi']

redundant(['hi', 'Hi', 'HI', 'hello'], groups=True, key=str.lower)
# [['hi', 'Hi', 'HI']]

pywhat (What Even Is This File?)

Ever get a weird file, string, or hex blob and wonder what on earth it is?

from pywhat import whatis

print(whatis("d41d8cd98f00b204e9800998ecf8427e"))
# Output: MD5 hash of an empty string
  • It identifies file types, encodings, and hashes like a forensic detective.
  • This library can detect 300+ patterns, from obscure hash algorithms to credit card numbers.
  • pywhat docs

Playwright — Automating the Web

Problem: Logging into portals and downloading files manually. Every. Single. Day. \
Project: Auto-login bot.

Steps
Use Playwright to launch Chromium in headless mode.
Log into your account.
Download the latest statement automatically.
# pip install playwright
# pip install pytest-playwright (optional)

# Install the required browsers:
# playwright install

from playwright.sync_api import sync_playwright
import re

with sync_playwright() as p:
    browser = p.firefox.launch(headless=False, slow_mo=5000)
    page = browser.new_page()
    page.goto("https://playwright.dev")
    print(page.title())
    browser.close()

The best part? It doesn’t break every time the site sneezes (looking at you, Selenium 👀).

PyAutoGUI: Automate Your Computer Like a Hacker

Ever wanted your script to literally move your mouse, type into apps, or take screenshots? That’s PyAutoGUI.

import pyautogui

pyautogui.moveTo(500, 500)
pyautogui.click()
pyautogui.typewrite("Automation is fun!")

Pydantic-Core (v2) – Data Validation Without the Bloat

Forget what you knew about Pydantic v1. Pydantic-Core (which powers Pydantic v2) is a Rust-backed, zero-dependency, high-speed data validation and serialization engine. And you can use it completely standalone — no FastAPI needed.

Why it’s modular:
You define schema validation without touching any HTTP logic.
Works as a thin validation layer — plug it into any project.
Interop with JSON Schema, msgpack, or even direct memory structures.
from pydantic_core import SchemaValidator

schema = {
    'type': 'typed-dict',
    'fields': {
        'name': {'schema': {'type': 'str'}},
        'age': {'schema': {'type': 'int'}}
    }
}

validator = SchemaValidator(schema)
data = validator.validate_python({'name': 'Alice', 'age': 30})

Why it changed how I work:

I stopped trusting incoming JSON structures from external sources. Now I run everything through Pydantic-Core — it’s like a seatbelt for your data.

Pydantic-Core is 70x faster than the original Pydantic in many cases. Yes, seventy.

Msgspec – JSON Parsing at C-Speed with Type Safety

Frameworks love their JSON. But they parse it slow. Enter msgspec, a lesser-known gem that delivers ultra-fast JSON, MessagePack, and TOML parsing with optional type checking.

Think Pydantic + orjson — but leaner, faster, and with zero dependencies.

import msgspec

class User(msgspec.Struct):
    name: str
    age: int

data = msgspec.json.decode(b'{"name": "Alice", "age": 30}', type=User)
Why it’s modular:
Plug it into any project — no need for ORM, framework, or API layer.
Works with plain structs — no magic metaclasses.
Serialization + deserialization in one.

On large payloads, msgspec is 10–15x faster than the standard json module. I use msgspec as the default deserializer for every API service I build. It’s like giving your app a JSON Red Bull.

SUBSCRIBE FOR NEW ARTICLES

@
comments powered by Disqus