<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Function Archives - AzureOps</title>
	<atom:link href="https://azureops.org/articles/category/azure/function/feed/" rel="self" type="application/rss+xml" />
	<link>https://azureops.org/articles/category/azure/function/</link>
	<description>Notable things about Cloud, Data and DevOps.</description>
	<lastBuildDate>Mon, 13 Oct 2025 14:27:22 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://i0.wp.com/azureops.org/wp-content/uploads/2021/04/cropped-android-chrome-512x512-1.png?fit=32%2C32&#038;ssl=1</url>
	<title>Function Archives - AzureOps</title>
	<link>https://azureops.org/articles/category/azure/function/</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">190208641</site>	<item>
		<title>Connect Python Azure Function to Azure SQL Using Managed Identity</title>
		<link>https://azureops.org/articles/connect-python-azure-function-to-azure-sql-using-managed-identity/</link>
		
		<dc:creator><![CDATA[Kunal Rathi]]></dc:creator>
		<pubDate>Thu, 18 Sep 2025 18:21:20 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[Managed Identity]]></category>
		<category><![CDATA[Python]]></category>
		<guid isPermaLink="false">https://azureops.org/?p=8874</guid>

					<description><![CDATA[<p>An Azure Function is a lightweight, serverless compute option in Azure that lets you execute small chunks of code in response to events or schedules without managing servers. When connecting Azure Functions to Azure SQL Database, you need a secure way to authenticate without storing credentials. That’s where Managed Identity steps in. Managed Identity allows [&#8230;]</p>
<p>The post <a href="https://azureops.org/articles/connect-python-azure-function-to-azure-sql-using-managed-identity/">Connect Python Azure Function to Azure SQL Using Managed Identity</a> appeared first on <a href="https://azureops.org">AzureOps</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="">An <strong>Azure Function</strong> is a lightweight, serverless compute option in Azure that lets you execute small chunks of code in response to events or schedules without managing servers. When connecting Azure Functions to <strong>Azure SQL Database</strong>, you need a secure way to authenticate without storing credentials. That’s where <strong>Managed Identity</strong> steps in. Managed Identity allows Azure resources (like Functions, VMs, Logic Apps) to access other Azure services securely by leveraging <strong>Azure Active Directory (AAD)</strong>.In this article, we’ll explore how to connect <a href="https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-python?tabs=get-started%2Casgi%2Capplication-level&amp;pivots=python-mode-decorators" target="_blank" rel="noreferrer noopener">Python Azure Function</a><strong> to Azure SQL</strong> using <strong>Managed Identity</strong>. You’ll learn step-by-step setup, Python code implementation, troubleshooting, and best practices to ensure your solution is secure and scalable.</p>



<h2 class="wp-block-heading">Why Use Managed Identity with Azure SQL?</h2>



<p class="">Storing passwords in configuration files is risky. Managed Identity solves this problem by:</p>



<ul class="wp-block-list">
<li class=""><strong>Eliminating Secrets</strong> → No passwords, no connection strings with credentials.</li>



<li class=""><strong>Centralized Identity Management</strong> → Uses <strong>Azure AD authentication</strong> for consistency.</li>



<li class=""><strong>Least Privilege Principle</strong> → Assigns only the required SQL permissions.</li>



<li class=""><strong>Automatic Rotation</strong> → No need to update or rotate credentials manually.</li>
</ul>



<p class="">This makes it the <strong>recommended authentication method</strong> when connecting Azure Functions to SQL Database.</p>



<p class="has-pale-cyan-blue-background-color has-background"><strong>Prerequisites:</strong><br>Before implementing, ensure you have:<br>1. An Azure subscription.<br>2. An Azure SQL Database already created.<br>3. An Azure Function App (Python runtime).<br>4. Azure CLI or Portal access.</p>



<p class="">This guide assumes you already have a basic understanding of creating an Azure Function. If you need a refresher, please refer to our previous article on <a href="https://azureops.org/articles/create-python-azure-function/" target="_blank" rel="noreferrer noopener">How to Create a Python Azure Function</a>.</p>



<p class="">Let&#8217;s now see how to connect Python Azure Function to Azure SQL database using managed identity authentication. In this example we will fetch data from a public API and securely write it to an <strong>Azure SQL Database</strong> table..</p>



<h3 class="wp-block-heading">Step 1: Set Up Your Azure SQL Database</h3>



<h4 class="wp-block-heading">Creating WeatherData Table</h4>



<p class="">In this guide, we’ll simulate fetching weather data from an API and storing it in Azure SQL.</p>



<p class="">Run the following SQL script inside your Azure SQL database:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; gutter: false; title: ; notranslate">
CREATE TABLE WeatherData (
    Id INT PRIMARY KEY IDENTITY(1,1),
    City VARCHAR(100),
    Temperature DECIMAL(5,2),
    Humidity INT,
    ForecastDate DATETIME
);

</pre></div>


<h3 class="wp-block-heading">Step 2: Enabling Managed Identity for Azure Function</h3>



<p class="">INavigate to your <strong>Function App</strong> in Azure Portal.</p>



<p class="">Under <strong>Settings → Identity</strong>, enable <strong>System Assigned Managed Identity</strong>.</p>



<p class="">Azure will create an identity in Microsoft Entra representing your Function.</p>



<figure class="wp-block-image size-full is-resized"><a href="https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Enable-Azure-function-managed-identity.png?ssl=1"><img fetchpriority="high" decoding="async" width="1072" height="715" data-attachment-id="8884" data-permalink="https://azureops.org/articles/connect-python-azure-function-to-azure-sql-using-managed-identity/enable-azure-function-managed-identity/" data-orig-file="https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Enable-Azure-function-managed-identity.png?fit=1072%2C715&amp;ssl=1" data-orig-size="1072,715" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Enable Azure function managed identity" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Enable-Azure-function-managed-identity.png?fit=300%2C200&amp;ssl=1" data-large-file="https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Enable-Azure-function-managed-identity.png?fit=1072%2C715&amp;ssl=1" src="https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Enable-Azure-function-managed-identity.png?fit=1072%2C715&amp;ssl=1" alt="Connect Python Azure Function to Azure SQL" class="wp-image-8884" style="width:821px;height:auto" srcset="https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Enable-Azure-function-managed-identity.png?w=1072&amp;ssl=1 1072w, https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Enable-Azure-function-managed-identity.png?resize=300%2C200&amp;ssl=1 300w, https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Enable-Azure-function-managed-identity.png?resize=930%2C620&amp;ssl=1 930w, https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Enable-Azure-function-managed-identity.png?resize=768%2C512&amp;ssl=1 768w, https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Enable-Azure-function-managed-identity.png?resize=450%2C300&amp;ssl=1 450w, https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Enable-Azure-function-managed-identity.png?resize=600%2C400&amp;ssl=1 600w" sizes="(max-width: 1072px) 100vw, 1072px" /></a></figure>



<h3 class="wp-block-heading">Step 3: Grant the Managed Identity Access to Azure SQL</h3>



<h4 class="wp-block-heading">Configuring Azure Entra Admin</h4>



<p class="">To allow <strong>Managed Identity</strong> to authenticate, assign an <strong>Azure Entra admin</strong> for your SQL server.</p>



<ol class="wp-block-list">
<li class="">Go to Azure Portal → SQL Server → <strong>Active Entra Admin</strong>.</li>



<li class="">Assign an Azure Entra user/group as the admin.</li>



<li class="">Save changes.</li>
</ol>



<h3 class="wp-block-heading">Grant the permissions</h3>



<p class="">Now, connect to to your Azure SQL Database using the Entra ID authentication. You need to grant the Managed Identity permission to write to the database. Use the following T-SQL commands, replacing <code>&lt;your-azure-function-name&gt;</code> with the name of your function:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; gutter: false; title: ; notranslate">
CREATE USER &#x5B;your-azure-function-name] FROM EXTERNAL PROVIDER;
ALTER ROLE db_datawriter ADD MEMBER &#x5B;your-azure-function-name];
</pre></div>


<ul class="wp-block-list">
<li class=""><code>CREATE USER</code> creates the identity inside SQL.</li>



<li class=""><code>ALTER ROLE</code> gives write permissions to insert/update/delete.</li>
</ul>



<p class="">Learn how to grant access to Azure SQL databases in this <a href="https://azureops.org/articles/grant-access-to-azure-sql-database/" target="_blank" rel="noreferrer noopener">post</a>.</p>



<h3 class="wp-block-heading">Step 4: Configure Application Settings</h3>



<p class="">In the Function App Environment variables, define following variables.</p>



<ul class="wp-block-list">
<li class=""><strong>SqlConnectionInfo</strong> → <code>Server=&lt;your-sql-server&gt;.database.windows.net;Database=&lt;your-db&gt;;</code></li>



<li class=""><strong>WEATHER_API_URL</strong> → https://api.open-meteo.com/v1/forecast?latitude=60.17&amp;longitude=24.94&amp;hourly=temperature_2m,relative_humidity_2m</li>



<li class=""><strong>TIMER_SCHEDULE</strong> → <code>0 * * * * *</code> (Runs every hour).</li>
</ul>



<figure class="wp-block-image size-full is-resized"><a href="https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Add-environment-variables-to-Azure-function.png?ssl=1"><img decoding="async" width="975" height="677" data-attachment-id="8886" data-permalink="https://azureops.org/articles/connect-python-azure-function-to-azure-sql-using-managed-identity/add-environment-variables-to-azure-function/" data-orig-file="https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Add-environment-variables-to-Azure-function.png?fit=975%2C677&amp;ssl=1" data-orig-size="975,677" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Add environment variables to Azure function" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Add-environment-variables-to-Azure-function.png?fit=300%2C208&amp;ssl=1" data-large-file="https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Add-environment-variables-to-Azure-function.png?fit=975%2C677&amp;ssl=1" src="https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Add-environment-variables-to-Azure-function.png?fit=975%2C677&amp;ssl=1" alt="Azure Function configuration settings
" class="wp-image-8886" style="width:850px;height:auto" srcset="https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Add-environment-variables-to-Azure-function.png?w=975&amp;ssl=1 975w, https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Add-environment-variables-to-Azure-function.png?resize=300%2C208&amp;ssl=1 300w, https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Add-environment-variables-to-Azure-function.png?resize=893%2C620&amp;ssl=1 893w, https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Add-environment-variables-to-Azure-function.png?resize=768%2C533&amp;ssl=1 768w, https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Add-environment-variables-to-Azure-function.png?resize=450%2C312&amp;ssl=1 450w, https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Add-environment-variables-to-Azure-function.png?resize=600%2C417&amp;ssl=1 600w" sizes="(max-width: 975px) 100vw, 975px" /></a></figure>



<h3 class="wp-block-heading">Step 5: Writing Python Azure Function Code</h3>



<p class="">Now, it&#8217;s time to write the code that will perform the data fetching and insertion. For this example, we&#8217;ll use a Python HTTP-triggered function and the <code>requests</code> and <code>pyodbc</code> libraries. You will also need the <code>azure-identity</code> package to handle the Managed Identity authentication.</p>



<h4 class="wp-block-heading">1. Installing Required Packages</h4>



<p class="">Add to <code>requirements.txt</code>:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; gutter: false; title: ; notranslate">
azure-functions
requests
pypyodbc
</pre></div>


<h4 class="wp-block-heading">2. Write the function code (<code>__init__.py</code>):</h4>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: python; title: ; notranslate">
import azure.functions as func
import logging, os, requests, pypyodbc

app = func.FunctionApp()

@app.timer_trigger(schedule=&quot;%TIMER_SCHEDULE%&quot;, arg_name=&quot;myTimer&quot;)
def load_weather_data_to_sql(myTimer: func.TimerRequest):
    if myTimer.past_due:
        logging.info(&quot;The timer is past due!&quot;)

    try:
        url = os.getenv(&quot;WEATHER_API_URL&quot;)
        response = requests.get(url)
        data = response.json().get(&quot;current&quot;, {})
        
        temperature = data.get(&quot;temperature_2m&quot;)
        humidity = data.get(&quot;relative_humidity_2m&quot;)
        city = &quot;Berlin&quot;

        conn = get_sql_connection()
        cursor = conn.cursor()
        cursor.execute(
            &quot;INSERT INTO WeatherData (City, Temperature, Humidity, ForecastDate) VALUES (?, ?, ?, GETDATE())&quot;,
            (city, temperature, humidity)
        )
        conn.commit()
        cursor.close()
        conn.close()
        logging.info(&quot;Weather data inserted successfully&quot;)

    except Exception as e:
        logging.error(f&quot;Error: {e}&quot;)

def get_sql_connection():
    conn_info = os.getenv(&quot;SqlConnectionInfo&quot;)
    parts = dict(item.split(&quot;=&quot;,1) for item in conn_info.split(&quot;;&quot;) if &quot;=&quot; in item)
    server, db = parts.get(&quot;Server&quot;), parts.get(&quot;Database&quot;)
# Depending on the python version, select appropriate ODBC Driver. For latest version 3.12, use ODBC Driver 18. For previous versions, try ODBC Driver 17.
    conn_str = f&quot;DRIVER={{ODBC Driver 18 for SQL Server}};Server={server};Database={db};Authentication=ActiveDirectoryMsi;&quot;
    return pypyodbc.connect(conn_str)

</pre></div>


<figure class="is-style-default wp-block-image size-large is-resized"><a href="https://marketplace.visualstudio.com/items?itemName=AzureOps.ssiscatalogerpro&amp;ssr=false#overview" target="_blank" rel="noopener"><img data-recalc-dims="1" decoding="async" width="1200" height="148" data-attachment-id="4839" data-permalink="https://azureops.org/articles/azure-data-studio-for-sql-developers/scmw-horizontal-ad/" data-orig-file="https://i0.wp.com/azureops.org/wp-content/uploads/2023/01/SCMW-horizontal-ad.png?fit=1326%2C163&amp;ssl=1" data-orig-size="1326,163" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="SCMW-horizontal-ad" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/azureops.org/wp-content/uploads/2023/01/SCMW-horizontal-ad.png?fit=300%2C37&amp;ssl=1" data-large-file="https://i0.wp.com/azureops.org/wp-content/uploads/2023/01/SCMW-horizontal-ad.png?fit=1200%2C148&amp;ssl=1" src="https://i0.wp.com/azureops.org/wp-content/uploads/2023/01/SCMW-horizontal-ad.png?resize=1200%2C148&#038;ssl=1" alt="" class="wp-image-4839" style="object-fit:cover;width:811px;height:99px" srcset="https://i0.wp.com/azureops.org/wp-content/uploads/2023/01/SCMW-horizontal-ad.png?resize=1200%2C148&amp;ssl=1 1200w, https://i0.wp.com/azureops.org/wp-content/uploads/2023/01/SCMW-horizontal-ad.png?resize=450%2C55&amp;ssl=1 450w, https://i0.wp.com/azureops.org/wp-content/uploads/2023/01/SCMW-horizontal-ad.png?resize=600%2C74&amp;ssl=1 600w, https://i0.wp.com/azureops.org/wp-content/uploads/2023/01/SCMW-horizontal-ad.png?resize=300%2C37&amp;ssl=1 300w, https://i0.wp.com/azureops.org/wp-content/uploads/2023/01/SCMW-horizontal-ad.png?resize=768%2C94&amp;ssl=1 768w, https://i0.wp.com/azureops.org/wp-content/uploads/2023/01/SCMW-horizontal-ad.png?w=1326&amp;ssl=1 1326w" sizes="(max-width: 1200px) 100vw, 1200px" /></a></figure>



<h3 class="wp-block-heading">Step 6: Testing the Integration</h3>



<h4 class="wp-block-heading">Running Function Locally</h4>



<ul class="wp-block-list">
<li class="">Use <strong>Azure Functions Core Tools</strong>.</li>



<li class="">Set local.settings.json with required env variables.</li>



<li class="">Test the API call and SQL insertion.</li>
</ul>



<h4 class="wp-block-heading">Deploying to Azure</h4>



<ul class="wp-block-list">
<li class="">Push code to Azure Function App.</li>



<li class="">Check logs in <strong>Application Insights</strong> or <code>Log Stream</code>.</li>



<li class="">Common Issues and Troubleshooting.</li>
</ul>



<h2 class="wp-block-heading">Best Practices for Secure and Scalable Integration</h2>



<ul class="wp-block-list">
<li class="">Use <strong>least privilege</strong> for SQL roles.</li>



<li class="">Store configs in <strong>Azure Key Vault</strong>.</li>



<li class="">Monitor using <strong>Azure Monitor + Application Insights</strong>.</li>



<li class="">Implement retry logic for transient failures.</li>
</ul>



<h2 class="wp-block-heading">FAQs</h2>


<div class="wp-block-uagb-faq uagb-faq__outer-wrap uagb-block-1f3f6ec0 uagb-faq-icon-row uagb-faq-layout-accordion uagb-faq-expand-first-true uagb-faq-inactive-other-true uagb-faq__wrap uagb-buttons-layout-wrap uagb-faq-equal-height     " data-faqtoggle="true" role="tablist"><div class="wp-block-uagb-faq-child uagb-faq-child__outer-wrap uagb-faq-item uagb-block-152cbd76 " role="tab" tabindex="0"><div class="uagb-faq-questions-button uagb-faq-questions">			<span class="uagb-icon uagb-faq-icon-wrap">
								<svg xmlns="https://www.w3.org/2000/svg" viewBox= "0 0 448 512"><path d="M432 256c0 17.69-14.33 32.01-32 32.01H256v144c0 17.69-14.33 31.99-32 31.99s-32-14.3-32-31.99v-144H48c-17.67 0-32-14.32-32-32.01s14.33-31.99 32-31.99H192v-144c0-17.69 14.33-32.01 32-32.01s32 14.32 32 32.01v144h144C417.7 224 432 238.3 432 256z"></path></svg>
							</span>
						<span class="uagb-icon-active uagb-faq-icon-wrap">
								<svg xmlns="https://www.w3.org/2000/svg" viewBox= "0 0 448 512"><path d="M400 288h-352c-17.69 0-32-14.32-32-32.01s14.31-31.99 32-31.99h352c17.69 0 32 14.3 32 31.99S417.7 288 400 288z"></path></svg>
							</span>
			<span class="uagb-question">Can I use User-Assigned Managed Identity instead of System-Assigned?</span></div><div class="uagb-faq-content"><p>Yes, both are supported. User-assigned is better for multiple Functions sharing one identity.</p></div></div><div class="wp-block-uagb-faq-child uagb-faq-child__outer-wrap uagb-faq-item uagb-block-588ab62f " role="tab" tabindex="0"><div class="uagb-faq-questions-button uagb-faq-questions">			<span class="uagb-icon uagb-faq-icon-wrap">
								<svg xmlns="https://www.w3.org/2000/svg" viewBox= "0 0 448 512"><path d="M432 256c0 17.69-14.33 32.01-32 32.01H256v144c0 17.69-14.33 31.99-32 31.99s-32-14.3-32-31.99v-144H48c-17.67 0-32-14.32-32-32.01s14.33-31.99 32-31.99H192v-144c0-17.69 14.33-32.01 32-32.01s32 14.32 32 32.01v144h144C417.7 224 432 238.3 432 256z"></path></svg>
							</span>
						<span class="uagb-icon-active uagb-faq-icon-wrap">
								<svg xmlns="https://www.w3.org/2000/svg" viewBox= "0 0 448 512"><path d="M400 288h-352c-17.69 0-32-14.32-32-32.01s14.31-31.99 32-31.99h352c17.69 0 32 14.3 32 31.99S417.7 288 400 288z"></path></svg>
							</span>
			<span class="uagb-question">What if I want read-only access to SQL?</span></div><div class="uagb-faq-content"><p>Assign the <code>db_datareader</code> role instead of <code>db_datawriter</code>.</p></div></div><div class="wp-block-uagb-faq-child uagb-faq-child__outer-wrap uagb-faq-item uagb-block-81419b26 " role="tab" tabindex="0"><div class="uagb-faq-questions-button uagb-faq-questions">			<span class="uagb-icon uagb-faq-icon-wrap">
								<svg xmlns="https://www.w3.org/2000/svg" viewBox= "0 0 448 512"><path d="M432 256c0 17.69-14.33 32.01-32 32.01H256v144c0 17.69-14.33 31.99-32 31.99s-32-14.3-32-31.99v-144H48c-17.67 0-32-14.32-32-32.01s14.33-31.99 32-31.99H192v-144c0-17.69 14.33-32.01 32-32.01s32 14.32 32 32.01v144h144C417.7 224 432 238.3 432 256z"></path></svg>
							</span>
						<span class="uagb-icon-active uagb-faq-icon-wrap">
								<svg xmlns="https://www.w3.org/2000/svg" viewBox= "0 0 448 512"><path d="M400 288h-352c-17.69 0-32-14.32-32-32.01s14.31-31.99 32-31.99h352c17.69 0 32 14.3 32 31.99S417.7 288 400 288z"></path></svg>
							</span>
			<span class="uagb-question">Does Managed Identity work with Elastic Pools?</span></div><div class="uagb-faq-content"><p>Yes, it works across all Azure SQL deployment models.</p></div></div><div class="wp-block-uagb-faq-child uagb-faq-child__outer-wrap uagb-faq-item uagb-block-9bb291eb " role="tab" tabindex="0"><div class="uagb-faq-questions-button uagb-faq-questions">			<span class="uagb-icon uagb-faq-icon-wrap">
								<svg xmlns="https://www.w3.org/2000/svg" viewBox= "0 0 448 512"><path d="M432 256c0 17.69-14.33 32.01-32 32.01H256v144c0 17.69-14.33 31.99-32 31.99s-32-14.3-32-31.99v-144H48c-17.67 0-32-14.32-32-32.01s14.33-31.99 32-31.99H192v-144c0-17.69 14.33-32.01 32-32.01s32 14.32 32 32.01v144h144C417.7 224 432 238.3 432 256z"></path></svg>
							</span>
						<span class="uagb-icon-active uagb-faq-icon-wrap">
								<svg xmlns="https://www.w3.org/2000/svg" viewBox= "0 0 448 512"><path d="M400 288h-352c-17.69 0-32-14.32-32-32.01s14.31-31.99 32-31.99h352c17.69 0 32 14.3 32 31.99S417.7 288 400 288z"></path></svg>
							</span>
			<span class="uagb-question">Is pypyodbc required or can I use pyodbc?</span></div><div class="uagb-faq-content"><p>In Azure Functions Linux consumption plan, <code>pypyodbc</code> works more reliably.</p></div></div><div class="wp-block-uagb-faq-child uagb-faq-child__outer-wrap uagb-faq-item uagb-block-e8d40354 " role="tab" tabindex="0"><div class="uagb-faq-questions-button uagb-faq-questions">			<span class="uagb-icon uagb-faq-icon-wrap">
								<svg xmlns="https://www.w3.org/2000/svg" viewBox= "0 0 448 512"><path d="M432 256c0 17.69-14.33 32.01-32 32.01H256v144c0 17.69-14.33 31.99-32 31.99s-32-14.3-32-31.99v-144H48c-17.67 0-32-14.32-32-32.01s14.33-31.99 32-31.99H192v-144c0-17.69 14.33-32.01 32-32.01s32 14.32 32 32.01v144h144C417.7 224 432 238.3 432 256z"></path></svg>
							</span>
						<span class="uagb-icon-active uagb-faq-icon-wrap">
								<svg xmlns="https://www.w3.org/2000/svg" viewBox= "0 0 448 512"><path d="M400 288h-352c-17.69 0-32-14.32-32-32.01s14.31-31.99 32-31.99h352c17.69 0 32 14.3 32 31.99S417.7 288 400 288z"></path></svg>
							</span>
			<span class="uagb-question">Can I connect to SQL Server on-prem using Managed Identity?</span></div><div class="uagb-faq-content"><p>Not directly. You’d need a Hybrid Connection or VPN.</p></div></div><div class="wp-block-uagb-faq-child uagb-faq-child__outer-wrap uagb-faq-item uagb-block-8a7feb69 " role="tab" tabindex="0"><div class="uagb-faq-questions-button uagb-faq-questions">			<span class="uagb-icon uagb-faq-icon-wrap">
								<svg xmlns="https://www.w3.org/2000/svg" viewBox= "0 0 448 512"><path d="M432 256c0 17.69-14.33 32.01-32 32.01H256v144c0 17.69-14.33 31.99-32 31.99s-32-14.3-32-31.99v-144H48c-17.67 0-32-14.32-32-32.01s14.33-31.99 32-31.99H192v-144c0-17.69 14.33-32.01 32-32.01s32 14.32 32 32.01v144h144C417.7 224 432 238.3 432 256z"></path></svg>
							</span>
						<span class="uagb-icon-active uagb-faq-icon-wrap">
								<svg xmlns="https://www.w3.org/2000/svg" viewBox= "0 0 448 512"><path d="M400 288h-352c-17.69 0-32-14.32-32-32.01s14.31-31.99 32-31.99h352c17.69 0 32 14.3 32 31.99S417.7 288 400 288z"></path></svg>
							</span>
			<span class="uagb-question">Azure function execution giving Error: Error during function execution: (&#8216;01000&#8217;, &#8220;[01000] [unixODBC][Driver Manager]Can&#8217;t open lib &#8216;ODBC Driver 17 for SQL Server&#8217; : file not found&#8221;)</span></div><div class="uagb-faq-content"><p>This error usually occurs due to mismatch of ODBC Driver version. Depending on the python version, select appropriate ODBC Driver. For latest version 3.12, use ODBC Driver 18. For previous versions, try ODBC Driver 17.</p></div></div></div>


<h2 class="wp-block-heading">Conclusion</h2>



<p class="">By following these steps, you’ve securely connected a <strong>Python Azure Function</strong> to an <strong>Azure SQL Database</strong> using <strong>Managed Identity</strong>. This approach avoids hardcoding credentials, ensures automatic rotation, and aligns with cloud security best practices.</p>



<p class="">With this foundation, you can extend the Function to handle more APIs, perform ETL pipelines, or automate reporting tasks, all while staying secure and compliant.</p>



<p class="has-background" style="background-color:#beefca"><strong>Pro tips:</strong><br>1. Always prefer pypyodbc in Functions to avoid dependency issues.<br>2. Use retry policies when inserting data into SQL.<br>3. Keep Functions lightweight, offload heavy processing to Azure Data Factory or Microsoft Fabric.<br>4. If scaling out, validate SQL performance with connection pooling.<br>5. Learn how to <a href="https://azureops.org/articles/connect-azure-sql-from-data-factory-using-managed-identity/" target="_blank" rel="noreferrer noopener">connect to Azure SQL from Azure Data Factory</a> using managed identity.<br></p>



<h2 class="wp-block-heading">See more</h2>



<iframe loading="lazy" width="700" height="394" src="https://www.youtube.com/embed/t2h6xNVFQkc" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="is-style-fill wp-block-button"><a class="wp-block-button__link has-white-color has-blush-light-purple-gradient-background has-text-color has-background has-link-color wp-element-button" href="https://azureops.org/product/ssis-catalog-migration-wizard-pro/" target="_blank" rel="noreferrer noopener">Download Now</a></div>
</div>
<p>The post <a href="https://azureops.org/articles/connect-python-azure-function-to-azure-sql-using-managed-identity/">Connect Python Azure Function to Azure SQL Using Managed Identity</a> appeared first on <a href="https://azureops.org">AzureOps</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">8874</post-id>	</item>
		<item>
		<title>Create Python Azure function in Visual Studio Code</title>
		<link>https://azureops.org/articles/create-python-azure-function/</link>
		
		<dc:creator><![CDATA[Kunal Rathi]]></dc:creator>
		<pubDate>Thu, 07 Nov 2024 16:38:45 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[azure function]]></category>
		<category><![CDATA[python azure function]]></category>
		<guid isPermaLink="false">https://azureops.org/?p=7939</guid>

					<description><![CDATA[<p>Azure Functions is a serverless computing service that enables developers to deploy small pieces of code without the need to manage the underlying infrastructure. It supports various programming languages, including .NET, Python, JavaScript, TypeScript, Java, PowerShell, and C#, providing flexibility and versatility for various applications. This article describes how to create Python Azure function in [&#8230;]</p>
<p>The post <a href="https://azureops.org/articles/create-python-azure-function/">Create Python Azure function in Visual Studio Code</a> appeared first on <a href="https://azureops.org">AzureOps</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="">Azure Functions is a serverless computing service that enables developers to deploy small pieces of code without the need to manage the underlying infrastructure. It supports various programming languages, including .NET, Python, JavaScript, TypeScript, Java, PowerShell, and C#, providing flexibility and versatility for various applications. This article describes how to create Python Azure function in Visual Studio code.</p>



<p class="has-pale-cyan-blue-background-color has-background"><strong>Prerequisites:</strong><br>1. <a href="https://code.visualstudio.com/download" target="_blank" rel="noreferrer noopener">Visual Studio Code</a> installed on your machine. <br>2. <strong>Azure Functions Core Tools</strong> installed. This can be installed via <a href="https://nodejs.org/">Node.js</a> or the <code>npm install -g azure-functions-core-tools</code> command.<br>3. <strong>Python Interpreter</strong> (Ensure Python 3.8 or later is installed, preferably the latest version). Install it from Microsoft Store.<br>4. <strong>Azure Account</strong> with an active subscription. If you don’t have one, create a free Azure account at <a href="https://azure.microsoft.com/free/">Azure Free Account</a>.<br>4. <strong>Azure Functions Extension for Visual Studio Code</strong> installed. Install this from the Extensions marketplace in Visual Studio Code.<br>5. <strong>Azure CLI</strong> (Command Line Interface), for deploying the function.</p>



<p class=""></p>



<figure class="wp-block-image size-full is-resized"><a href="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/install-Azure-function-extension.webp?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" width="1180" height="377" data-attachment-id="7968" data-permalink="https://azureops.org/articles/create-python-azure-function/install-azure-function-extension/" data-orig-file="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/install-Azure-function-extension.webp?fit=1180%2C377&amp;ssl=1" data-orig-size="1180,377" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="install-Azure-function-extension" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/install-Azure-function-extension.webp?fit=300%2C96&amp;ssl=1" data-large-file="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/install-Azure-function-extension.webp?fit=1180%2C377&amp;ssl=1" src="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/install-Azure-function-extension.webp?resize=1180%2C377&#038;ssl=1" alt="create python azure function" class="wp-image-7968" style="width:933px;height:auto" srcset="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/install-Azure-function-extension.webp?w=1180&amp;ssl=1 1180w, https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/install-Azure-function-extension.webp?resize=300%2C96&amp;ssl=1 300w, https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/install-Azure-function-extension.webp?resize=768%2C245&amp;ssl=1 768w, https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/install-Azure-function-extension.webp?resize=450%2C144&amp;ssl=1 450w, https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/install-Azure-function-extension.webp?resize=600%2C192&amp;ssl=1 600w" sizes="auto, (max-width: 1180px) 100vw, 1180px" /></a></figure>



<h2 class="wp-block-heading">Follow the below steps to Create Python Azure function in Visual Studio Code</h2>



<p class="">1. Open Visual Studio Code and on the left-hand side ribbon, Click Azure Icon. A menu at the bottom will pop up. Click on the Azure function icon and click the &#8216;Create Function&#8217; menu item.</p>



<figure class="wp-block-image size-full is-resized"><a href="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Right-click-on-Azure-icon-and-select-Azure-function.webp?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" width="463" height="426" data-attachment-id="7945" data-permalink="https://azureops.org/articles/create-python-azure-function/right-click-on-azure-icon-and-select-azure-function/" data-orig-file="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Right-click-on-Azure-icon-and-select-Azure-function.webp?fit=463%2C426&amp;ssl=1" data-orig-size="463,426" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Right-click-on-Azure-icon-and-select-Azure-function" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Right-click-on-Azure-icon-and-select-Azure-function.webp?fit=300%2C276&amp;ssl=1" data-large-file="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Right-click-on-Azure-icon-and-select-Azure-function.webp?fit=463%2C426&amp;ssl=1" src="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Right-click-on-Azure-icon-and-select-Azure-function.webp?resize=463%2C426&#038;ssl=1" alt="" class="wp-image-7945" style="width:373px;height:auto" srcset="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Right-click-on-Azure-icon-and-select-Azure-function.webp?w=463&amp;ssl=1 463w, https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Right-click-on-Azure-icon-and-select-Azure-function.webp?resize=300%2C276&amp;ssl=1 300w, https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Right-click-on-Azure-icon-and-select-Azure-function.webp?resize=450%2C414&amp;ssl=1 450w" sizes="auto, (max-width: 463px) 100vw, 463px" /></a></figure>



<p class="">2. Select Python as a language as shown in the below image. </p>



<figure class="wp-block-image size-full is-resized"><a href="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-Python-programming-language.webp?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" width="771" height="187" data-attachment-id="7946" data-permalink="https://azureops.org/articles/create-python-azure-function/select-python-programming-language/" data-orig-file="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-Python-programming-language.webp?fit=771%2C187&amp;ssl=1" data-orig-size="771,187" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Select-Python-programming-language" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-Python-programming-language.webp?fit=300%2C73&amp;ssl=1" data-large-file="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-Python-programming-language.webp?fit=771%2C187&amp;ssl=1" src="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-Python-programming-language.webp?resize=771%2C187&#038;ssl=1" alt="" class="wp-image-7946" style="width:545px;height:auto" srcset="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-Python-programming-language.webp?w=771&amp;ssl=1 771w, https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-Python-programming-language.webp?resize=300%2C73&amp;ssl=1 300w, https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-Python-programming-language.webp?resize=768%2C186&amp;ssl=1 768w, https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-Python-programming-language.webp?resize=450%2C109&amp;ssl=1 450w, https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-Python-programming-language.webp?resize=600%2C146&amp;ssl=1 600w" sizes="auto, (max-width: 771px) 100vw, 771px" /></a></figure>



<p class="">3. Select &#8216;Model V2&#8217; as the Python programming model.</p>



<figure class="wp-block-image size-full is-resized"><a href="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-model-V2-1.webp?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" width="603" height="158" data-attachment-id="7962" data-permalink="https://azureops.org/articles/create-python-azure-function/select-model-v2-2/" data-orig-file="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-model-V2-1.webp?fit=603%2C158&amp;ssl=1" data-orig-size="603,158" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Select model V2" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-model-V2-1.webp?fit=300%2C79&amp;ssl=1" data-large-file="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-model-V2-1.webp?fit=603%2C158&amp;ssl=1" src="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-model-V2-1.webp?resize=603%2C158&#038;ssl=1" alt="" class="wp-image-7962" style="width:546px;height:auto" srcset="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-model-V2-1.webp?w=603&amp;ssl=1 603w, https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-model-V2-1.webp?resize=300%2C79&amp;ssl=1 300w, https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-model-V2-1.webp?resize=450%2C118&amp;ssl=1 450w, https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-model-V2-1.webp?resize=600%2C157&amp;ssl=1 600w" sizes="auto, (max-width: 603px) 100vw, 603px" /></a></figure>



<p class="">4. Select Python interpreter as the latest available version (3.11.9). </p>



<figure class="wp-block-image size-full is-resized"><a href="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-python-version.webp?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" width="573" height="171" data-attachment-id="7949" data-permalink="https://azureops.org/articles/create-python-azure-function/select-python-version/" data-orig-file="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-python-version.webp?fit=573%2C171&amp;ssl=1" data-orig-size="573,171" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Select-python-version" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-python-version.webp?fit=300%2C90&amp;ssl=1" data-large-file="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-python-version.webp?fit=573%2C171&amp;ssl=1" src="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-python-version.webp?resize=573%2C171&#038;ssl=1" alt="" class="wp-image-7949" style="width:543px;height:auto" srcset="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-python-version.webp?w=573&amp;ssl=1 573w, https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-python-version.webp?resize=300%2C90&amp;ssl=1 300w, https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-python-version.webp?resize=450%2C134&amp;ssl=1 450w" sizes="auto, (max-width: 573px) 100vw, 573px" /></a></figure>



<p class="">5. Select the type of trigger you want to use for this function. In our case, we will use the Time trigger. Provide a <strong>CRON Expression</strong> (e.g., <code>0 */5 * * * *</code> for every 5 minutes) to schedule the timer trigger.</p>



<figure class="wp-block-image size-full is-resized"><a href="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-trigger-type.webp?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" width="686" height="222" data-attachment-id="7951" data-permalink="https://azureops.org/articles/create-python-azure-function/select-trigger-type/" data-orig-file="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-trigger-type.webp?fit=686%2C222&amp;ssl=1" data-orig-size="686,222" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Select-trigger-type" data-image-description="" data-image-caption="" data-medium-file="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-trigger-type.webp?fit=300%2C97&amp;ssl=1" data-large-file="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-trigger-type.webp?fit=686%2C222&amp;ssl=1" src="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-trigger-type.webp?resize=686%2C222&#038;ssl=1" alt="create python azure function" class="wp-image-7951" style="width:542px;height:auto" srcset="https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-trigger-type.webp?w=686&amp;ssl=1 686w, https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-trigger-type.webp?resize=300%2C97&amp;ssl=1 300w, https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-trigger-type.webp?resize=450%2C146&amp;ssl=1 450w, https://i0.wp.com/azureops.org/wp-content/uploads/2024/07/Select-trigger-type.webp?resize=600%2C194&amp;ssl=1 600w" sizes="auto, (max-width: 686px) 100vw, 686px" /></a></figure>



<p class="">6. Once the above steps are complete, Visual Studio Code will generate a Python Azure Function template with a pre-defined structure. Open the <code>__init__.py</code> file and add the desired logic for your function.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: python; title: ; notranslate">
import datetime
import logging

import azure.functions as func

def main(mytimer: func.TimerRequest) -&gt; None:
    utc_timestamp = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).isoformat()

    if mytimer.past_due:
        logging.warning(&#039;The timer is past due!&#039;)

    logging.info(f&#039;Python timer trigger function ran at {utc_timestamp}&#039;)

</pre></div>


<h2 class="wp-block-heading">Debugging Your Function Locally</h2>



<ol class="wp-block-list">
<li class="">Press <code>F5</code> or click on the <strong>Run and Debug</strong> option in Visual Studio Code.</li>



<li class="">Azure Core Tools will emulate the function runtime locally, allowing you to test the functionality.</li>
</ol>



<h2 class="wp-block-heading">Deploying the Function to Azure</h2>



<ol class="wp-block-list">
<li class="">Click on the <strong>Azure Icon</strong> in Visual Studio Code.</li>



<li class="">Sign in to your Azure account if not already done.</li>



<li class="">Right-click on the <strong>Functions</strong> node and select <strong>Deploy to Function App</strong>.</li>



<li class="">Follow the prompts to create or choose an Azure Function App in your subscription.</li>
</ol>



<p class="">We have seen how to create Python Azure function in Visual Studio Code.</p>



<h2 class="wp-block-heading">See more</h2>



<iframe loading="lazy" width="700" height="394" src="https://www.youtube.com/embed/t2h6xNVFQkc" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="is-style-fill wp-block-button"><a class="wp-block-button__link has-white-color has-blush-light-purple-gradient-background has-text-color has-background has-link-color wp-element-button" href="https://azureops.org/product/ssis-catalog-migration-wizard-pro/" target="_blank" rel="noreferrer noopener">Download Now</a></div>
</div>
<p>The post <a href="https://azureops.org/articles/create-python-azure-function/">Create Python Azure function in Visual Studio Code</a> appeared first on <a href="https://azureops.org">AzureOps</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">7939</post-id>	</item>
	</channel>
</rss>
