<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Notebooks on Hat Full of Data</title><link>https://hatfullofdata.blog/categories/notebooks/</link><description>Recent content in Notebooks on Hat Full of Data</description><generator>Hugo -- gohugo.io</generator><language>en-gb</language><lastBuildDate>Mon, 12 Jan 2026 10:51:34 +0000</lastBuildDate><atom:link href="https://hatfullofdata.blog/categories/notebooks/index.xml" rel="self" type="application/rss+xml"/><item><title>Accessing a Variable Library in a Notebook</title><link>https://hatfullofdata.blog/accessing-a-variable-library-in-a-notebook/</link><pubDate>Mon, 12 Jan 2026 09:34:51 +0000</pubDate><guid>https://hatfullofdata.blog/accessing-a-variable-library-in-a-notebook/</guid><description>&lt;img src="https://hatfullofdata.blog/accessing-a-variable-library-in-a-notebook/cover.png" alt="Featured image of post Accessing a Variable Library in a Notebook" /&gt;&lt;p&gt;This post walks through how to access a variable library in a notebook in Microsoft Fabric. I recommend a Microsoft Fabric project starts by creating a variable library to store the common values different artifacts need and could be changed if a deployment pipeline gets involved. So when we create a notebook we need to be able to use these variables. This means we need load the variable library in a notebook and then get the variable values.&lt;/p&gt;
&lt;h2&gt;Variable Library Series&lt;/h2&gt;
&lt;p&gt;Variable libraries should be part of every project. This post is part of my series to help get you started creating the library and then using the variables and finally seeing your hard work pay back when it comes to deployment pipelines.&lt;/p&gt;
&lt;ol&gt;
 &lt;li&gt;&lt;a href="https://hatfullofdata.blog/variable-library/"&gt;Getting started with variable libraries&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;strong&gt;Variable Values in a Fabric Notebook&lt;/strong&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href="https://hatfullofdata.blog/using-a-variable-library-in-a-data-pipeline/"&gt;Variable Values in a Data Pipeline&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href="https://hatfullofdata.blog/using-a-variable-library-in-lakehouse-shortcuts/"&gt;Variable Values in Lakehouse Shortcuts&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href="https://hatfullofdata.blog/using-variable-library-in-a-dataflow/"&gt;Variable Values in Dataflows&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=""&gt;Variable Libraries in Deployment Pipelines&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="connect-to-library"&gt;Connect to Library
