1

What is the equivalent to az account set Azure using Python SDK?

I'd like to select a subscription to act upon using Python script.

Example:

In a bash script, I'd choose the subscription to act on using az account set --subscription $desiredSub. I want to know the equivalent in Azure Pythons SDK.

SeaDude
  • 3,725
  • 6
  • 31
  • 68
  • 1
    Please expand your answer to clarify what you are asking. Do you mean you want to modify the CLI configuration via Python or you are writing a program and you want to authenticate with Azure? For the first case, look into modules such as azure-cli-core https://pypi.org/project/azure-cli-core/ and https://github.com/Azure/azure-cli/ – John Hanley Nov 27 '21 at 21:49
  • Expanded. I need to select which subscription to act on in a Python script. – SeaDude Nov 28 '21 at 01:58
  • Is your question: **How do I list my Azure subscriptions in Python**? – John Hanley Nov 28 '21 at 02:11
  • No. "How do I set the Azure Subscription for these X Python commands?" Sometimes a Python script will operate on multiple Azure Subscriptions ("Take a secret from Key Vault Secret 1 in Subscription A. Use the secret to provision resources in Subscription B."). For the first 3 commands `az account set --subscription $desiredSub` could be used for Subscription A, for the last 3 commands `az account set --subscription $desiredSub` would be aimed at Sub B. – SeaDude Nov 28 '21 at 03:11
  • If you are writing a Python script why are you concerned about the CLI? I do not understand your question. Are you trying to modify the CLI environment from Python? – John Hanley Nov 28 '21 at 03:15

0 Answers0