Hacking the Python Import System
summary
Explains how Python resolves imports by implementing sys.meta_path finders and loader objects with create_module and exec_module, and shows exactly which sys.path entries Python iterates. Demonstrates a working proxy loader that redirects imports of a Linux‑only package to a remote server via an RPC proxy, and a proof‑of‑concept that asks OpenAI to synthesize missing modules (OpenAI-generated modules). Demos run but the AI generator is inconsistent and unsafe for production; the loader approach reliably replaces platform‑restricted packages.
AI-written summary · about
chapters (10)
- 0:00Introduction to Python imports
- 1:14How Python import system works
- 3:02Role of finder and loader objects
- 5:36Built-in finders in Python
- 8:08PYTHONPATH and sys.path
- 11:25Extending the import system
- 11:45Remote module proxy example
- 14:44AI-generated modules demo
- 16:38Live demo of AI import
- 19:44Important warnings and resources
related talks
26mWhat happens behind execution of an `import` statement?
45mWhat happens when you import a module?
30mImporting Without "import": Behind the Scenes of importlib
29m"from where?!? import what?!?"
23mHooking into the import system
28mImport Deep Dive
32mfrom hat import rabbit: Hacking your way through Python's import machinery for fun and profit
21mUnderstanding the Magic of Python Modules and Packages
