Microsoft Fabric Updates Blog

Fabric Changing the game: Using your own library with Microsoft Fabric

Unlock the Power of Reusing Your Library in the Lakehouse with This Step-by-Step Guide. Fabric provides you with different options to build your analytics solution. If you decide to use Lakehouse and code your solution with Python you may want to reuse some functions and reuse certain business logic across your code. Once your library is created and imported into Fabric you can even use the endorsement options to flag for other users to use your code. It is quite simple to create your own library with Python and even simpler to reuse it on Fabric. Let’s check the step by step:

Creating library – Why?

Library in the Python context is a set of codes pre-compiled. That code, as it was mentioned before, could be something like a business logic that you reuse across the organization. When reusing this Library in a Fabric environment, we need to package the code and import.

1 . How?

Let’s set our environment:

  1. First, install Visual Studio Code – Visual Studio Code – Code Editing. Redefined
  2. Install Python Extension – Python – Visual Studio Marketplace
  3. Add a folder to the environment that represents what you are trying to achieve. Mine is named as testpackage, as you can see in Fig 1- package_folder:
Fig 1- package_folder

Note: Commands should run at the terminal in the VS Code.

4. Define your interpreter as Fig 2- Interpreter shows:

Fig 2- Interpreter

5. Create the folder where your code will be. Mine is Math_Custom, as we will create a function that will add 2 numbers for the sake of this example. You can create this folder using the following command line at the Visual Studio Code, as Fig 3 – Mkdir shows:

Fig 3 – Mkdir

6. Let’s create a function to be reused: We will define a simple example for this library exercise. As mentioned, we will create a function called add_2. That function will add a number plus the other. Hence, to accomplish that: first, open a new file. (Menu file at the VS Code -> new File -> Python, as Fig 4-NewPy, shows.)

Fig 4-NewPy


def add_2(x,y):

  return x+y

Run the file add_2.y by clicking on run. Fig 5-Run, shows :

Fig 5-Run

7. Next, let’s create the init file of the project with the function/modules created, __Init__ defines the methods that will be called when you use your import statement to use this library. Inside of the use the following code as this example shows:


from add_2 import add_2

8. We also need a Setup File to create this package and import it to the library later. should exist outside of the math_custom folder. Therefore, create a new Python file and save it as outside the math_custom folder. This file should contain the package metadata, for example:


from setuptools import setup, find_packages




  author='Liliam Leme',



9. The structure of your folder should be something like this at this point:

testpackage ( main folder)

​ —– ( setup file)

​ ———– math_custom (Source code folder)

——————– ( function code)

——————– init file)

10. Ok. Let’s test our definitions of modules/functions and see how it goes. Create a new py file called and run the file:


import add_2

print (add_2.add_2(1,2))

Example at Fig 6 – Compile, show the execution of the module which you should be able to get by clicking in run at the Visual Studio Code:

Fig 6 – Compile

11. License\Readme files: will be a file that you can create in the source folder math_custom and it will contain information about your package as the example below:

   # Example Package

   This is a simple example package. 

As for License, quoting from (Packaging Python Projects — Python Packaging User Guide) “It’s important for every package uploaded to the Python Package Index to include a license. This tells users who install your package the terms under which they can use your package.

The structure would be something like this at this point:


├── folder_name_of_my_module

│ ├──

│ ├──

│ ├── tests\



13. The next step is to create the Distribution Package. ref: Glossary — Python Packaging User Guide. Run the following commands at the terminal in the VS Code as Fig 7-Pip shows:

   -m pip install
Fig 7-Pip

Install Wheel, Fig 8 and 9-Wheels show the following steps to create the package:

pip install wheel

Check installation

pip install check-wheel-contents

Fig 8-Wheels
Fig 9-Wheels

Note, In case you face this issue:

pip : The term ‘pip’ is not recognized as the name of a cmdlet, function, script file, or operable program.

Add a Python path to the list of variables by doing the following:


Right-click on My Computer -> System from the Control Panel, select Advanced system settings and click Environment Variables.

Click on path and edit the location of the Python path. It should be the one you use when you install, generally speaking, at:


12. Create the distribution

Your package will be “A versioned archive file that contains Python packages, modules, and other resource files that are used to distribute a Release“. Fig 10-Package shows.

The command line is: bdist_wheel

Fig 10-Package

You can check if the Distribution was created successfully at VS Code Explorer, Fig 11-Dist. exemplifies:

Fig 11-Dist.

12. Import inside of Fabric.

The easiest step of all steps. ​ The easiest step is to import into Fabric.

From Fabric, open the workspace settings by selecting the workspace first( my workspace name is NextSynapse12) -> Data Engineering -> Library management.

Fig 12-Fabric, show the step-by-step:

Ref: Workspaces – Microsoft Fabric | Microsoft Learn

Manage Apache Spark libraries – Microsoft Fabric | Microsoft Learn

From the docs:

  • Upload new custom library: You can upload your custom codes as packages to the Fabric runtime through the portal. The library management module helps you resolve potential conflicts and download dependencies in your custom libraries. To upload a package, select the Upload button under the Custom libraries panel and select a local directory.”
Fig 12-Fabric.

13. Executing

Once your library is imported into the Fabric environment you can do the following to reuse – Fig 13 – Execution, show the result:


##custom library.

from math_custom import add_2

print (add_2.add_2(1,2))
Fig 13 - Execution

14- Simple as that if you want to flag this notebook code to be reused across your organization you can use the endorsement options for Fabric, available at the items settings. Endorsement overview – Microsoft Fabric | Microsoft Learn

  • Promotion: Promotion enables users to highlight items that they think are valuable, worthwhile, and ready for others to use. It encourages the collaborative spread of content within the organization
  • Certification: Certification means that the item meets the organization’s quality standards can be regarded as reliable and authoritative, and is ready for use across the organization.
Fig 14 – Endorsement

That is, it!

Liliam – UK


Quick Start — The Hitchhiker’s Guide to Packaging 1.0 documentation (

Workspaces – Microsoft Fabric | Microsoft Learn

Manage Apache Spark libraries – Microsoft Fabric | Microsoft Learn

Endorsement overview – Microsoft Fabric | Microsoft Learn

Related blog posts

Fabric Changing the game: Using your own library with Microsoft Fabric

June 26, 2024 by Amir Jafari

We are excited to share guidance for how you can use Microsoft Fabric to turn your data into knowledge for Generative AI applications. This guide will walk you through implementing a RAG (Retrieval Augmented Generation) system in Microsoft Fabric using Azure OpenAI and Azure AI Search. By the end, you’ll be more familiar with how to … Continue reading “Building Custom AI Applications with Microsoft Fabric: Implementing Retrieval Augmented Generation for Enhanced Language Models”

June 25, 2024 by Santhosh Kumar Ravindran

We are excited to announce the Capacity Pools for Data Engineering and Data Science in Microsoft Fabric. As part of the Data Engineering and Science settings in the Admin portal, capacity administrators can create custom pools based on their workload requirements. Optimizing Cloud Spend and Managing Compute Resources In enterprise environments, managing cloud spending and … Continue reading “Introducing Capacity Pools for Data Engineering and Data Science in Microsoft Fabric”