Hooking into the import system
summary
Explains a concrete import-hook system used at Bloomberg that blocks imports like socket via a custom finder, loads modules from a database with a finder+loader pair that execs code into module.__dict__, and supports immediate deployment by writing to sqlite3 (demo uses an in‑memory DB). Claims the loader+finder is ~about 30 lines of Python, registers in sys.meta_path, and returns the expected ModuleNotFoundError when absent. The demo runs and shows function calls returning correct values and fast availability.
AI-written summary · about
chapters (6)
- 0:00Introduction
- 1:22Python import system
- 5:32Tracing finder example
- 7:24Implementing a block list
- 11:00Loading from a database
- 19:17Database loader demo
related talks
30mImporting Without "import": Behind the Scenes of importlib
26mWhat happens behind execution of an `import` statement?
21mHacking the Python Import System
45mWhat happens when you import a module?
28mImport Deep Dive
32mfrom hat import rabbit: Hacking your way through Python's import machinery for fun and profit
29m"from where?!? import what?!?"
26mModules 101: how to avoid spaghetti, big balls of mud and houses of straw!
