cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Find root path to Repo for .py file import

MetaRossiVinli
Contributor

I want to import a Python function stored in the following file path:

`<repo>/lib/lib_helpers.py`

I want to import the function from any file in my repo. For instance from these:

`<repo>/notebooks/etl/bronze/dlt_bronze_elt`

`<repo>/workers/job_worker`

It is possible to get the root path of the repo? This way people on my team can clone the repo but the paths will still work. I think I want the import code to look something like this:

repo_root = <<call to get the root of the Databricks Repo>>
sys.path.append(os.path.abspath(f'{repo_root}/lib/'))
from lib_helpers import helper_func

I am still new to Databricks. Does dbutils or another util help with this?

1 ACCEPTED SOLUTION

Accepted Solutions

MetaRossiVinli
Contributor

Ok, I figured it out. If you just make it a Python module by adding an empty 

`__init__.py`, Databricks will load it on start. Then, you can just import it.

View solution in original post

1 REPLY 1

MetaRossiVinli
Contributor

Ok, I figured it out. If you just make it a Python module by adding an empty 

`__init__.py`, Databricks will load it on start. Then, you can just import it.

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!