Microsoft Fabric Updates Blog

Develop, test and deploy a user data functions in Microsoft Fabric using Visual Studio Code

Fabric User data functions is a platform that allows you to host and run serverless functions on Fabric. This empowers data developers to write custom logic and embed it into their Fabric ecosystem. This feature supports the Python 3.11.9 runtime and allows you to use public libraries from PyPI. In this blog post, we will walk through the process of creating, testing, and deploying a Fabric user data functions item using Visual Studio Code locally.

Prerequisites

Before you begin, ensure you have the following:

Creating a Fabric user data functions item

Open Visual Studio Code and select the new item button in Fabric Workspace explorer.

Create a user data functions item

Provide the following details to complete creation of the user data functions item:

  1. Create a name for user data functions item.
  2. Select the language (currently Python only).
  3. Choose whether to open the new project in the current window or a new window.

User data functions project will open on your local machine. You will be prompted to set a Python virtual environment to debug and test locally. Continue through the next steps to set this up.

Create virtual environment for user data functions item
Create virtual environment for user data functions item project

Now you are ready to start adding your own functions function_app.py.

Add functions to user data functions item

Imagine a scenario where you want to use validation functions that you can use in your notebooks such as validate email, phone, date for customer order data that needs to be validated before being written to a database. 

Here are three such functions:

  • is_valid_email to validate if the string is a valid email address.
  • is_valid_phone to validate if the phone value passed to the function is in desired format.
  • is_valid_datetime to validate if the date string is in the desired format.

Replace functions_app.py with the following code:  

import fabric.functions as fn
import logging

udf = fn.UserDataFunctions()

import re
from datetime import datetime

"""Validate an email address."""
@udf.function()
def is_valid_email(email: str) -> bool:
    pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
    logging.info(f'validating the email address {email}.')
    return re.match(pattern, email) is not None

"""Validate a phone number (basic international & local format)."""
@udf.function()
def is_valid_phone(phone: str) -> bool:
    pattern = r'^\+?[\d\s\-().]{7,15}$'
    logging.info(f'validating the phone number {phone}.')
    return re.match(pattern, phone) is not None

"""Validate a datetime string against a format."""
@udf.function()
def is_valid_datetime(datestring: str ) -> bool:    
    try:
        dateformat = "%Y-%m-%d %H:%M:%S"
        logging.info(f'validating the date {datestring}.')
        datetime.strptime(datestring, dateformat)
        return True
    except ValueError:
        return False

IMPORTANT NOTE

  • Every function withing a user data functions needs to have udf.function() decorator to identify this as fabric user data function that can be invoked.
  • There are specific input types and output types supported. Please refer to the programming model documentation.

Local debugging a function

You can open Fabric explorer in the local folder and see the User data function item you are editing and reflect all your local changes. You can view all the functions listed for this item. Select Run and debug to start debugging or press F5.  

Select Run and debug to test a function
Select Run and debug to test a function

Run and debug page will allow you to test any function within this item. Example of testing the is_valid_email() function.

Test your local function changes
Test your local function changes

Deploying your functions to Fabric

In the local folder, select the user data function item. Click on publish to initiate deploying your changes to the workspace this function belongs to.

Publish your changes to fabric
Publish your changes to fabric

Manage existing user data functions in VS Code

  • Select the user data function and choose ‘Open in Explorer’ to open the UDF project locally.
Open a user data functions item locally
  • For user data functions items, you can configure required libraries and data connections.
Manage connections and libraries for a user data functions item
Manage connections and libraries for a user data functions item
  • Start adding a function from a sample code snippet.
Insert sample code snippet for new function
Insert sample code snippet for a new function

Conclusion

By following these steps, you will have successfully developed, debugged, and deployed a user data function to Microsoft Fabric. This is a simple validation example, but you can do more with User data functions and VS Code provides a local development experiences to develop and test these functions before making them ready for production use. Feel free to request features or report issues on VS Code fabric extension issues. Submit your feedback on Fabric Ideas and join the conversation on the Fabric Community.

Related blog posts

Develop, test and deploy a user data functions in Microsoft Fabric using Visual Studio Code

May 22, 2025 by Eren Orbey

With AI-powered capabilities in Data Wrangler, you can now do even more to accelerate exploratory analysis and data preparation in Fabric.

May 19, 2025 by Santhosh Kumar Ravindran

The Fabric Spark Native Execution Engine (NEE) is now generally available (GA) as part of Fabric Runtime 1.3. This C++-based vectorized engine (built on Apache Gluten and Velox) runs Spark workloads directly on the lakehouse, requiring no code changes or new libraries. It supports Spark 3.5 APIs and both Parquet and Delta Lake formats, so … Continue reading “Microsoft Fabric Spark: Native Execution Engine now generally available”