Importing Without "import": Behind the Scenes of importlib - Bryce Beagle

Опубликовано: 25 Март 2026
на канале: Python Italia
276
9

Importing Without "import": Behind the Scenes of importlib - Bryce Beagle - PyCon Italia 2024

Elevator Pitch:
You've typed `import x` or `from y import z` in your Python programs countless times. But you probably don't know what really goes on behind the scenes. When are import statements actually evaluated? How does Python know where to find packages? What does importing a package even do at runtime?

Description:
The import system of Python is frequently used, but seldom fully understood. It's a black box of mysterious behavior‒symbols magically become available in your file, but how? This talk will go over the inner workings of `importlib`, the internal library responsible for all things importing.

You may be familiar with `sys.path` or even the `site-packages` directory, but have you heard of `finder`s, `loader`s, or `spec`s? We'll also discuss the `__import__` builtin, how to import packages without using the import statement, package and module lookup, caching, and more.

This talk will be a fast-paced crash course/demo as we tinker with the internals of the import process. We'll have a little fun along the way by messing with the internal library to break things in strange ways. We'll also do the dumb thing of building PyO3 bindings for a Rust library _at import time_, just to show that we can.

This talk is targeted towards an intermediate to advanced audience. An understanding of how to (normally) import packages is required, and being knowledgeable of system packages such as `sys` is beneficial. After this talk listeners should come away with a deeper understanding of what the language is doing every time the import statement is used.


Learn more: https://2024.pycon.it/event/importing...

#APIs #Packaging #CompilerandInterpreters