{"id":1363,"library":"azure-mgmt-eventgrid","title":"Azure Event Grid Management Client Library","description":"The Microsoft Azure Event Grid Management Client Library for Python allows developers to programmatically manage Event Grid resources such as topics, domains, and event subscriptions within Azure. It is part of the Azure SDK for Python (Track 2) and follows a regular release cadence, often aligning with updates to the underlying Azure REST APIs. The current stable version is 10.4.0.","status":"active","version":"10.4.0","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python","tags":["azure","cloud","event-grid","management","sdk","resource-management"],"install":[{"cmd":"pip install azure-mgmt-eventgrid","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for core Azure management client functionalities.","package":"azure-mgmt-core","optional":false},{"reason":"Highly recommended for authentication with Azure services, providing various credential types.","package":"azure-identity","optional":true}],"imports":[{"symbol":"EventGridManagementClient","correct":"from azure.mgmt.eventgrid import EventGridManagementClient"},{"note":"Required for authenticating with Azure services. Install separately with `pip install azure-identity`.","symbol":"DefaultAzureCredential","correct":"from azure.identity import DefaultAzureCredential"}],"quickstart":{"code":"import os\nfrom azure.identity import DefaultAzureCredential\nfrom azure.mgmt.eventgrid import EventGridManagementClient\n\n# Set your Azure Subscription ID as an environment variable or replace directly\n# Example: export AZURE_SUBSCRIPTION_ID=\"<your-subscription-id>\"\nsubscription_id = os.environ.get(\"AZURE_SUBSCRIPTION_ID\", \"\")\n\nif not subscription_id:\n    raise ValueError(\"AZURE_SUBSCRIPTION_ID environment variable not set.\")\n\n# Acquire a credential object using DefaultAzureCredential\n# This will attempt to authenticate via various methods:\n# Environment variables, Managed Identity, Azure CLI, VS Code, etc.\n# For local development, ensure you are logged in via Azure CLI (`az login`)\ncredential = DefaultAzureCredential()\n\n# Create the Event Grid Management Client\nclient = EventGridManagementClient(credential, subscription_id)\n\nprint(f\"Listing Event Grid topics in subscription: {subscription_id}\")\n\ntry:\n    # List all Event Grid topics in the subscription\n    topics = client.topics.list_by_subscription()\n    for topic in topics:\n        print(f\"- Topic Name: {topic.name}, Location: {topic.location}\")\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Ensure you have 'Contributor' or 'Owner' role on the subscription.\")\n","lang":"python","description":"This quickstart demonstrates how to authenticate with Azure using `DefaultAzureCredential` and then list all Event Grid topics within a specified Azure subscription using the `EventGridManagementClient`. Ensure you have the `AZURE_SUBSCRIPTION_ID` environment variable set and have appropriate permissions in Azure."},"warnings":[{"fix":"Consult the official migration guide and release notes for the specific library version. Update your code to reflect new model structures or method signatures.","message":"Azure SDK for Python libraries (Track 2) often introduce breaking changes between major versions. These changes typically align with updates to the underlying Azure REST APIs or the SDK guidelines, affecting resource models, method signatures, or parameter names. Always review release notes when upgrading to a new major version.","severity":"breaking","affected_versions":"All major version upgrades (e.g., v9.x.x to v10.x.x)"},{"fix":"Implement polling mechanisms or introduce delays to wait for resources to reach a stable `succeeded` provisioning state before attempting subsequent operations. The Azure SDK may provide `begin_create_or_update` methods that return long-running operation pollers.","message":"Resource provisioning in Azure (like creating an Event Grid topic or domain) can be an asynchronous operation. Chaining dependent operations too quickly after a create/update call might result in 'resource not found' or 'resource not ready' errors due to eventual consistency.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure you are using the correct library for your task: `azure-mgmt-eventgrid` for resource management (create, update, delete topics/domains) and `azure-eventgrid` for data plane operations (send/receive events).","message":"The `azure-mgmt-eventgrid` library manages Event Grid resources. For publishing or consuming events, you need `azure-eventgrid` (the data plane SDK), which is a separate library with different imports and client objects.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For local development, ensure you've run `az login` or configured the necessary environment variables for your chosen credential type. For production, consider Managed Identities for Azure resources.","message":"Authentication with Azure services locally requires setting up `DefaultAzureCredential` correctly. Common issues include not being logged in via `az login` (Azure CLI) or missing required environment variables for service principal authentication (`AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`).","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}