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