What Is the Python Standard Library?

Learn what the Python standard library is, why it matters, and how to use its built-in modules without installing anything extra.

6 min read

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.

pythonpython
import math
 
print(math.sqrt(25))  # 5.0

The 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.

pythonpython
import datetime
 
today = datetime.date.today()
print(today)  # 2026-07-12

The 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:

pythonpython
from pathlib import Path
 
home = Path.home()
print(home)  # /Users/yourname

Path 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.

CategoryExample modulesWhat you can do
Math and numbersmath, random, statistics, decimal, fractionsSquare roots, random values, statistics, precise decimals
Dates and timesdatetime, time, calendar, zoneinfoWork with dates, times, time zones, and calendars
File and path operationspathlib, os, shutil, glob, tempfileBrowse folders, copy files, find files, create temp files
Data formatsjson, csv, pickle, base64, xmlRead and write JSON, CSV, and other structured data
Text processingre, string, textwrap, difflibSearch text with regex, wrap paragraphs, compare strings
Compressionzipfile, tarfile, gzip, bz2Create and extract zip and tar archives
Networking and interneturllib, email, http, socketserverMake HTTP requests, send email, build simple servers
Concurrencythreading, multiprocessing, asyncio, concurrent.futuresRun tasks in parallel, manage threads and processes
Debugging and testingpdb, unittest, doctest, tracebackDebug code, write and run tests, inspect errors
System and runtimesys, argparse, logging, platformRead command-line arguments, log messages, check the OS
Securityhashlib, secrets, hmac, sslHash passwords, generate secure tokens, use encryption
Collections and data structurescollections, array, enum, dataclasses, typingSpecialized 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.

pythonpython
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

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_name and 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.
RunePowered by Rune AI

Frequently Asked Questions

Do I need to install the standard library separately?

No. Every Python installation includes the full standard library. You can import its modules as soon as Python is installed, with no extra packages.

How many modules are in the Python standard library?

The library contains over 200 modules covering file operations, math, dates, networking, data formats, compression, debugging, testing, and much more. You do not need to learn every module. Start with the ones that match your current project.

Can I use standard library modules in any Python project?

Yes. Standard library modules work on Windows, macOS, and Linux without platform-specific setup. Some modules interact with the operating system, but the core behavior is consistent across platforms.

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.