The Python standard library is a collection of more than 200 modules that come with every Python installation. It includes modules for math, dates, files, JSON, CSV, random numbers, regular expressions, logging, and many other everyday tasks. You do not need to install anything extra to use them.
Python developers call this "batteries included". The language ships with enough built-in tools that many common programming problems are solved before you ever reach for a third-party package.
import math
print(math.sqrt(25)) # 5.0The math module is part of the standard library. The import line loads it, math.sqrt(25) calls its square root function, and no pip install step was needed at any point.
Why the standard library matters
When you learn to write Python functions and split code into reusable modules, you start thinking about where shared logic should live. The standard library is the first layer of reusable code worth learning, because it is already present on every machine that runs your program.
There are three practical reasons to reach for it first:
- No dependencies, so your script runs on any machine with Python installed.
- Stability, because the modules are tested with every Python release and rarely break.
- Documentation, since every module is covered in detail at docs.python.org with examples.
This does not mean you should never use third-party libraries. When a standard library module can do the job, though, it is usually the better choice for simplicity and portability.
How to use the standard library
Using a standard library module is the same as using any Python module. Import it, then call its functions or access its attributes. There is no registration step, no download, and no configuration file to edit.
import datetime
today = datetime.date.today()
print(today) # 2026-07-12The datetime module ships with Python. You import it, call datetime.date.today(), and get the current date back. The same import-and-call pattern works for every module in the library.
You can also import specific names from a module instead of the whole thing:
from pathlib import Path
home = Path.home()
print(home) # /Users/yournamePath is a class inside the pathlib module. Importing it directly means you write Path.home() instead of pathlib.Path.home(), which keeps code shorter when you use the name often.
Categories of standard library modules
The standard library covers a wide range of tasks. This table shows the main categories and a few representative modules in each, so you can see the overall shape of what ships with Python.
| Category | Example modules | What you can do |
|---|---|---|
| Math and numbers | math, random, statistics, decimal, fractions | Square roots, random values, statistics, precise decimals |
| Dates and times | datetime, time, calendar, zoneinfo | Work with dates, times, time zones, and calendars |
| File and path operations | pathlib, os, shutil, glob, tempfile | Browse folders, copy files, find files, create temp files |
| Data formats | json, csv, pickle, base64, xml | Read and write JSON, CSV, and other structured data |
| Text processing | re, string, textwrap, difflib | Search text with regex, wrap paragraphs, compare strings |
| Compression | zipfile, tarfile, gzip, bz2 | Create and extract zip and tar archives |
| Networking and internet | urllib, email, http, socketserver | Make HTTP requests, send email, build simple servers |
| Concurrency | threading, multiprocessing, asyncio, concurrent.futures | Run tasks in parallel, manage threads and processes |
| Debugging and testing | pdb, unittest, doctest, traceback | Debug code, write and run tests, inspect errors |
| System and runtime | sys, argparse, logging, platform | Read command-line arguments, log messages, check the OS |
| Security | hashlib, secrets, hmac, ssl | Hash passwords, generate secure tokens, use encryption |
| Collections and data structures | collections, array, enum, dataclasses, typing | Specialized containers, type hints, enumerations |
This table is not exhaustive. The full library reference at docs.python.org lists every module, but you do not need to memorize it. Learn modules as you encounter the tasks they solve.
A practical example
Say you want to read a JSON file, pick a random item from a list inside it, and log the result. Every part of that job is covered by a built-in module, so the whole script needs no installs and runs anywhere.
import json
import logging
import random
logging.basicConfig(level=logging.INFO)
with open("tasks.json") as file:
data = json.load(file)
task = random.choice(data["items"])
logging.info("Selected task: %s", task)Three modules work together here: json parses the file, random picks an item, and logging writes an informational message to the console. This is the standard library mindset in action. When you need a common capability, check the built-in modules before searching for a package.
How to explore the standard library
You do not need to read the entire library reference to benefit from it. Start with the modules that match what you are building right now, and let each new task introduce you to the next module.
A practical exploration path looks like this:
- Ask whether Python has a built-in module for the task in front of you.
- Search the official library index at docs.python.org for a matching module.
- Try a small example in the Python shell before adding it to your project.
For example, a search for "path" leads you to pathlib for file paths. If you need random values, the random module has you covered, and when you need to work with dates and times, datetime is the answer.
When to use a third-party library instead
The standard library is not always the right answer, and knowing its limits matters as much as knowing its contents. Reach for an external package in a few clear situations.
- The built-in module lacks a feature you need, the way the requests package improves on urllib for complex HTTP work.
- You need more performance than the built-in module can provide.
- A third-party library is the de facto standard for the task, such as NumPy for numerical computing or pandas for data analysis.
The key is to make the choice consciously. Know what the standard library offers, then decide whether it fits. Do not default to an external package just because a tutorial happened to use one.
What to learn next
The library is large, but a small set of core modules covers most day-to-day work. Learn the math module for calculations, random for random values, and datetime for dates and times. After those, pathlib for file paths and json for structured data will carry you through most real projects.
Rune AI
Key Insights
- The Python standard library is a collection of over 200 modules included with every Python installation.
- "Batteries included" means you can handle many common programming tasks without installing third-party packages.
- Import a standard library module with
import module_nameand start using it immediately. - Standard library modules are maintained, documented, and tested alongside Python itself.
- Before reaching for an external library, check whether a standard library module already covers your need.
Frequently Asked Questions
Do I need to install the standard library separately?
How many modules are in the Python standard library?
Can I use standard library modules in any Python project?
Conclusion
The standard library is the first place to look when you need common functionality in Python. Before reaching for a third-party package, check whether the standard library already has a module that solves your problem. Using built-in tools keeps your project smaller, faster to set up, and easier for others to run.
More in this topic
Format Dates and Times in Python
Learn how to use strftime and strptime to format dates as strings and parse date strings into Python datetime objects.
Encode and Decode Base64 Data in Python
Learn how to use Python's base64 module to encode binary data as text and decode Base64 strings back to bytes.
Python `math` Module Explained
Learn how to use the Python math module for square roots, rounding, trigonometry, logarithms, and mathematical constants.