Reading Azure Key Vault secrets in Azure Synapse notebook using Python SDK

heta desai 247 Reputation points

I have created python package which read azure key vault secrets. The wheel package is created and imported into synapse spark pool. when I tried to add package in synapse notebook from wheel package it throws an error :

ModuleNotFoundError: No module named 'azure.keyvault'

here is the python module that reads secrets from Azure key vault and wheel package is imported into apache spark pool

from azure.identity import DefaultAzureCredential
from azure.keyvault.secrets import SecretClient

KEYVAULT_NAME = "lll-kv-scus"


credential = DefaultAzureCredential(exclude_shared_token_cache_credential=True)

client = SecretClient(vault_url=KEYVAULT_URI, credential=credential)

Server = client.get_secret("erverURL").value
User = client.get_secret("sql-user").value
Password = client.get_secret("sql-password").value
Database = client.get_secret("sql-databasename").value

A method is defined which returns key vault secrets. In synapse notebook tried to import above package to get secrets but it is unable to import SecretClient package.

Azure Key Vault
Azure Key Vault
An Azure service that is used to manage and protect cryptographic keys and other secrets used by cloud apps and services.
1,165 questions
Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
4,577 questions
{count} votes

1 answer

Sort by: Most helpful
  1. PRADEEPCHEEKATLA-MSFT 83,566 Reputation points Microsoft Employee

    Hello @Anonymous ,

    Thanks for the question and using MS Q&A platform.

    As per the error message: ModuleNotFoundError: No module named 'azure.keyvault' - which clearly says Azure Key Vault Secrets modules has not installed on the Apache Spark pool.

    Before installing the Azure Key Vault Module:


    Here is the requirements.txt file contains:


    To resolve this issue you need to install Azure Key Vault module on the Apache Spark pool as shown below:


    After installing the Azure Key Vault Module:


    Hope this will help. Please let us know if any further queries.


    • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you. Original posters help the community find answers faster by identifying the correct answer. Here is how
    • Want a reminder to come back and check responses? Here is how to subscribe to a notification
    • If you are interested in joining the VM program and help shape the future of Q&A: Here is jhow you can be part of Q&A Volunteer Moderators
    0 comments No comments