Skip to main content

Command Palette

Search for a command to run...

How to Search For Specific Words In All Fabric Notebooks In A Workspace

Search across all notebooks for specific words or code

Updated
S

Principal Program Manager, Microsoft Fabric CAT helping users and organizations build scalable, insightful, secure solutions. Blogs, opinions are my own and do not represent my employer.

My personal Fabric trial tenant is a mess. I create items, test them and donโ€™t name them properly. For example, I have a workspace with 226 notebooks named Notebook 1 , Notebook 2 etc ๐Ÿ™„ I am sure I am not alone of this crime. I needed to find a notebook I created a few months ago that contained a specific code logic. Fabric global search only searches for item names and not item content. So here is what I came up with:

import sempy.fabric as fabric 
import json

def extract_notebook_cells(notebook_name, workspace):

    return [{'cell_type': cell.get('cell_type'), 'source': ''.join(cell.get('source', '')).replace('\n', ' ')} 
            for cell in json.loads(notebookutils.notebook.getDefinition(notebook_name, workspaceId=workspace)).get('cells', [])]

def search_notebooks(word, workspace=None):
    if workspace is None: #workspace id of the notebook if not given
        workspace = fabric.get_notebook_workspace_id() 
    else:
        workspace = fabric.resolve_workspace_id(workspace) #get workspace id

    notebooks = [nb['displayName'] for nb in notebookutils.notebook.list(workspace)]
    matching_notebooks = []
    print(f"Workspace: {fabric.resolve_workspace_name(workspace)}")
    for notebook_name in notebooks:
        try:
            cells = extract_notebook_cells(notebook_name=notebook_name, workspace=workspace)
            if any(word.lower() in str(cell['source']).lower() for cell in cells):
                matching_notebooks.append(notebook_name)
        except Exception as e:
            print(f"Error {notebook_name}: {str(e)}")

    return matching_notebooks

search_notebooks("Cache")

Logic:

  • Get a list of notebooks in a workspace

  • For each notebook, get the definition, strip everything and get only cell/markdown blocks

  • Search for the keyword

  • Depending on the number of notebooks and notebook content, this can take a while. You can certainly speed it up with some optimization but this is sufficient for me. You can also use your own regex pattern for more advanced search.

UPDATE : Aug 26, 2025

Semantic Link Labs v0.11.3 now has a search_notebooks function to search a keyword in a single notebook or all notebooks in a list of workspaces.