Python ships with a comprehensive standard library — over 200 modules covering file I/O, networking, data formats, concurrency, testing, cryptography, and more. These pages cover the most commonly used modules with real code examples sourced from the official Python documentation.
Operating System & Files
osFile paths, directory operations, environment variables, process info. The bridge between Python and the OS.
Built · Session 23sysCommand-line arguments (argv), stdin/stdout/stderr, sys.path, sys.modules, interpreter version. Direct access to the Python interpreter.
Built · Session 23pathlibObject-oriented file paths — join with /, read/write directly, glob/rglob. The modern replacement for os.path string manipulation.
Built · Session 23Data Formats & Text
jsonEncode Python to JSON and decode JSON to Python. Custom encoders for datetimes, Decimal, and any object.
Built · Session 23reRegular expressions — search, match, findall, sub, groups, lookaheads. Find patterns in any text.
Built · Session 23datetimeDate and time objects, timedelta, strftime/strptime, timezone-aware datetimes, and zoneinfo for the IANA database.
Built · Session 23Data Structures & Iterators
collectionsCounter, defaultdict, namedtuple, deque, OrderedDict, ChainMap — specialised containers that go beyond list and dict.
Built · Session 23itertoolschain, product, combinations, groupby, accumulate — the iterator algebra toolkit for memory-efficient sequence operations.
Built · Session 23Coming in future sessions
asyncioAsync I/O, event loops, coroutines, tasks, and streams. The framework for concurrent Python code.
Coming · Session 24unittestTest cases, assertions, mocking, and test runners. Python's built-in testing framework.
Coming · Session 24loggingStructured logging with levels, handlers, formatters, and propagation. The right way to record what your program does.
Coming · Session 24functoolslru_cache and cache for memoisation, partial, reduce, singledispatch, cached_property, total_ordering.
csvRead and write CSV correctly — reader, writer, DictReader, DictWriter, dialects, and the newline="" rule.
subprocessRun external programs — subprocess.run(), capture output, pipelines, timeouts, Popen, injection safety.
argparseCommand-line argument parsing — parsers, positional/optional args, types, choices, subcommands.
mathMathematical functions — constants, sqrt, rounding, trig, logs, isclose for float safety.
randomPseudo-random numbers — randint, choice, shuffle, sample, distributions, seeding (not for security).
contextlibwith-statement utilities — @contextmanager, suppress, redirect_stdout, ExitStack.
secretsCryptographically secure random — tokens, passwords, constant-time compare. Use for all security randomness.
hashlibSecure hashes — SHA-256, file integrity, password hashing with pbkdf2/scrypt, HMAC, BLAKE2.
statisticsStatistics without NumPy — mean, median, stdev, NormalDist, quantiles, correlation, regression.
pickleObject serialization — save any Python object to bytes. Powerful but unsafe with untrusted data.
sqlite3Built-in SQL database — zero setup, one file. Connect, query, parameters, transactions, Row factory.
timeSystem clock, sleep, and performance timing — timestamps, perf_counter, monotonic, nanosecond clocks.
shutilHigh-level file operations — copy/move directory trees, rmtree, create and extract archives, disk usage.
copyShallow and deep copy — the difference that causes Python’s most confusing bugs. copy() vs deepcopy().
concurrent.futuresHigh-level parallelism — run functions across threads or processes with one uniform API. Futures, map, submit.
queueThread-safe queues — pass work between threads safely. FIFO, LIFO, priority, producer-consumer, join.
socketLow-level networking — the foundation beneath every HTTP library. TCP/UDP clients and servers.
http.serverBuilt-in HTTP server — instant file sharing and custom handlers. For development and learning, not production.