Essential Modules in Python

From the Python cheat sheet ยท Standard Library ยท verified Jul 2026

Essential Modules

Most commonly used standard library modules.

python
from collections import Counter, defaultdict
from datetime import datetime, timedelta
from pathlib import Path
import os, re, math, subprocess

Counter(["a","b","a"]).most_common()
now = datetime.now()
Path("dir").mkdir(exist_ok=True)
subprocess.run(["ls", "-la"], check=True)
๐Ÿ’ก Counter is the fastest way to count occurrences โ€” use it instead of manual loops
โšก defaultdict(list) lets you append to missing keys without checking first
๐Ÿ“Œ Use pathlib.Path over os.path โ€” it is more readable and cross-platform
๐ŸŸข subprocess.run(..., check=True, capture_output=True, text=True) is the modern default
stdlibcollectionsdatetimepathlibosre

More Python tasks

Back to the full Python cheat sheet