{"id":2880,"library":"azure-mgmt-resourcegraph","title":"Microsoft Azure Resource Graph Client Library for Python","description":"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+.","status":"active","version":"8.0.1","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/resources/azure-mgmt-resourcegraph","tags":["azure","cloud","management","resourcegraph","kql","resource"],"install":[{"cmd":"pip install azure-mgmt-resourcegraph azure-identity","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for Azure Active Directory authentication, replacing older credential systems.","package":"azure-identity","optional":false}],"imports":[{"note":"Starting with version 2.0.0, the `ResourceGraphClient` should be imported directly from `azure.mgmt.resourcegraph`.","wrong":"from azure.mgmt.resourcegraph.resource_graph_client import ResourceGraphClient","symbol":"ResourceGraphClient","correct":"from azure.mgmt.resourcegraph import ResourceGraphClient"}],"quickstart":{"code":"import os\nfrom azure.identity import DefaultAzureCredential\nfrom azure.mgmt.resourcegraph import ResourceGraphClient\n\n# Set your Azure subscription ID in an environment variable or replace directly\nsubscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', 'YOUR_AZURE_SUBSCRIPTION_ID')\n\ndef main():\n    if subscription_id == 'YOUR_AZURE_SUBSCRIPTION_ID':\n        print(\"Please set the AZURE_SUBSCRIPTION_ID environment variable or replace 'YOUR_AZURE_SUBSCRIPTION_ID' in the code.\")\n        return\n\n    # Authenticate using DefaultAzureCredential. It tries multiple credential types.\n    # Ensure AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET (for service principal)\n    # or AZURE_USERNAME, AZURE_PASSWORD (for interactive login) are set as environment variables\n    # or use 'az login' for Azure CLI credential.\n    credential = DefaultAzureCredential()\n\n    # Create ResourceGraphClient\n    client = ResourceGraphClient(credential)\n\n    # Define your Kusto Query Language (KQL) query\n    query_request = {\n        \"query\": \"Resources | project id, name, type, location | limit 5\",\n        \"subscriptions\": [subscription_id]\n    }\n\n    print(f\"Running query on subscription: {subscription_id}\")\n    try:\n        response = client.resources(query_request)\n        for resource in response.data:\n            print(f\"ID: {resource['id']}, Name: {resource['name']}, Type: {resource['type']}, Location: {resource['location']}\")\n    except Exception as e:\n        print(f\"An error occurred: {e}\")\n\nif __name__ == '__main__':\n    main()","lang":"python","description":"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."},"warnings":[{"fix":"Migrate to `azure-identity` classes (e.g., `DefaultAzureCredential`) for authentication and ensure the parameter name is `credential`.","message":"The 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`.","severity":"breaking","affected_versions":"7.0.0b1 and higher (including 8.x)"},{"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`).","message":"Import paths for `ResourceGraphClient`, `ResourceGraphClientConfiguration`, and models were changed. For example, `ResourceGraphClient` must now be imported directly from `azure.mgmt.resourcegraph`.","severity":"breaking","affected_versions":"2.0.0 and higher (including 8.x)"},{"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.","message":"Azure 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always include an `order by` clause in your KQL queries if consistent, repeatable ordering of results is required.","message":"Queries without an `order by` clause may yield different results each time they are executed due to the distributed nature of the Resource Graph service.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}