Forum Discussion

Thomas_R's avatar
Thomas_R
Frequent Visitor
2 years ago

Import (function) notebook into own nootbook

Hi all

 

Is there any way to import one nootbook into another and at the same time have easy version control?

 

My purpos is to have a function-nootbook I can create a lot of usefull functions (and if you have some good scripts you want to share, feel free to also post a link to those ๐Ÿ˜‰ ). I want to import that function-nootbook into all my other noethooks.

 

The only way I've found wich works, is to upload a Wheels notebook into "Custom Libraries". In this way, there are a step to make sure to upload the notebook each time, insted of just saving it in the workspace, and have the build-in version control

 

Hope you can help

/Thomas

9 Replies

  • We do this all the time.

     

    We have a notebook called common_functions in which we can use in the parent notebook.

     

    You will have to call the functions notebook this way in order to have the functions/variables in the session memory:     %run common_functions

     

    If you run the child notebook this way, it will create a new session and you can't reference the child notebook functions in the parent notebook:  mssparkutils.notebook.run("notebook", params)

    • Nashrin's avatar
      Nashrin
      Frequent Visitor

      Hi,

      I have a specific use case where I need a DataFrame in return after running the parent notebook. Is ther any suggested way to handle this type of scenarios.

  • v-cboorla-msft's avatar
    v-cboorla-msft
    Microsoft Employee

    Hi Thomas_R 

     

    Thanks for uisng Microsoft Fabric Community.

     

    You're right, importing one notebook into another in Fabric with built-in version control isn't straightforward. One of the best approach is using Custom Libraries with Wheels.

    Custom Libraries with Wheels:

    • Pros:
      • Works for importing functions across notebooks.
      • Provides version control through custom library versions.
    • Cons:
      • Requires manually uploading the updated notebook to create new versions.
      • Can be cumbersome if you update functions frequently.

    Meanwhile we will reach out to the internal team to check for any other alternative approaches.

    We will update you once we hear back from them.

     

    Thanks

     

    • v-cboorla-msft's avatar
      v-cboorla-msft
      Microsoft Employee

      Hi Thomas_R 


      We havenโ€™t heard from you on the last response and was just checking back to see if you have a resolution yet.
      In case if you have any resolution please do share that same with the community as it can be helpful to others.
      Otherwise, will respond back with the more details and we will try to help.


      Thanks

    • Thomas_R's avatar
      Thomas_R
      Frequent Visitor

      Thanks for the clarification. If there are a better way layer on, please let me know ๐Ÿ™‚

  • Thomas_R's avatar
    Thomas_R
    Frequent Visitor

    Still waiting for you to get back to me for other possible soultuoins ๐Ÿ™‚

    • v-cboorla-msft's avatar
      v-cboorla-msft
      Microsoft Employee

      Hi Thomas_R 

       

      Apologies for the delay in response.

      The other alternative possible solution is Notebook Resources (Alternative approach) but the recommended possible solution is Custom Libraries with Wheels (Recommended Approach).

      Notebook Resources:

      Pros:

      • Simple setup: Just place the function notebook in a designated folder for import.
      • Function context: Functions stay close to the main notebook for easier reference.

      Cons:

      • No explicit version control: Changes in the function notebook impact all notebooks using it.
      • Limited scope: Not ideal for functions used across different projects or workspaces.

      Recommendation:

      • Choose Custom Libraries with Wheels if:
        • You need strict version control for your functions.
        • You have a large set of reusable functions.
        • You want to share functions across different projects or workspaces.
      • Choose Notebook Resources if:
        • You want a quick and easy setup for function import.
        • Your functions are tightly coupled with the main notebook.
        • You don't need explicit version control or extensive function reusability.

      Ultimately, the best approach depends on your specific workflow and how you prioritize version control, modularity, and ease of use.

       

      I hope this information helps. Please do let us know if you have any further questions.

       

      Thanks

      • v-cboorla-msft's avatar
        v-cboorla-msft
        Microsoft Employee

        Hi Thomas_R 


        We havenโ€™t heard from you on the last response and was just checking back to see if you have a resolution yet.
        In case if you have any resolution please do share that same with the community as it can be helpful to others.
        Otherwise, will respond back with the more details and we will try to help.


        Thanks