Member-only story

What You Need To Know About Import System — Python

How It Works From Finding To Loading Your Module

Yanick Andrade
4 min readSep 23, 2024
Photo by Matt Ridley on Unsplash

Not a member yet? Read it for free here.

I never stopped to think about how the import system in Python or any other programming language works until recently when I was writing about circular import errors.

Like most things that can appear simple at a high level, once you dive into the subject, you’ll see there’s much more to discover.

Understanding how the Python import system works can improve your code’s performance and save you from unexpected problems like those mentioned above.

In Python, there are three ways of importing a module: 1) using the import statement, 2) using the importlib library, and 3) using the dunder method __import__.

Before we delve into the import system, we first need to understand how Python treats packages and modules.

Packages and Modules in Python

--

--

Yanick Andrade
Yanick Andrade

Written by Yanick Andrade

As a Software Engineer I’m always trying to learn new things and keep growing. That’s why I started writing articles.

No responses yet