Python programs operate on objects with explicit input, ownership and failure contracts.
Learning roadmap
This section contains 27 written lessons or quiz banks. Programs are verified on CPython 3.14.6. Standard-library lessons target 3.11+ syntax; lessons using data, web, machine-learning or testing packages state their tested dependencies separately. Framework programs use local test clients, not a deployed service. Read the stated limits before adapting a fixture into an application.
Text and file boundaries
Read the contract, run its program and inspect the failure case.
- Python JSON validation: reject duplicate members and non-integer amounts
- Python CSV imports: parse quoted fields before validating rows
- Python pathlib files: specify encoding and close the resource owner
Database and diagnostic boundaries
Read the contract, run its program and inspect the failure case.
- Python sqlite3 transactions: bind values and roll back failed batches
- Python logging: include bounded context without printing sensitive payloads
Field and test boundaries
Read the contract, run its program and inspect the failure case.
- Python regular expressions: use fullmatch for a complete field contract
- Python datetime: require an offset before comparing timestamps
- Python unittest: test rejected input and preserve state after failure
Bounded ingestion
Read the contract, run its program and inspect the failure case.
Configuration and disclosure boundaries
Read the contract, run its program and inspect the failure case.
- Python tomllib: parse configuration and validate its schema
- Python configuration precedence: merge, validate, then publish
- Python logging: allowlist fields before they reach a handler
Reception, writer contention and owned archive members
Read the contract, run its program and inspect the failure case.
- Python JSON Lines: cap line bytes and validate the whole batch before returning it
- Python SQLite writer contention: reject a busy transaction before changing state
- Python ZIP extraction: validate names and decompressed budgets before owned writes
Wire spelling, authentication and expansion budgets
Read the contract, run its program and inspect the failure case.
- Python strict Base64: reject alternate spellings before decoding a record
- Python HMAC envelopes: authenticate exact bytes and separate replay policy
- Python bounded gzip decoding: cap expanded output before publishing it
Partial input and nested rollback
Read the contract, run its program and inspect the failure case.
- Python SQLite savepoints: discard one substep without committing the batch
- Python SpooledTemporaryFile: rollover is a storage choice, not an upload limit
- Python socket recv: assemble a bounded frame across partial reads
Sorted feeds and relational integrity
Read the contract, run its program and inspect the failure case.
- Python heapq.merge: combine sorted feeds without sorting every value again
- Python SQLite foreign keys: enable enforcement on each connection
Ambiguous input fields
Read the contract, run its program and inspect the failure case.
- Python JSON duplicate keys: reject ambiguous object fields
- Python CSV headers: reject duplicate names before row mapping
SQLite key and replay rules
Read the contract, run its program and inspect the failure case.
- Python SQLite UNIQUE with NULL: an absent key can repeat
- Python SQLite upsert: make a replay update explicit
Continue learning
Move between tutorial, collections, advanced material and practice using the subject tabs. The sidebar changes with each section; related examples keep one canonical lesson URL.
- Python Tutorial
- Data Types & Collections
- Advanced Python
- Interview Questions
- Exercises
- Quizzes
- Projects
- Cheatsheet
- DSA in Python
- Packaging & Tools
- Data Analysis
- Web Applications
- Testing & Quality
SQLite and JSON integrity
- Python SQLite busy writer: handle contention as a bounded outcome
- Python SQLite WAL reader: an open transaction keeps its snapshot
- Python JSON nonfinite numbers: reject NaN on input and output
Spreadsheet export boundaries
Lifetime and I/O boundaries
- Python subprocess pipe: stop after the first byte beyond budget
- Python streaming SHA-256: hash bytes without a second full copy
Python 3.13 and 3.14 contracts
- Python UUIDv7: time-ordered IDs without treating them as a clock
- Python Zstandard decompression: stop at an output budget
Runtime, profiling, and ownership
- Python template strings: escape text values before rendering HTML
- Python Path.copy: a snapshot needs an explicit metadata policy
Native and platform boundaries
- Python POSIX filename bytes: round-trip an undecodable path
- Python POSIX subprocess timeout: stop the owned process group
- Python amount parsing: define a wire format before Decimal
Bounded streams and storage controls
- Python SQLite blob handles: preallocate bytes and keep the write inside a transaction
- Python SQLite authorizer: deny a statement on the connection that executes it
- Python SQLite progress handler: interrupt one expensive statement
- Python SQLite SQL length limits: cap statement text separately from bound values
- Python mmap access modes: write-through changes a file, copy-on-write does not
- Python os.scandir metadata: a cached DirEntry is not a fresh file check
- Python SQLite Row: duplicate result names make named access ambiguous
Received data and owned local I/O
- Python pickle: preserve trusted aliases without decoding received objects
- Python query strings: retain blank fields and reject repeated keys
- Python EmailMessage: keep received newlines out of a header field
- Python email parsing: inspect all sender headers before trusting one
- Python ConfigParser: read literal percent signs without hidden interpolation
- Python socket recv: assemble an exact frame across local socket reads
- Python TextIOWrapper: choose whether input line endings are normalized
- Python POSIX dir_fd and O_NOFOLLOW: reject a final symlink on an owned open
