thecodex.expert · The Codex Family of Knowledge
Python

Python Standard Library

The "batteries included" standard library — everything you need to work with files, time, data, text, networks, and more, without installing anything.

Python 3.13 No install needed Last verified:

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

Data Formats & Text

Data Structures & Iterators

Coming in future sessions

asyncio

Async I/O, event loops, coroutines, tasks, and streams. The framework for concurrent Python code.

Coming · Session 24
unittest

Test cases, assertions, mocking, and test runners. Python's built-in testing framework.

Coming · Session 24
📄
logging

Structured logging with levels, handlers, formatters, and propagation. The right way to record what your program does.

Coming · Session 24
📄
functools

lru_cache and cache for memoisation, partial, reduce, singledispatch, cached_property, total_ordering.

📄
csv

Read and write CSV correctly — reader, writer, DictReader, DictWriter, dialects, and the newline="" rule.

📄
subprocess

Run external programs — subprocess.run(), capture output, pipelines, timeouts, Popen, injection safety.

📄
argparse

Command-line argument parsing — parsers, positional/optional args, types, choices, subcommands.

📄
math

Mathematical functions — constants, sqrt, rounding, trig, logs, isclose for float safety.

📄
random

Pseudo-random numbers — randint, choice, shuffle, sample, distributions, seeding (not for security).

📄
contextlib

with-statement utilities — @contextmanager, suppress, redirect_stdout, ExitStack.

📄
secrets

Cryptographically secure random — tokens, passwords, constant-time compare. Use for all security randomness.

📄
hashlib

Secure hashes — SHA-256, file integrity, password hashing with pbkdf2/scrypt, HMAC, BLAKE2.

📄
statistics

Statistics without NumPy — mean, median, stdev, NormalDist, quantiles, correlation, regression.

📄
pickle

Object serialization — save any Python object to bytes. Powerful but unsafe with untrusted data.

📄
sqlite3

Built-in SQL database — zero setup, one file. Connect, query, parameters, transactions, Row factory.

📄
time

System clock, sleep, and performance timing — timestamps, perf_counter, monotonic, nanosecond clocks.

📄
shutil

High-level file operations — copy/move directory trees, rmtree, create and extract archives, disk usage.

📄
copy

Shallow and deep copy — the difference that causes Python’s most confusing bugs. copy() vs deepcopy().

📄
concurrent.futures

High-level parallelism — run functions across threads or processes with one uniform API. Futures, map, submit.

📄
queue

Thread-safe queues — pass work between threads safely. FIFO, LIFO, priority, producer-consumer, join.

📄
socket

Low-level networking — the foundation beneath every HTTP library. TCP/UDP clients and servers.

📄
http.server

Built-in HTTP server — instant file sharing and custom handlers. For development and learning, not production.