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:
- Visual Studio Code is installed on your machine.
- VS Code extensions
- An active Microsoft Fabric account
- Python 3.11 version
Creating a Fabric user data functions item
Open Visual Studio Code and select the new item button in Fabric Workspace explorer.

Provide the following details to complete creation of the user data functions item:
- Create a name for user data functions item.
- Select the language (currently Python only).
- 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.

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.

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

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.

Manage existing user data functions in VS Code
- Select the user data function and choose ‘Open in Explorer’ to open the UDF project locally.

- For user data functions items, you can configure required libraries and data connections.

- Start adding a function from a sample code snippet.

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.