Chapter 1 — The Python Object Model
- 1.1 Everything Is an Object
- 1.2 Attribute Lookup: The Full Resolution Order
- 1.3 Special Methods (Dunder Methods)
- 1.4
__slots__ - 1.5 Function Objects in Depth
- 1.6 Attribute Access Hooks
- 1.7
@property,@staticmethod,@classmethod - 1.8
__init_subclass__and Class Hooks - 1.9 The
object.__class__andtype.__instancecheck__ - 1.10 Object Copying
- 1.11 Identity, Equality, and Interning
- Summary of Key Principles
Chapter 2 — The Type System & Type Hints
- 2.1 The Purpose of Type Hints in Python
- 2.2 Annotation Mechanics
- 2.3 Core Typing Constructs
- 2.4 Generics
- 2.5 Structural Typing with
Protocol - 2.6
TypedDict - 2.7
dataclassvsNamedTuplevsTypedDict - 2.8
@overload - 2.9 Abstract Base Classes and
typing.abc - 2.10 Annotating Callables
- 2.11 Runtime Type Checking
- 2.12
mypyConfiguration and Usage Patterns - 2.13 Common Typing Mistakes and Misconceptions
- 2.14 Typing Patterns for Interview Code
- Summary
Chapter 3 — Functional Programming: Comprehensions, functools, itertools
- 3.1 What “Functional” Means in Python
- 3.2 Comprehensions
- 3.3
functools - 3.4
itertools - 3.5 Building an Iterator Algebra
- 3.6
operatorModule - 3.7 Higher-Order Function Patterns
- 3.8
mapandfilter - 3.9 Performance Reference
- 3.10 Common Interview Applications
- Summary
Chapter 4 — Iterators, Generators & Coroutines
- 4.1 The Iterator Protocol
- 4.2 Generator Functions
- 4.3
yield from - 4.4 Practical Generator Patterns
- 4.5 Async Generators
- 4.6
contextlibUtilities - 4.7 Advanced Generator Internals
- 4.8 Typing Generators and Iterators
- 4.9 Common Mistakes and Pitfalls
- 4.10 Complete Example: Lazy Streaming Pipeline
- Summary
Chapter 5 — Decorators & Metaclasses
- 5.1 What a Decorator Is
- 5.2 Function Decorators
- 5.3 Class Decorators
- 5.4 Stacking Decorators
- 5.5 Descriptors as Decorators
- 5.6 The
typeMetaclass - 5.7 Writing Metaclasses
- 5.8 Abstract Base Classes
- 5.9
__init_subclass__— Metaclass-Lite - 5.10 Decorator Patterns Reference
- 5.11 Decorator Anti-Patterns
- 5.12 Choosing the Right Tool
- 5.13 Complete Example: A Production-Grade Decorator Stack
- Summary
Chapter 6 — Memory Management & CPython Internals
- 6.1 Why CPython Internals Matter at Staff Level
- 6.2 Reference Counting
- 6.3 The Cyclic Garbage Collector
- 6.4 CPython Memory Allocator
- 6.5 String Interning
- 6.6 Integer Interning
- 6.7 The
disModule — Bytecode Inspection - 6.8 The Import System
- 6.9 The Global Interpreter Lock (Preview)
- 6.10 Profiling and Memory Tracing
- 6.11 Object Lifecycle Patterns and Leak Detection
- 6.12
__del__,weakref.finalize, and Safe Cleanup - 6.13 Slots Revisited — Memory Layout
- Summary
Chapter 7 — The GIL: A Precise Model
- 7.1 What the GIL Is
- 7.2 Why the GIL Exists
- 7.3 The Execution Model: When the GIL Is Held and Released
- 7.4 Threading with the GIL: What Actually Happens
- 7.5 The GIL and C Extensions
- 7.6 Alternatives to the GIL for CPU-Bound Parallelism
- 7.7 Atomicity Under the GIL
- 7.8 The GIL and
asyncio - 7.9 Diagnosing GIL-Related Performance Problems
- 7.10 The GIL in Practice: Decision Framework
- 7.11 Common Misconceptions
- Summary
Chapter 8 — Threading: Correct Concurrent Design
- 8.1 The
threadingModule - 8.2
Thread— Lifecycle and Configuration - 8.3
Lock— Mutual Exclusion - 8.4
RLock— Reentrant Lock - 8.5
SemaphoreandBoundedSemaphore - 8.6
Event— Thread Signalling - 8.7
Condition— Monitor Pattern - 8.8
Barrier— Phase Synchronisation - 8.9
threading.local— Thread-Local Storage - 8.10 Deadlock
- 8.11 Livelock and Starvation
- 8.12 Correct Thread-Safe Patterns
- 8.13
threading.Timer - 8.14
threading.excepthook— Unhandled Thread Exceptions - 8.15 Complete Example: Thread-Safe Web Crawler
- Summary
Chapter 9 — concurrent.futures & Queue-Based Concurrency
- 9.1 The Abstraction Hierarchy
- 9.2
concurrent.futures— Core Concepts - 9.3
ThreadPoolExecutorin Depth - 9.4
ProcessPoolExecutorin Depth - 9.5
queueModule — Production Queue Types - 9.6 Producer-Consumer Patterns
- 9.7 Backpressure
- 9.8
concurrent.futuresvsqueue— Decision Guide - 9.9 Error Handling in Futures
- 9.10 Monitoring and Observability
- 9.11 Complete Example: Parallel Crawler with
ProcessPoolExecutor - Summary
Chapter 10 — Asyncio: Deep Dive
- 10.1 The Concurrency Model
- 10.2 Coroutines, Tasks, and the Event Loop
- 10.3
gather,wait, andas_completed - 10.4 Cancellation
- 10.5 Synchronisation Primitives
- 10.6
run_in_executor— Bridging Sync and Async - 10.7 Event Loop Internals
- 10.8 Structured Concurrency (Python 3.11+
TaskGroup) - 10.9
asyncioPatterns - 10.10 Mixing
asynciowith Threads - 10.11 Error Handling and Debugging
- 10.12
asyncioandaiohttp— HTTP Client Pattern - Summary
Chapter 11 — Multiprocessing
- 11.1 When Multiprocessing Is the Right Tool
- 11.2 Start Methods
- 11.3
Process— Individual Processes - 11.4
Pool— Worker Process Pools - 11.5 Inter-Process Communication
- 11.6
multiprocessing.shared_memory— Zero-Copy Shared Data - 11.7
mp.Manager— Managed Shared Objects - 11.8 Synchronisation Across Processes
- 11.9
ProcessPoolExecutorvsmp.Pool - 11.10 Pickling Deep Dive
- 11.11 Common Failure Modes
- 11.12 Complete Example: Parallel Document Processor
- Summary
Chapter 12 — Designing Pythonic APIs
- 12.1 What Makes an API Pythonic
- 12.2 Function Signatures
- 12.3 Return Types
- 12.4 Lazy vs Eager APIs
- 12.5 Context Managers as API
- 12.6 Error Handling in APIs
- 12.7 Naming and Conventions
- 12.8 Versioning and Backward Compatibility
- 12.9 Configuration and Dependency Injection
- 12.10 Operator Overloading
- 12.11 Introspection and
__repr__ - 12.12 Complete Example: A Pythonic HTTP Client API
- Summary
Chapter 13 — Object-Oriented Design & Patterns
- 13.1 Design Patterns in a Python Context
- 13.2 SOLID Principles in Python
- 13.3 Creational Patterns
- 13.4 Structural Patterns
- 13.5 Behavioural Patterns
- 13.6 Composition vs Inheritance
- 13.7 Complete Example: A Plugin-Based Processing System
- Summary
Chapter 14 — Designing for Change & Extension
- 14.1 The Core Problem
- 14.2 Identifying and Isolating Change Axes
- 14.3 Extension Points
- 14.4 Configuration Management
- 14.5 Feature Flags
- 14.6 Dependency Management and Import Discipline
- 14.7 Versioning API Contracts
- 14.8 Module and Package Structure
- 14.9 Testing as a Design Signal
- 14.10 Backward Compatibility Checklist
- 14.11 Complete Example: Extensible Middleware System
- Summary
Chapter 15 — Packaging & Distribution
- 15.1 Why Packaging Matters at Staff Level
- 15.2 The Modern Python Package Ecosystem
- 15.3
pyproject.toml— The Complete Reference - 15.4 Version Management
- 15.5 Dependency Specification
- 15.6 Project Layout
- 15.7 Entry Points
- 15.8 Distribution Formats
- 15.9 Type Information Distribution (PEP 561)
- 15.10 Virtual Environments and Isolation
- 15.11 CI/CD Packaging Pipeline
- 15.12 CLI Design
- 15.13 Reproducible Builds and Supply Chain Security
- 15.14 Internal Packages and Private Registries
- 15.15 Complete
pyproject.tomlReference - Summary
Chapter 16 — Performance Engineering
- 16.1 The Performance Engineering Mindset
- 16.2 Understanding Python’s Performance Characteristics
- 16.3 Profiling Tools
- 16.4 Common Bottlenecks and Their Fixes
- 16.5 Data Structure Performance
- 16.6 Caching Strategies
- 16.7 Algorithmic Complexity
- 16.8 Python-Specific Optimisation Techniques
- 16.9 Concurrency as a Performance Tool
- 16.10 Cython, Numba, and C Extensions
- 16.11 Benchmarking Best Practices
- 16.12 Complete Example: Profiling and Optimising a URL Processor
- Summary
Chapter 17 — Debugging Under Pressure
- 17.1 The Debugging Mindset
- 17.2 Reading Tracebacks
- 17.3
pdb— The Python Debugger - 17.4
logging— Structured Observability - 17.5
sys._current_frames()and Stack Inspection - 17.6
faulthandler— Segfault and Signal Debugging - 17.7 Debugging Concurrency Bugs
- 17.8
inspectModule — Runtime Introspection - 17.9
disModule — Bytecode Inspection for Debugging - 17.10 Remote Debugging and Production Diagnostics
- 17.11 Binary Search Debugging
- 17.12 Debugging Checklist
- 17.13 Complete Example: Debugging a Production Race Condition
- Summary
Chapter 18 — Failure Mode Thinking & Resilience Patterns
- 18.1 The Failure Mode Mindset
- 18.2 Timeout Everywhere
- 18.3 Retry with Exponential Backoff and Jitter
- 18.4 Circuit Breaker
- 18.5 Rate Limiting
- 18.6 Bulkhead Pattern
- 18.7 Graceful Degradation
- 18.8 Load Shedding
- 18.9 Backpressure
- 18.10 Graceful Shutdown
- 18.11 Health Checks
- 18.12 Failure Mode Analysis: The Web Crawler
- 18.13 Complete Example: Resilient HTTP Client
- Summary
- Part V — Production-Grade Engineering
Chapter 19 — Security Awareness
- 19.1 Security as a Design Property
- 19.2 Injection Vulnerabilities
- 19.3
pickle— Arbitrary Code Execution - 19.4 Path Traversal
- 19.5 Server-Side Request Forgery (SSRF)
- 19.6 Secrets Management
- 19.7 Input Validation
- 19.8 Cryptography
- 19.9 Dependency Security
- 19.10 Web Security
- 19.11 Logging Security
- 19.12 Security Checklist
- 19.13 Complete Example: Secure Web Crawler Configuration
- Summary
Chapter 20 — Observability & Monitoring
- 20.1 The Three Pillars of Observability
- 20.2 Structured Logging
- 20.3 Metrics
- 20.4 Distributed Tracing
- 20.5 Health Checks and Readiness Probes
- 20.6 Alerting
- 20.7 SLIs, SLOs, and Error Budgets
- 20.8
structlog— Production Structured Logging - 20.9 Runbooks and On-Call Readiness
- 20.10 Complete Example: Fully Observable Crawler
- Summary
Chapter 21 — Reliability Concepts & Distributed Patterns
- 21.1 From Single-Process to Distributed Systems
- 21.2 The CAP Theorem and Its Practical Meaning
- 21.3 Consistency Models
- 21.4 Distributed Transactions
- 21.5 Consistent Hashing
- 21.6 Message Queues and Event-Driven Architecture
- 21.7 Leader Election
- 21.8 Service Discovery and Configuration
- 21.9 Horizontal Scaling Patterns
- 21.10 Data Replication and Read Scaling
- 21.11 Distributed Rate Limiting
- 21.12 The Twelve-Factor App
- 21.13 Complete Example: Distributed Crawler Architecture
- Summary