Import Deep Dive
summary
Explains exactly what import does: Python checks sys.modules cache, constructs a module spec describing loader and origin, creates an empty module object, inserts it into the cache, then executes code (or loads bytecode/C extensions/frozen modules). Covers surprising behaviors: import cycles yield half-initialized modules, zip and URL importers, and pyc cache semantics; contrasts built-in versus extension versus source modules and shows how import hooks and meta_path path_hooks decide which loader wins. Includes practical rules to avoid breakage.
AI-written summary · about
chapters (8)
- 0:00Intro
- 0:59Import
- 2:59Import Algorithm
- 5:30Loading
- 13:51Modules
- 15:30Loading Modules
- 22:06Questions
- 24:16Time to Bits
related talks
45mWhat happens when you import a module?
30mImporting Without "import": Behind the Scenes of importlib
26mWhat happens behind execution of an `import` statement?
29m"from where?!? import what?!?"
21mHacking the Python Import System
26mModules 101: how to avoid spaghetti, big balls of mud and houses of straw!
23mHooking into the import system
23mEverything is a Python module
