Importing custom Python code

When you’re writing code in Mage, you can import any other Python files using this format:

from [project_name].foo import bar

For example, if your project name is demo_project and you have the following folder structure:

demo_project/
|   pipelines/
|   utils/
|   |   helpers/
|   |   |   shared.py
|   |   |   __init__.py
|   |   __init__.py

You can write the following import statement to use functions in the demo_project/utils/helpers/shared.py file:

from demo_project.utils.helpers import shared