The Standard Library
One of Python's biggest selling points is often summed up in a single phrase: "batteries included." When you install Python, you don't just get the language syntax — you get a vast collection of modules, ready to use, covering everything from file system access and networking to data compression, testing, and text processing. This is the standard library, and it ships with every Python installation, with no extra downloads or package managers required.
The philosophy behind this is practical. Many everyday programming tasks — reading a file path in a cross-platform way, parsing JSON, scheduling a delay, generating a random number, running a shell command — are common enough that Python's core developers decided they belong in the language distribution itself, rather than being left to a patchwork of third-party packages of varying quality and maintenance. This means you can write a surprising amount of useful, production-grade code using only what's already installed, with no dependency management at all.
That doesn't mean the standard library replaces the wider PyPI ecosystem — packages like requests, numpy, or pandas exist because they do things the standard library either can't do or doesn't do as conveniently. But it does mean the standard library should usually be your first stop, not your last resort.
A tour of the most useful modules
The standard library contains well over 200 modules. You won't need most of them most of the time, but a handful come up constantly across almost every kind of Python project. Here's a curated map of the ones worth knowing by name.
Module | Purpose |
|---|---|
os | Interacting with the operating system — files, paths, environment variables |
sys | Interpreter internals — argv, path, exit |
json | Encode and decode JSON data |
datetime | Working with dates and times |
re | Regular expressions |
collections | Specialized container datatypes like Counter, defaultdict, deque |
itertools | Fast, memory-efficient iterator building blocks |
functools | Higher-order functions like reduce, lru_cache, partial |
pathlib | Object-oriented filesystem paths |
subprocess | Spawning and communicating with child processes |
argparse | Parsing command-line arguments |
logging | Flexible event logging |
unittest | Built-in testing framework |
math | Mathematical functions |
random | Pseudo-random number generation |
Seeing it in action
These modules aren't just abstract names in a table — they're one import away from solving a real problem. A few quick examples:
import os
# Where am I, and what's in this environment variable?
print(os.getcwd())
print(os.environ.get('HOME'))
# List every file in the current directory
for name in os.listdir('.'):
print(name)from pathlib import Path
# pathlib gives you an object-oriented, cross-platform way
# to build and inspect filesystem paths
config_path = Path('app') / 'config' / 'settings.json'
print(config_path)
print(config_path.suffix) # .json
print(config_path.exists())from collections import Counter
words = 'the quick brown fox jumps over the lazy dog the fox runs'.split()
counts = Counter(words)
print(counts.most_common(3))
# [('the', 3), ('fox', 2), ('quick', 1)]Python documentation has a full index of every stdlib module. It won't have a dependency to manage, a version to pin, or a supply-chain risk to audit, and it will already be installed everywhere your code runs.