1
1
---
2
2
title : " Quickstart: Your first Python query"
3
3
description : In this quickstart, you follow the steps to enable the Resource Graph library for Python and run your first query.
4
- ms.date : 05/26 /2020
4
+ ms.date : 05/27 /2020
5
5
ms.topic : quickstart
6
6
---
7
7
# Quickstart: Run your first Resource Graph query using Python
@@ -57,17 +57,15 @@ installed.
57
57
```
58
58
59
59
> [ !NOTE]
60
- > If Python is installed for all users, this command must be run from an elevated console.
60
+ > If Python is installed for all users, these commands must be run from an elevated console.
61
61
62
62
1 . Validate that the libraries have been installed. ` azure-mgmt-resourcegraph ` should be ** 2.0.0**
63
63
or higher, ` azure-mgmt-resource ` should be ** 9.0.0** or higher, and ` azure-cli-core ` should be
64
64
** 2.5.0** or higher.
65
65
66
66
``` bash
67
67
# Check each installed library
68
- pip show azure-mgmt-resourcegraph
69
- pip show azure-mgmt-resource
70
- pip show azure-cli-core
68
+ pip show azure-mgmt-resourcegraph azure-mgmt-resource azure-cli-core
71
69
```
72
70
73
71
## Run your first Resource Graph query
@@ -91,18 +89,20 @@ Resource Graph query. The query returns the first five Azure resources with the
91
89
# Wrap all the work in a function
92
90
def getresources ( strQuery ):
93
91
# Get your credentials from Azure CLI (development only!) and get your subscription list
94
- subClient = get_client_from_cli_profile(SubscriptionClient)
95
- subsRaw = [sub.as_dict() for sub in subClient.subscriptions.list()]
96
- subList = []
92
+ subsClient = get_client_from_cli_profile(SubscriptionClient)
93
+ subsRaw = []
94
+ for sub in subsClient.subscriptions.list():
95
+ subsRaw.append(sub.as_dict())
96
+ subsList = []
97
97
for sub in subsRaw:
98
- subList .append(sub.get(' subscription_id' ))
98
+ subsList .append(sub.get(' subscription_id' ))
99
99
100
100
# Create Azure Resource Graph client and set options
101
101
argClient = get_client_from_cli_profile(arg.ResourceGraphClient)
102
102
argQueryOptions = arg.models.QueryRequestOptions(result_format = " objectArray" )
103
103
104
104
# Create query
105
- argQuery = arg.models.QueryRequest(subscriptions = subList , query = strQuery, options = argQueryOptions)
105
+ argQuery = arg.models.QueryRequest(subscriptions = subsList , query = strQuery, options = argQueryOptions)
106
106
107
107
# Run query
108
108
argResults = argClient.resources(argQuery)
@@ -147,9 +147,7 @@ the following command:
147
147
148
148
``` bash
149
149
# Remove the installed libraries from the Python environment
150
- pip uninstall azure-mgmt-resourcegraph
151
- pip uninstall azure-mgmt-resource
152
- pip uninstall azure-cli-core
150
+ pip uninstall azure-mgmt-resourcegraph azure-mgmt-resource azure-cli-core
153
151
```
154
152
155
153
## Next steps
0 commit comments