The Python Standard Library is a collection of built-in modules and packages that come pre-installed with Python.
👉 You do NOT need to install anything to use it.
👉 It provides ready-made solutions for common programming tasks.
Python follows the philosophy:
“Batteries Included”
Meaning:
Python already gives you tools for most real-world problems.
The standard library helps you:
- Avoid reinventing the wheel
- Write less code
- Build reliable applications
- Follow best practices
- Work efficiently without third-party packages
You can handle:
- Files & directories
- Dates & time
- Math & statistics
- OS interaction
- Networking & internet
- Data formats (JSON, CSV)
- Compression
- Multithreading & multiprocessing
- Debugging & testing
- Security & encryption
All without installing anything.
Below are the most important categories, explained one by one.
Modules for mathematical operations.
mathrandomstatisticsdecimalfractions
import math
print(math.sqrt(16))
print(math.pi)Used for working with dates, times, and timestamps.
datetimetimecalendar
from datetime import datetime
now = datetime.now()
print(now)Used to work with files and folders.
ospathlibshutilglob
import os
print(os.getcwd())Used for reading/writing structured data.
jsoncsvpickleconfigparser
import json
data = {"name": "Alice", "age": 30}
json_string = json.dumps(data)
print(json_string)Used to interact with the web and networks.
urllibhttpsocketemail
from urllib.request import urlopen
response = urlopen("https://example.com")
print(response.status)Used to run tasks concurrently.
threadingmultiprocessingconcurrent.futuresasyncio
import threading
def task():
print("Task running")
t = threading.Thread(target=task)
t.start()Used to test and debug Python code.
unittestdoctestloggingtracebackpdb
import logging
logging.basicConfig(level=logging.INFO)
logging.info("This is a log message")Used for hashing and secure data handling.
hashlibsecretshmacssl
import hashlib
hash_value = hashlib.sha256(b"password").hexdigest()
print(hash_value)Used to interact with Python runtime and system.
sysargparseplatformsubprocess
import sys
print(sys.version)Tools inspired by functional programming.
functoolsitertoolsoperator
import itertools
for item in itertools.count(5, 2):
print(item)
if item > 10:
breakSpecialized data containers.
collectionsheapqarraybisect
from collections import Counter
counts = Counter("banana")
print(counts)Used to build and distribute Python projects.
venvdistutilsimportlibpkgutil
help(os)👉 https://docs.python.org/3/library/
| Mistake | Why It’s Wrong |
|---|---|
| Rewriting built-in functionality | Library already exists |
| Not reading docs | Miss powerful features |
| Using third-party libs unnecessarily | Stdlib is enough |
| Shadowing module names | Causes import errors |
✅ Prefer standard library first
✅ Learn commonly used modules deeply
✅ Combine modules effectively
✅ Read official documentation
❌ Don’t install libraries blindly
| Concept | Meaning |
|---|---|
| Standard Library | Built-in Python modules |
| Batteries Included | Ready-to-use tools |
| No installation | Comes with Python |
| Reliable | Well-tested |
| Essential | Used in all real projects |
- Write a script using
osandpathlibtogether. - Serialize and deserialize data using
json. - Hash a password using
hashlib. - Create logs using
logging. - Explore
itertoolsand explain one function.