The Python Standard Library: Built-In Modules Worth Knowing
The standard library modules you’ll actually reach for regularly — no pip install required, already in every Python installation
Common Python Packages covers the third-party libraries worth installing. This is the opposite list: what already ships with Python, no pip install required, and quietly does more of your day-to-day work than people expect.
This tour imports and uses all of the modules below, and runs as written on both Python 3.13 and 3.15:
import argparse
import csv
import io
import itertools
import json
import logging
import sqlite3
import sys
import tomllib
from collections import Counter, defaultdict, namedtuple
from dataclasses import dataclass
from datetime import datetime, timezone
from pathlib import Path
from zoneinfo import ZoneInfo
print(Counter("mississippi").most_common(2)) # [('i', 4), ('s', 4)]
print(list(itertools.combinations("abc", 2))) # [('a', 'b'), ('a', 'c'), ('b', 'c')]
print(Path("data") / "file.csv", Path("data/file.csv").suffix) # data/file.csv .csv
print(list(csv.DictReader(io.StringIO("name,score\nAda,92\n")))) # [{'name': 'Ada', 'score': '92'}]
print(json.loads('{"a": [1, 2]}')) # {'a': [1, 2]}
print(tomllib.loads('title = "demo"\n[tool]\nn = 3')) # {'title': 'demo', 'tool': {'n': 3}}
summer = datetime(2026, 7, 1, 12, 0, tzinfo=timezone.utc)
print(summer.astimezone(ZoneInfo("Europe/London")).isoformat()) # 2026-07-01T13:00:00+01:00
db = sqlite3.connect(":memory:")
db.execute("create table t(x)")
db.execute("insert into t values (1)")
print(db.execute("select count(*) from t").fetchone()) # (1,)
logging.basicConfig(level=logging.INFO, format="%(levelname)s:%(message)s", stream=sys.stdout)
logging.info("hello") # INFO:hello
parser = argparse.ArgumentParser()
parser.add_argument("--n", type=int, default=1)
print(parser.parse_args(["--n", "3"]).n) # 3Working with data structures
collections extends the built-in dict, list, and tuple with purpose-built variants — Counter for tallying items, defaultdict for dictionaries with automatic default values, namedtuple for lightweight structured records before you’d reach for a full class or a Pydantic model.
itertools provides efficient, memory-friendly ways to combine and iterate over sequences — chaining iterables together, generating permutations and combinations, or grouping consecutive items — without building intermediate lists in memory.
Working with files and paths
pathlib replaced the older os.path string-manipulation approach with an object-oriented API for filesystem paths — Path("data") / "file.csv" instead of os.path.join("data", "file.csv"), plus built-in methods for checking existence, reading text, and globbing. Modern Python code should default to pathlib over os.path. See pathlib vs os.path for side-by-side examples.
json and csv handle the two most common data interchange formats without any external dependency — reading and writing JSON, or reading and writing CSV files with proper quoting and delimiter handling. tomllib (Python 3.11 and later) reads TOML, the format of pyproject.toml; it can only read, so writing TOML needs a third-party package. sqlite3 gives you a full SQL database in a file or in memory with no server.
Working with dates, logging, and configuration
datetime handles dates and times, including timezone-aware objects — genuinely fiddly to get right by hand, and rarely worth a third-party dependency for basic use. Pair it with zoneinfo (Python 3.9 and later) for named time zones: in the tour above, noon UTC on 1 July converted to 13:00+01:00 in Europe/London. On Windows zoneinfo may need the third-party tzdata package for its zone data. logging provides structured, leveled logging (debug/info/warning/error) built in, a meaningful step up from scattering print() statements through a codebase. argparse builds command-line interfaces with help text and argument validation — Click is nicer for larger CLIs, but argparse alone covers most simple scripts without any dependency at all.
Testing without a dependency
unittest is the standard library’s built-in testing framework — class-based, assertEqual-style assertions. Most teams today prefer pytest for its plain-assert syntax and fixture system, but unittest requires zero installation and is worth knowing since some codebases and tutorials still use it. See pytest vs unittest for the fuller comparison.
What changed recently
Python 3.13 removed 19 long-deprecated modules under PEP 594; in a check on Python 3.15.2, cgi, imghdr, telnetlib, pipes, crypt, distutils, imp, asyncore and smtpd all failed to import, so old tutorials that use them need a replacement. Python 3.15 adds a profiling package (with profiling.tracing and the sampling profiler profiling.sampling), a math.integer module, and two new built-ins: frozendict and sentinel. See Python 3.15: what’s new for the full list.
Why this matters
Every module here is already installed the moment Python is — no dependency to add, no version to pin, no supply-chain surface to worry about. Reaching for the standard library first, before adding a third-party package for something it already does reasonably well, keeps a project’s dependency tree smaller and its long-term maintenance simpler.
Frequently Asked Questions
What’s the difference between the standard library and third-party packages?
Standard library modules already ship with Python — no pip install, no version to pin, no supply-chain surface. Third-party packages need to be installed separately and add to your project’s dependency tree.
Should you use pathlib or os.path?
pathlib — it replaced the older os.path string-manipulation approach with an object-oriented API for filesystem paths, plus built-in methods for checking existence, reading text, and globbing. Modern Python code should default to pathlib.
Is collections part of the Python standard library?
Yes. collections extends dict, list, and tuple with purpose-built variants — Counter for tallying items, defaultdict for automatic default values, and namedtuple for lightweight structured records.
Do you need pytest, or is unittest enough?
unittest ships with the standard library and requires zero installation, but most teams today prefer pytest for its plain-assert syntax and fixture system. unittest is worth knowing since some codebases and tutorials still use it.