~/talk

Importing Without "import": Behind the Scenes of importlib

Talkat PyCon Italia 2024 · 2024-05-22..05-25· [python, compilers-and-language-design]
links:none on file
slides:none on file

Covers exact import machinery: modules are plain module objects cached in sys.modules, import calls run finders that return ModuleSpec objects and loaders that exec or load binaries, and binding to names is the keyword’s job not the import builtin. Demonstrates using sys.meta_path and path_hooks to register a custom zipimport finder, a GitHub downloader, and even a hook that runs cargo to build Rust at import time and successfully load the compiled extension, while warning this is slow and unsafe for production and reloads need careful cache invalidation.

AI-written summary · about

  1. 0:00Introduction
  2. 0:32Understanding modules
  3. 4:26The import process
  4. 10:03Namespace binding
  5. 11:38Search paths and hooks
  6. 14:43Basic import examples
  7. 16:16Zip file imports
  8. 17:09GitHub repository imports
  9. 20:43Rust and dynamic building
  10. 22:43Q&A and conclusion
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.