How to import custom Python modules in the dbt models

Hi there

pipeline/
    modelling/
        model/
            schema/
                sample_model.py
        some_domain/
            filter_out.py

I trying to import filter_out.py model in the dbt model by providing the path

 **filter_out.py**

from test.filter_out import filter_out

But not able import it. But it is expecting some __init__.py

But dbt is not working properly with __init__.py

Any idea what is causing this problem. Let me know if there are any other details that would help.

Hi @Sam777,

You can define and reuse functions inside of a single model, but you can’t currently define a function in one model and reuse it in another: Python models | dbt Developer Hub

This is a work in progress - you can see the Code reuse section of that same doc discusses some different options we’re considering for the future.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.