Registry / azure / azure-mgmt-resourcegraph

azure-mgmt-resourcegraph

JSON →
library8.0.1pypypi✓ verified 23d ago

The `azure-mgmt-resourcegraph` library is the Microsoft Azure Resource Graph Client Library for Python. It provides an efficient way to query Azure resources across subscriptions and tenants at scale using Kusto Query Language (KQL). This package is currently active, with version 8.0.1 being the latest stable release as of November 2025, and is tested with Python 3.9+.

pip install azure-mgmt-resourcegraph azure-identity
INSTALL
IMPORT
SIG · AZURE-MGMT-RESOURC
A
azure-mgmt-resourcegraph
azurepythonv8.0.1
Install
4.0s avg
Import
560ms
Disk
45MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v8.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.600s · 45.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 4.0s · import 0.520s · 46MB
45MB installed
● package 45MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ResourceGraphClient
from azure.mgmt.resourcegraph import ResourceGraphClient
from azure.mgmt.resourcegraph.resource_graph_client import ResourceGraphClient
Starting with version 2.0.0, the `ResourceGraphClient` should be imported directly from `azure.mgmt.resourcegraph`.

This quickstart demonstrates how to query Azure resources using `ResourceGraphClient` and `DefaultAzureCredential`. It retrieves the ID, name, type, and location of the first 5 resources in a specified Azure subscription. Ensure `AZURE_SUBSCRIPTION_ID` and appropriate authentication environment variables (e.g., `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`) are set.

import os from azure.identity import DefaultAzureCredential from azure.mgmt.resourcegraph import ResourceGraphClient # Set your Azure subscription ID in an environment variable or replace directly subscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', 'YOUR_AZURE_SUBSCRIPTION_ID') def main(): if subscription_id == 'YOUR_AZURE_SUBSCRIPTION_ID': print("Please set the AZURE_SUBSCRIPTION_ID environment variable or replace 'YOUR_AZURE_SUBSCRIPTION_ID' in the code.") return # Authenticate using DefaultAzureCredential. It tries multiple credential types. # Ensure AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET (for service principal) # or AZURE_USERNAME, AZURE_PASSWORD (for interactive login) are set as environment variables # or use 'az login' for Azure CLI credential. credential = DefaultAzureCredential() # Create ResourceGraphClient client = ResourceGraphClient(credential) # Define your Kusto Query Language (KQL) query query_request = { "query": "Resources | project id, name, type, location | limit 5", "subscriptions": [subscription_id] } print(f"Running query on subscription: {subscription_id}") try: response = client.resources(query_request) for resource in response.data: print(f"ID: {resource['id']}, Name: {resource['name']}, Type: {resource['type']}, Location: {resource['location']}") except Exception as e: print(f"An error occurred: {e}") if __name__ == '__main__': main()
Debug
Known issues
breakingThe credential system was completely revamped. Older authentication methods like `azure.common.credentials` or `msrestazure.azure_active_directory` are no longer supported. The `credentials` parameter has been renamed to `credential`.
fix
Migrate to `azure-identity` classes (e.g., `DefaultAzureCredential`) for authentication and ensure the parameter name is `credential`.
affects: 7.0.0b1 and higher (including 8.x)
breakingImport paths for `ResourceGraphClient`, `ResourceGraphClientConfiguration`, and models were changed. For example, `ResourceGraphClient` must now be imported directly from `azure.mgmt.resourcegraph`.
fix
Update import statements to directly import classes from the top-level `azure.mgmt.resourcegraph` package or its `models` submodule (e.g., `from azure.mgmt.resourcegraph import ResourceGraphClient`).
affects: 2.0.0 and higher (including 8.x)
gotchaAzure Resource Graph queries are subject to throttling and limits on the number of subscriptions and results returned. By default, queries return a maximum of 100 records and a single call can only fetch data across up to 1,000 subscriptions.
fix
Implement strategies like grouping/staggering queries, batching requests for subscriptions, and using the `first` parameter (up to 5000) to override the default 100-record limit for query results.
affects: All versions
gotchaQueries without an `order by` clause may yield different results each time they are executed due to the distributed nature of the Resource Graph service.
fix
Always include an `order by` clause in your KQL queries if consistent, repeatable ordering of results is required.
affects: All versions
Upgrade
Version history
8.0.1latest on PyPI · released Nov 24, 2025
Audit
Dependencies
azure-identityrequiredRequired for Azure Active Directory authentication, replacing older credential systems.
Agent activity
41 hits · last 30 days
node
34
OpenAI (training)
1
Resources
azure-mgmt-resourcegraph — pip install azure-mgmt-resourcegraph · libregistry