Libify: Import Databricks Notebooks as Libraries/Modules

0.78 · maintenance · verified Thu Apr 16

Libify (version 0.78) is a Python library designed to simplify the process of importing Databricks notebooks as modules. It enables nesting of notebook imports for complex workflows and supports Databricks Runtime Version 5.5 and above. The library was last released in September 2020, indicating an infrequent release cadence and a focus on maintaining existing functionality rather than active development.

Common errors

Warnings

Install

Imports

Quickstart

To use Libify, you need two types of notebooks: an 'importee' (the one providing functions) and an 'importer' (the one consuming them). The 'importee' notebook must end with a specific `libify.exporter` call to make its global scope available. The 'importer' notebook then uses `libify.importer` to load the target notebook as a module, allowing access to its defined functions and variables using dot notation.

# --- In the notebook to be imported (e.g., '/Users/my_user/my_functions') ---
# This cell must be the LAST cell in the notebook and contain ONLY this code.
def greet(name):
    return f"Hello, {name} from imported notebook!"

def add(a, b):
    return a + b

import libify
libify.exporter(globals())

# --- In the importing notebook (e.g., '/Users/my_user/main_workflow') ---
import libify

# The path should be relative to the Databricks workspace root or absolute DBFS path
my_module = libify.importer(globals(), '/Users/my_user/my_functions')

# Now you can access functions/variables defined in 'my_functions' notebook
message = my_module.greet("World")
print(message)

result = my_module.add(5, 3)
print(f"The sum is: {result}")

# Expected output in the importing notebook:
# Hello, World from imported notebook!
# The sum is: 8

view raw JSON →