Registry / azure / azure-mgmt-eventgrid

azure-mgmt-eventgrid

JSON →
library10.4.0pypypi✓ verified 26d ago

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.

pip install azure-mgmt-eventgrid
INSTALL
IMPORT
SIG · AZURE-MGMT-EVENTGR
A
azure-mgmt-eventgrid
azurepythonv10.4.0
Install
2.8s avg
Import
651ms
Disk
27MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v10.4.0 · 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.690s · 28.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.8s · import 0.612s · 29MB
27MB installed
● package 27MB
Code
Verified usage

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

EventGridManagementClient
from azure.mgmt.eventgrid import EventGridManagementClient
DefaultAzureCredential
from azure.identity import DefaultAzureCredential
Required for authenticating with Azure services. Install separately with `pip install azure-identity`.

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.

import os from azure.identity import DefaultAzureCredential from azure.mgmt.eventgrid import EventGridManagementClient # Set your Azure Subscription ID as an environment variable or replace directly # Example: export AZURE_SUBSCRIPTION_ID="<your-subscription-id>" subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "") if not subscription_id: raise ValueError("AZURE_SUBSCRIPTION_ID environment variable not set.") # Acquire a credential object using DefaultAzureCredential # This will attempt to authenticate via various methods: # Environment variables, Managed Identity, Azure CLI, VS Code, etc. # For local development, ensure you are logged in via Azure CLI (`az login`) credential = DefaultAzureCredential() # Create the Event Grid Management Client client = EventGridManagementClient(credential, subscription_id) print(f"Listing Event Grid topics in subscription: {subscription_id}") try: # List all Event Grid topics in the subscription topics = client.topics.list_by_subscription() for topic in topics: print(f"- Topic Name: {topic.name}, Location: {topic.location}") except Exception as e: print(f"An error occurred: {e}") print("Ensure you have 'Contributor' or 'Owner' role on the subscription.")
Debug
Known issues
breakingAzure 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.
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.
affects: All major version upgrades (e.g., v9.x.x to v10.x.x)
gotchaResource 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.
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.
affects: All versions
gotchaThe `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.
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).
affects: All versions
gotchaAuthentication 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`).
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.
affects: All versions
gotchaTo use `DefaultAzureCredential` or any other credential from `azure.identity` for authenticating with Azure services, the `azure-identity` package must be installed. A `ModuleNotFoundError` for `azure.identity` indicates this package is missing from your environment.
fix
Ensure the `azure-identity` package is installed in your Python environment. You can typically install it using pip: `pip install azure-identity`.
affects: All versions
gotchaTo use `DefaultAzureCredential` or other credential types from the Azure Identity library, the `azure-identity` package must be installed. This error typically means the package was not included in your project's dependencies.
fix
Ensure `azure-identity` is listed in your `requirements.txt` or installed via `pip install azure-identity`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'azure.mgmt.eventgrid'
The `azure-mgmt-eventgrid` package is not installed in the current Python environment.
fix
pip install azure-mgmt-eventgrid
ClientAuthenticationError: DefaultAzureCredential failed to retrieve a token from the included credentials.
The application cannot authenticate with Azure due to missing or incorrect environment variables for `DefaultAzureCredential`, or insufficient permissions for the assigned identity.
fix
Ensure `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, and `AZURE_CLIENT_SECRET` (or other credential-specific environment variables) are correctly set, and that the authenticated identity has the necessary Event Grid roles (e.g., 'Event Grid Data Sender' or 'Event Grid Contributor').
Code=ResourceNotFound; Message=The Resource 'Microsoft.EventGrid/topics/{topic_name}' under resource group {resource_group_name} was not found.
The specified Azure Event Grid resource (e.g., topic, domain, or event subscription) does not exist, the name, resource group, or subscription ID is incorrect, or the authenticated identity lacks permissions to view it.
fix
Verify the resource name, resource group name, and subscription ID, and ensure the authenticated identity has 'Reader' or appropriate Event Grid permissions on the resource.
AttributeError: 'EventGridManagementClient' object has no attribute 'topics'
The code is attempting to access an operation directly on the `EventGridManagementClient` that is part of an operation group (like 'topics', 'event_subscriptions', 'domains') or a method that has been renamed or removed in a different library version.
fix
Access operations through their respective operation groups (e.g., `client.topics.create_or_update(...)` instead of `client.create_or_update_topic(...)`) and consult the library's documentation for the correct API usage for your installed version.
Upgrade
Version history
10.4.0latest on PyPI · released Mar 24, 2025
Audit
Dependencies
azure-mgmt-corerequiredRequired for core Azure management client functionalities.
azure-identityoptionalHighly recommended for authentication with Azure services, providing various credential types.
Agent activity
28 hits · last 30 days
node
22
OpenAI (training)
1
Resources
azure-mgmt-eventgrid — pip install azure-mgmt-eventgrid · libregistry