Sign inGet started
← Back to all guides

Importing function from another notebook

By Filip Žitný

Updated on March 6, 2024

In this guide, We will walk you through two methods to achieve this: using a package to import directly from a notebook, and saving your functions to a Python file and importing them as a module.

Importing from a Python file

The most straightforward and recommended method is to save your functions in a Python file (.py) and then import them into your notebooks. Here’s how to do it:

def greetFromAnotherFile(name):
    return f"Sup, {name} from another file!"

Notebook 1

import sys
import importlib # !pip install importlib
import another_file


Importing from another notebook


def greetFromAnotherNotebook(name):
    return f"Hello, {name} from another notebook!"

After writing a function or anything else that you would want to use in another notebook you will need to export the Deepnote Notebook into .ipynb file and than drag and drop it into files.

Screenshot 2024-07-01 at 11.22.43.png

Screenshot 2024-07-01 at 11.26.08.png

Notebook 1

import ipynb
%run imported_another_notebook.ipynb

Example project structure

├── Notebook 1
├── another_notebook

├── work/
		├── requirements.txt
		├── imported_another_notebook.ipynb #after exporting
		└── .deepnote


For the showcase, I created an example notebook where you can try it yourself and an example app for view.


Deepnote offers flexibility in how you can structure and reuse code within your projects. Whether you prefer to save functions in a Python file or import them directly from other notebooks using nbimporter, you can keep your code organized and maintainable. If you encounter further issues, feel free to contact our support for assistance. Happy coding in Deepnote!

This guide should help you efficiently import functions from other notebooks or Python files in Deepnote, making your workflow smoother and more productive. If you encounter any issues, please get in touch with our support. Happy hacking in Deepnote! 🐍

Filip Žitný

Data Scientist

Follow Filip on Twitter, LinkedIn and GitHub

That’s it, time to try Deepnote

Get started – it’s free
Book a demo



  • Integrations
  • Pricing
  • Documentation
  • Changelog
  • Security




  • Privacy
  • Terms

© Deepnote