Two import styles
import json imports the whole module — you then write json.dumps() to call it. The module name acts as a namespace, so there are no name collisions.
from pathlib import Path imports just the Path class directly into your namespace. You write Path("file.txt") instead of pathlib.Path("file.txt").
Line-by-line
- json Built-in JSON encoder/decoder — serialize Python objects to strings and back.
- functools Higher-order functions: wraps, reduce, lru_cache, partial.
- datetime Dates, times, and time arithmetic.
- Path Object-oriented file-path manipulation — much cleaner than os.path.
- dataclass Decorator that auto-generates __init__, __repr__, __eq__ from annotations.
- Optional Type hint: Optional[str] means the value can be str or None.
- Counter Dict subclass that auto-counts hashable objects.