Skip to main content

Easy to use Python library for Azure Resource Manager.

The azurerm library provides wrapper functions for the Azure REST api. It doesn’t include every option for every API call but it is easy to extend. The goal is to make it easy to call the API from Python using the latest API versions (in some cases before the official SDKs are available).

Note: This is not an official Microsoft library, just some REST wrappers to make it easier to call the Azure REST API. For the official Microsoft Azure library for Python please go here: https://github.com/Azure/azure-sdk-for-python.

Latest news

For what’s new in the most recent version refer to the Changelog.

For occasional azurerm code samples and announcements see the azurerm blog.

Installation

  1. pip install azurerm

  2. To call these functions you need an authentication token. One way to get this is by creating a Service Principal, another is to get a bearer token using CLI.

Authenticating using a Service Principal

For a semi-permanent/hardcoded way to authenticate, you can create a “Service Principal” for your application (an application equivalent of a user). Once you’ve done this you’ll have 3 pieces of information: A tenant ID, an application ID, and an application secret. You will use these to create an authentication token. For more information on how to get this information go here: Authenticating a service principal with Azure Resource Manager. See also: Azure Resource Manager REST calls from Python. Make sure you create a service principal with sufficient access rights, like “Contributor”, not “Reader”.

Authenticating using CLI

When you run a CLI command, it caches an authentication token which you can use with azurerm calls. Recent versions of CLI have a command which returns an authentication token: az account get-access-token. Azurerm has added a new function to get the Azure authentication token from CLI’s local cache:

azurerm.get_access_token_from_cli()

This saves you from having to create a Service Princial at all. Note: This function will fail unless you have an unexpired authentication token in your local CLI cache. I.e. you have run az login on the same machine recently.

Example authenticating using the Azure Portal Cloud Shell:

me@Azure:-$ pip install --user --upgrade azurerm
me@azure:-$ python
>>> import azurerm
>>> token = azurerm.get_access_token_from_cli()
>>> azurerm.list_subscriptions(token)

azurerm examples

See below for some simple examples. A detailed set of azurerm programming examples can be found here: azurerm Python library programming examples. For more examples look at the azurerm examples library.

For full documentation see azurerm reference manual.

See also the unit test suite which covers the main storage, network, compute functions - the goal is to expand it to test every function in the library: test

National/isolated cloud support

To use this library with national or isolated clouds, set environment variables to override the public default endpoints.

E.g. bash shell example for China..

export AZURE_RM_ENDPOINT='https://management.chinacloudapi.cn'
export AZURE_AUTH_ENDPOINT='https://login.chinacloudapi.cn/'
export AZURE_RESOURCE_ENDPOINT='https://management.core.chinacloudapi.cn/'

Example to list Azure subscriptions, create a Resource Group, list Resource Groups

import azurerm

# create an authentication token (use a Service Principal or call get_access_token_from_cli())
# Service principal example:
tenant_id = 'your-tenant-id'
application_id = 'your-application-id'
application_secret = 'your-application-secret'

access_token = azurerm.get_access_token(tenant_id, application_id, application_secret)

# list subscriptions
subscriptions = azurerm.list_subscriptions(access_token)
for sub in subscriptions['value']:
    print(sub['displayName'] + ': ' + sub['subscriptionId'])

# select the first subscription
subscription_id = subscriptions['value'][0]['subscriptionId']

# create a resource group
print('Enter Resource group name to create.')
rgname = input()
location = 'southeastasia'
rgreturn = azurerm.create_resource_group(access_token, subscription_id, rgname, location)
print('Create RG return code: ' + str(rgreturn.status_code)

# list resource groups
resource_groups = azurerm.list_resource_groups(access_token, subscription_id)
for rg in resource_groups['value']:
    print(rg["name"] + ', ' + rg['location'] + ', ' + rg['properties']['provisioningState'])

Example to create a virtual machine

See create_vm.py.

See also an example to create a VM Scale Set create_vmss.py.

Example to create a Media Services Account

See createmediaserviceaccountinrg.py

Functions currently supported

A basic set of infrastructure create, list, query functions are implemented. If you want to add something please send me a PR (don’t forget to update this readme too).

See the Function reference for full documentation.

Release files for azurerm 0.8.23

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for azurerm 0.8.23
File Size Uploaded
azurerm-0.8.23.tar.gz 18.3 kB Details

Release files / azurerm-0.8.23.tar.gz

Download URL azurerm-0.8.23.tar.gz
Size 18.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5bc669b9a7a3e9381b10abe497cd4586cdf590f21604df5075bfed79fe125e07
BLAKE2b-256 checksum
How to use checksums
f0a5ed92979c7440135d5727cacb193eced0499a89e48185ab2c046b74e8d7e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.9.18

1 release file

0.9.17

3 release files

0.9.15

1 release file

0.9.14

2 release files

0.9.13

2 release files

0.9.12

2 release files

0.9.9

1 release file

0.9.8

1 release file

0.9.7

1 release file

0.9.6

1 release file

0.9.5

1 release file

0.9.4

1 release file

0.9.3

1 release file

0.9.2

1 release file

0.9.1

1 release file

0.9.0

1 release file

0.8.28

1 release file

0.8.27

1 release file

0.8.26

1 release file

0.8.25

1 release file

0.8.24

1 release file

This release

0.8.23 This release

1 release file

0.8.22

1 release file

0.8.21

1 release file

0.8.20

1 release file

0.8.19

1 release file

0.8.18

1 release file

0.8.17

1 release file

0.8.16

1 release file

0.8.15

1 release file

0.8.14

1 release file

0.8.13

1 release file

0.8.12

1 release file

0.8.11

1 release file

0.8.10

1 release file

0.8.9

1 release file

0.8.8

1 release file

0.8.7

1 release file

0.8.6

1 release file

0.8.5

1 release file

0.8.4

1 release file

0.8.3

1 release file

0.8.2

1 release file

0.8.1

1 release file

0.8.0

1 release file

0.7.28

1 release file

0.7.26

1 release file

0.7.24

1 release file

0.7.22

1 release file

0.7.21

1 release file

0.7.20

1 release file

0.7.18

1 release file

0.7.17

1 release file

0.7.16

1 release file

0.7.15

1 release file

0.7.14

1 release file

0.7.13

1 release file

0.7.12

1 release file

0.7.11

1 release file

0.7.10

1 release file

0.7.9

1 release file

0.7.8

1 release file

0.7.7

1 release file

0.7.6

1 release file

0.7.5

1 release file

0.7.4

1 release file

0.7.3

1 release file

0.7.2

1 release file

0.7.1

1 release file

0.7.0

1 release file

0.6.17

1 release file

0.6.16

1 release file

0.6.15

1 release file

0.6.14

1 release file

0.6.13

1 release file

0.6.12

1 release file

0.6.11

1 release file

0.6.10

1 release file

0.6.9

1 release file

0.6.8

1 release file

0.6.7

1 release file

0.6.6

1 release file

0.6.5

1 release file

0.6.4

1 release file

0.6.3

1 release file

0.6.2

1 release file

0.6.1

1 release file

0.6.0

1 release file

0.5.9

1 release file

0.5.8

1 release file

0.5.7

1 release file

0.5.6

1 release file

0.5.5

1 release file

0.5.4

1 release file

0.5.3

1 release file

0.5.2

1 release file

0.5.1

1 release file

0.5.0

1 release file

0.4.9

1 release file

0.4.8

1 release file

0.4.7

1 release file

0.4.6

1 release file

0.4.5

1 release file

0.4.4

1 release file

0.4.3

1 release file

0.4.2

1 release file

0.4.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page