Contribute Media
A thank you to everyone who makes this possible: Read More

Import Deep Dive


Petr Viktorin - Import Deep Dive [EuroPython 2015] [24 July 2015] [Bilbao, Euskadi, Spain]

Whatever you need to do with Python, you can probably import a library for it. But what exactly happens when you use that import statement? How does a source file that you've installed or written become a Python module object, providing functions or classes for you to play with?

While the import mechanism is relatively well-documented in the reference and dozens of PEPs, sometimes even Python veterans are caught by surprise. And some details are little-known: did you know you can import from zip archives? Write CPython modules in C, or even a dialect of Lisp? Or import from URLs (which might not be a good idea)?

This talk explains exactly what can happen when you use the import statement – from the mundane machinery of searching PYTHONPATH through subtle details of packages and import loops, to deep internals of custom importers and C extension loading.


Improve this page