Python Standard Library: What Ships Without Installing Anything
In the previous post we learned to handle errors gracefully. Now let us talk about something that will save you enormous amounts of time: Python’s standard library.
The Python Standard Library is the collection of modules that ships with every Python installation, covering file system operations, dates and times, data serialisation, mathematics, networking, testing, and compression without requiring a single third-party install. The first instinct of many beginners — and honestly of many experienced developers — is to reach for a third-party package. Often the right answer is already in the box.
The Python community has a saying: batteries included. This post is about finding the batteries.
Python Modules and the import Statement
Before exploring specific modules, a quick note on how to use them. A module is a Python file — or a package of files — that you bring into your script with import:
import math
print(math.sqrt(144)) # 12.0
If you only need one thing from a module, from x import y keeps the namespace cleaner:
from math import sqrt, pi
print(sqrt(144)) # 12.0
print(pi) # 3.141592653589793
You can alias a module to a shorter name with as:
import datetime as dt
today = dt.date.today()
That is all there is to it. The rest is knowing which modules exist and what they do.
pathlib — File Paths Done Right
🔒 Subscribe to keep reading.
datetime — Dates and Times
🔒 Subscribe to keep reading.
json — Data Exchange
🔒 Subscribe to keep reading.
random — Controlled Randomness
🔒 Subscribe to keep reading.
dataclasses — Structured Data Without Ceremony
🔒 Subscribe to keep reading.
Complete Example: Combining pathlib, json, random, and dataclasses
🔒 Subscribe to keep reading.
Python Standard Library vs Third-Party Packages: When to Reach for Each
🔒 Subscribe to keep reading.
References
🔒 Subscribe to keep reading.
You've hit a Deep Dive tutorial.
I spend dozens of hours researching, coding, and breaking things to write these guides. This content is free, but reserved for my subscriber community. Drop your email below to unlock this guide (and all past/future deep dives):
Full content temporarily unavailable — refresh in a moment
Already a subscriber? Use the magic link from your last newsletter, or reset your password.
Log in to unlock
New subscribers get an inbox mail: Set a password to unlock articles. The form does not log you in — use the same email afterwards.