Python comes with a huge standard library — modules that ship with every Python install. Knowing what’s there saves you from reinventing things and from reaching for a third-party package when you don’t need one.
This lesson is a quick tour. Section 14 covers the most useful modules in depth.
Maths and numbers
math— everyday maths:sqrt,log,cos,pi,floor,ceil.statistics— basic stats:mean,median,stdev,variance.decimal— exact decimal arithmetic for money.fractions— exact fractions like 1/3.
Randomness
random— random numbers, choices, shuffles.secrets— cryptographically safe random values (for tokens, passwords).
Dates and times
datetime— dates, times, durations.time— lower-level clock and sleep functions.calendar— calendar utilities.zoneinfo— timezone-aware times.
Collections and iteration
collections—Counter,defaultdict,deque,OrderedDict,namedtuple.itertools—chain,groupby,combinations,product,islice.functools—partial,reduce,lru_cache,cache.
Files and the filesystem
pathlib— modern path handling (covered in Section 10).os— OS-level operations: env vars, processes, low-level file ops.shutil— copying, moving, deleting trees of files.tempfile— temporary files and directories.glob— finding files by pattern (also viapathlib.Path.glob).
Data formats
json— JSON (covered in Section 10).csv— CSV (covered in Section 10).tomllib— TOML reading (Python 3.11+).xml.etree.ElementTree— XML parsing.
System and process
sys— interpreter info, command-line arguments, exit.argparse— building command-line interfaces.subprocess— running other programs.logging— proper logging (covered in Section 15).
Networking
urllib— basic HTTP requests.http— lower-level HTTP tools.socket— raw socket programming.
For real HTTP work, almost everyone uses the third-party requests library or the modern httpx. urllib is fine for quick tasks.
Concurrency
threading— threads.multiprocessing— processes.asyncio— async/await for I/O concurrency.concurrent.futures— high-level “run these in parallel” interface.
We won’t cover concurrency in this course — it’s a substantial topic for a follow-up.
Text and strings
re— regular expressions.string— string constants (ascii_letters,digits,punctuation), templates.textwrap— wrap and dedent text.
Debugging and testing
unittest— built-in testing framework.pdb— Python debugger (covered in Section 15).pprint— pretty-print complex data structures.traceback— work with tracebacks programmatically.
For testing, most modern projects use the third-party pytest instead of unittest — but unittest is always available.
Miscellany
enum— enumeration types.typing— type-hinting helpers (we’ll see more in Section 13).dataclasses— boilerplate-free classes (covered in Section 12).hashlib— hashing (SHA, MD5).uuid— UUIDs.gzip,zipfile,tarfile— compressed files.
How to discover more
When you find yourself thinking “I bet Python has a built-in for this”, check first:
- Search the Python docs.
- Type
help(module_name)in the REPL. - Skim the standard library index — even a quick scroll teaches you what’s available.
A surprising amount of common work — parsing dates, counting words, downloading files, walking directories — has a clean built-in answer.
What’s next
Final lesson of the section — running modules as scripts, the right way.