&lt;/h2&gt;&lt;p&gt;The first task is to create a variable for the variable library. The notebookutils package includes the functions we need to do this easily. In the code below the variable vl will refer to the variable library that is called “Finance Variables”. This code assumes the notebook is in the same workspace as the library.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-xml" data-lang="xml"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;# Get the Variable library
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;vl = notebookutils.variableLibrary.getLibrary(&amp;#34;Finance Variables&amp;#34;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;h2 id="get-variable-value"&gt;Get Variable Value
&lt;/h2&gt;&lt;p&gt;Once we have the variable library loaded, we can access the variable values in one of two syntaxes.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-xml" data-lang="xml"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;# 2 syntaxes to get variable value
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;SP_URL = vl.getVariable(&amp;#34;SharePoint_URL&amp;#34;)
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;Limit = vl.Limit
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Combining both of the two and adding some print statements we can demo the above using this code.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt; 1
&lt;/span&gt;&lt;span class="lnt"&gt; 2
&lt;/span&gt;&lt;span class="lnt"&gt; 3
&lt;/span&gt;&lt;span class="lnt"&gt; 4
&lt;/span&gt;&lt;span class="lnt"&gt; 5
&lt;/span&gt;&lt;span class="lnt"&gt; 6
&lt;/span&gt;&lt;span class="lnt"&gt; 7
&lt;/span&gt;&lt;span class="lnt"&gt; 8
&lt;/span&gt;&lt;span class="lnt"&gt; 9
&lt;/span&gt;&lt;span class="lnt"&gt;10
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-xml" data-lang="xml"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;# Get the Variable library
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;vl = notebookutils.variableLibrary.getLibrary(&amp;#34;Finance Variables&amp;#34;)
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;# 2 syntaxes to get variable value
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;SP_URL = vl.getVariable(&amp;#34;SharePoint_URL&amp;#34;)
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;Limit = vl.Limit
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;# Check results
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;print(f&amp;#34;{SP_URL=}&amp;#34;)
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;print(f&amp;#34;{Limit=}&amp;#34;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;And here is the run&lt;/p&gt;
&lt;p&gt;&lt;img alt="Screen shot of the code loading variable library in a notebook and the results after it ran." class="gallery-image" data-flex-basis="576px" data-flex-grow="240" height="283" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://hatfullofdata.blog/accessing-a-variable-library-in-a-notebook/image-3.png" width="680"&gt;&lt;/p&gt;
&lt;h2 id="get-a-variable-value-by-reference"&gt;Get a variable value by reference
&lt;/h2&gt;&lt;p&gt;There is a third way to get a variable value. The get method from notebookutils variable library uses a reference string that follows the following syntax:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-xml" data-lang="xml"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&amp;#34;$(/**/&lt;span class="nt"&gt;&amp;lt;LIBRARY&lt;/span&gt; &lt;span class="err"&gt;NAME&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;/&lt;span class="nt"&gt;&amp;lt;VARIABLE&lt;/span&gt; &lt;span class="err"&gt;NAME&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;)&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Before you get excited that the ** implies you could refer to another workspace, sorry that is not supported. This string is used in the variableLibrary.get action in notebookutils. For example to get the two values from before could be done like this&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-xml" data-lang="xml"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;# Get the variable values directly
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;SP_URL = notebookutils.variableLibrary.get(&amp;#34;$(/**/Finance Variables/SharePoint_URL)&amp;#34;)
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;Limit = notebookutils.variableLibrary.get(&amp;#34;$(/**/Finance Variables/Limit)&amp;#34;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;And here is the run&lt;/p&gt;
&lt;p&gt;&lt;img alt="Screen shot of the code loading variable library in a notebook using references and the results after it ran." class="gallery-image" data-flex-basis="788px" data-flex-grow="328" height="207" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://hatfullofdata.blog/accessing-a-variable-library-in-a-notebook/image-4.png" width="680"&gt;&lt;/p&gt;
&lt;blockquote class="alert alert-tip"&gt;
 &lt;div class="alert-header"&gt;
 &lt;span class="alert-icon"&gt;💡&lt;/span&gt;
 &lt;span class="alert-title"&gt;Tip&lt;/span&gt;
 &lt;/div&gt;
 &lt;div class="alert-body"&gt;
 &lt;p&gt;The print(f&amp;quot;{Limit=}&amp;quot;) prints Limit=4 for us newbies to Python!&lt;/p&gt;
 &lt;/div&gt;
 &lt;/blockquote&gt;
&lt;h2 id="naming-conventions"&gt;Naming Conventions
&lt;/h2&gt;&lt;p&gt;When you start and there are only 4 variables in the library its easy to remember the names to type in by hand when you are using a variable library in a notebook. When it gets to 20 names, its harder. So create standards, whats the case pattern, you using _ between words or not? Pick a set of rules and stick with it, BronzeWorkspaceID works just as well as Bronze_Workspace_ID, WorkspaceID1 and workspace_id2 are a technical debt you don’t need.&lt;/p&gt;
&lt;h2 id="conclusion-on-using-variable-library-in-a-notebook"&gt;Conclusion on using Variable Library in a Notebook
&lt;/h2&gt;&lt;p&gt;I’m really impressed on how easy it is to use the variable library in a notebook. The pattern is simple and resusable. If I had a magic wand it it would be great is the intellisense knew the variable names from loading the variable library object.&lt;/p&gt;
&lt;p&gt;The method by reference is great if you want to dynamically select which variable to load as the string could be dynamically built.&lt;/p&gt;
&lt;p&gt;Using a combination of parameters and accessing a variable library means reusable notebooks are easier to write. This needs to become part of the best practice pattern being used.&lt;/p&gt;
&lt;h2 id="references"&gt;References
&lt;/h2&gt;&lt;p&gt;Microsoft learn covers Variable library utilities as part of the notebook utilities page.&lt;/p&gt;
&lt;p&gt;&lt;a class="link" href="https://learn.microsoft.com/en-us/fabric/data-engineering/notebook-utilities#variable-library-utilities?wt.mc_id=DX-MVP-5003563" target="_blank" rel="noopener"
 &gt;https://learn.microsoft.com/en-us/fabric/data-engineering/notebook-utilities#variable-library-utilities&lt;/a&gt;&lt;/p&gt;</description></item></channel></rss>