Skip to main content
The Python Standard Library is a collection of modules and packages distributed with Python. It provides a wide range of facilities including built-in functions, data types, file I/O, networking, concurrency, and much more.

What’s in the Standard Library?

The standard library is organized into several categories:

Core Language Features

  • Built-in Functions: Available without importing (print(), len(), range(), etc.)
  • Built-in Types: Fundamental data types (int, str, list, dict, etc.)
  • Built-in Exceptions: Standard exception hierarchy

Essential Modules

sys

System-specific parameters and functions

os

Operating system interfaces

pathlib

Object-oriented filesystem paths

datetime

Date and time manipulation

Data Structures & Algorithms

collections

Specialized container datatypes

itertools

Iterator building blocks

functools

Higher-order functions and operations

typing

Type hints and annotations

Concurrency & Parallelism

asyncio

Asynchronous I/O and coroutines

threading

Thread-based parallelism

multiprocessing

Process-based parallelism

concurrent.futures

High-level concurrency interface

Text Processing

re

Regular expression operations

string

String operations and formatting

json

JSON encoder and decoder

csv

CSV file reading and writing

File & Data Persistence

io

Core I/O operations

pickle

Python object serialization

sqlite3

SQLite database interface

zipfile

ZIP archive handling

Networking & Internet

socket

Low-level networking interface

http

HTTP modules

urllib

URL handling modules

email

Email and MIME handling

Library Philosophy

The Python Standard Library follows these principles:
Python comes with a comprehensive standard library that provides tools for common programming tasks without requiring external dependencies.
Most standard library modules work consistently across different operating systems, with platform-specific variations clearly documented.
All standard library modules are thoroughly tested and maintained by the Python core development team.
Standard library APIs are stable and follow strict backward compatibility guidelines.

Getting Started

No installation required! The standard library is included with Python:
import sys
import os
from pathlib import Path
from datetime import datetime

print(f"Python {sys.version}")
print(f"Running on {sys.platform}")
print(f"Current directory: {Path.cwd()}")
print(f"Current time: {datetime.now()}")

Common Patterns

File Operations

from pathlib import Path

# Modern path handling
path = Path("data.txt")
if path.exists():
    content = path.read_text()
    print(content)

Date and Time

from datetime import datetime, timedelta

# Current time
now = datetime.now()

# Time arithmetic
tomorrow = now + timedelta(days=1)
print(f"Tomorrow: {tomorrow.strftime('%Y-%m-%d')}")

Data Structures

from collections import Counter, defaultdict, deque

# Count items
items = ['apple', 'banana', 'apple', 'orange', 'banana', 'apple']
count = Counter(items)
print(count.most_common(2))  # [('apple', 3), ('banana', 2)]

# Default dictionary
grouped = defaultdict(list)
grouped['fruits'].append('apple')

# Double-ended queue
queue = deque([1, 2, 3])
queue.appendleft(0)  # Add to front

Concurrency

import asyncio

async def fetch_data():
    await asyncio.sleep(1)
    return "Data fetched"

async def main():
    result = await fetch_data()
    print(result)

asyncio.run(main())

Next Steps

Built-in Functions

Explore Python’s built-in functions

Built-in Types

Learn about fundamental data types
Start with the modules you’ll use most: sys, os, pathlib, datetime, and json.

Build docs developers (and LLMs) love