Standard Library Overview
Python ships a large standard library - batteries included for paths, time, JSON, processes, parsing, and more. Reach for stdlib before adding dependencies; know which module owns each job.
Search across all documentation pages
Python ships a large standard library - batteries included for paths, time, JSON, processes, parsing, and more. Reach for stdlib before adding dependencies; know which module owns each job.
from pathlib import Path
import json
import logging
log = logging.getLogger(__name__)
config = json.loads(Path("config.json").read_text(encoding="utf-8"))
log.info("loaded keys=%s", list(config))When to reach for stdlib:
pathlibargparseurllib or httpx if needs growhashlib, secretssubprocessMap common tasks to modules in one script.
from __future__ import annotations
import json
import re
import secrets
import subprocess
import sys
from datetime import datetime, timezone
from pathlib import Path
def snapshot_system(tmp: Path) -> dict:
return {
"python": sys.version.split()[0],
"cwd": str(Path.cwd()),
"now_utc": datetime.now(timezone.utc).isoformat(),
"token": secrets.token_hex(8),
"digits": re.findall(r"\d+", "a1b22"),
"ls": subprocess.run(
["ls", str(tmp)],
capture_output=True,
text=True,
check=False,
).stdout.strip(),
}
tmp = Path("/tmp")
print(json.dumps(snapshot_system(tmp), indent=2))What this demonstrates:
| Need | Module |
|---|---|
| Paths | pathlib, os |
| Time | datetime, zoneinfo |
| Data formats | json, tomllib (3.11+) |
| Text patterns | re |
| Processes | subprocess |
| CLI | argparse |
| Crypto-ish | hashlib, secrets, hmac |
more-itertools nice but itertools often enough. Fix: check stdlib first.shell=False.| Alternative | Use When | Don't Use When |
|---|---|---|
| PyPI micro-lib | Stdlib missing feature | One-function need covered |
| Vendor copy | Restricted deploy | Normal network install ok |
Modules evolve with deprecation cycles - read What's New per Python version (3.14).
urllib.request for simple sync; production services use httpx/requests.
tomllib for pyproject TOML; configparser for INI-style legacy config.
asyncio, async generators, some protocols - not all IO is async-native.
docs.python.org library index + this section's focused pages.
typing, types, dataclasses, enum - no pydantic required for simple models.
Yes pickle - avoid untrusted data; prefer json for interchange.
logging for services; print for CLI user output and quick scripts.
Yes - pair with uv 0.6+ externally for speed per team toolchain.
Check official 3.14 release notes for stdlib additions affecting your pins.
Stack versions: This page was written for Python 3.14.0 (stable 3.14, maintenance 3.13), FastAPI 0.115+, Django 5.2, Flask 3.1, Pydantic 2, PyTorch 2.6+, pandas 2.2+, Polars 1.x, ruff 0.9+, and uv 0.6+.
Reviewed by Chris St. John·Last updated Jul 19, 2026