Python Standard Library Tour
Python's standard library includes 200+ modules for math, file I/O, networking, dates, JSON, regular expressions, and more — no pip install needed!
20 min•By Priygop Team•Updated 2026
Standard Library
Standard Library
# os — operating system interface
import os
print(f"OS: {os.name}")
print(f"CWD: {os.getcwd()}")
# datetime — dates and times
from datetime import datetime, timedelta
now = datetime.now()
print(f"Now: {now.strftime('%Y-%m-%d %H:%M')}")
future = now + timedelta(days=30)
print(f"In 30 days: {future.strftime('%Y-%m-%d')}")
# random — random numbers
import random
print(f"Random int: {random.randint(1, 100)}")
print(f"Random choice: {random.choice(['a', 'b', 'c'])}")
items = [1, 2, 3, 4, 5]
random.shuffle(items)
print(f"Shuffled: {items}")
# collections — specialized containers
from collections import Counter, defaultdict
words = "the cat sat on the mat the cat".split()
word_count = Counter(words)
print(f"Word count: {word_count.most_common(3)}")
# itertools — iterator tools
from itertools import chain, combinations
letters = list(combinations("ABCD", 2))
print(f"Combinations: {letters}")
# hashlib — secure hashing
import hashlib
hash_val = hashlib.sha256("password123".encode()).hexdigest()
print(f"SHA256: {hash_val[:20]}...")
# uuid — unique identifiers
import uuid
print(f"UUID: {uuid.uuid4()}")Tip
Tip
Explore the standard library before installing packages. datetime, json, csv, pathlib, collections, itertools cover most needs.
Diagram
Loading diagram…
Module = file, Package = folder + __init__.py, Library = pip.
Common Mistake
Warning
Re-implementing what the standard library already provides. Check docs.python.org/3/library before writing custom code.
Quick Quiz
Practice Task
Note
(1) Use collections.Counter to count words. (2) Use itertools.chain to flatten lists. (3) Use datetime to calculate age.