# The Python Standard Library

> Learn what Python's standard library includes, how it differs from built-ins and third-party packages, and how to import its modules.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2021-01-01 | Updated: 2026-07-18 | Topics: [Python](https://flaviocopes.com/tags/python/) | Canonical: https://flaviocopes.com/python-standard-library/

[Python](https://flaviocopes.com/python-introduction/) ships with a large **standard library**.

It includes modules for working with files, dates, JSON, databases, networking, testing, logging, and much more. You do not install these modules from PyPI before importing them.

Use the [standard library reference](https://docs.python.org/3/library/) for the Python version you run. Module availability can vary by platform and distribution. For example, `tkinter` depends on Tcl/Tk being available.

## Built-ins, the standard library, and third-party packages

These three groups are related, but they are not the same:

- Built-in functions and types such as `print()`, `len()`, `str`, and `list` are available without an import.
- Standard library modules ship with Python and normally need an `import`.
- Third-party packages are installed separately, usually from the [Python Package Index](https://pypi.org/).

For example, `requests` is a popular third-party HTTP package. It is not part of the standard library. Python's standard library includes `urllib.request` for opening URLs.

## Useful standard library modules

Here are some modules worth knowing:

- `math` for math utilities
- `re` for regular expressions
- `json` to work with [JSON](https://flaviocopes.com/json/)
- `datetime` to work with dates
- `pathlib` to work with filesystem paths
- `sqlite3` to use SQLite
- `os` and `sys` for operating system and interpreter functionality
- `collections` for specialized container data types
- `itertools` and `functools` for iteration and function tools
- `subprocess` to start and communicate with other programs
- `logging` for application logs
- `unittest` for automated tests
- `venv` to create virtual environments
- `random` for simulations and other non-security uses
- `secrets` for security-sensitive random values
- `statistics` for statistics utilities
- `urllib.request` to open URLs

The [`random` documentation](https://docs.python.org/3/library/random.html) explicitly recommends `secrets` for cryptographic and security uses.

## How to import a module

You import a standard library module in the same way you import code from another module:

```python
import math

result = math.sqrt(4)
print(result)  # 2.0
```

You can also import a specific name:

```python
from math import sqrt

result = sqrt(4)
print(result)  # 2.0
```

Importing the module is often clearer because `math.sqrt()` immediately tells the reader where `sqrt()` came from.

Here is a small HTTP example using only the standard library:

```python
from urllib.request import urlopen

with urlopen("https://www.python.org/", timeout=10) as response:
    html = response.read()

print(len(html))
```

For a real application, also handle network errors and decide how much response data you are willing to read.
