{"id":1364,"library":"azure-mgmt-eventhub","title":"Azure Event Hub Management Client","description":"The `azure-mgmt-eventhub` library provides a client for managing Azure Event Hub resources, including Event Hub namespaces, Event Hubs, Consumer Groups, and Disaster Recovery configurations. It is part of the Azure SDK for Python, currently at version 11.2.0, and receives regular updates for bug fixes, new features, and API changes.","status":"active","version":"11.2.0","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/eventhub/azure-mgmt-eventhub","tags":["azure","eventhub","management","cloud"],"install":[{"cmd":"pip install azure-mgmt-eventhub azure-identity","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for authentication with Azure services using modern credential types like DefaultAzureCredential.","package":"azure-identity"}],"imports":[{"symbol":"EventHubManagementClient","correct":"from azure.mgmt.eventhub import EventHubManagementClient"},{"symbol":"DefaultAzureCredential","correct":"from azure.identity import DefaultAzureCredential"}],"quickstart":{"code":"import os\nfrom azure.identity import DefaultAzureCredential\nfrom azure.mgmt.eventhub import EventHubManagementClient\n\n# Set these environment variables or replace with actual values\n# AZURE_SUBSCRIPTION_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, AZURE_TENANT_ID\n# Or log in via Azure CLI: `az login`\nSUBSCRIPTION_ID = os.environ.get(\"AZURE_SUBSCRIPTION_ID\", \"<your-subscription-id>\")\nRESOURCE_GROUP_NAME = os.environ.get(\"AZURE_RESOURCE_GROUP_NAME\", \"<existing-resource-group>\")\nEVENTHUB_NAMESPACE_NAME = os.environ.get(\"AZURE_EVENTHUB_NAMESPACE_NAME\", \"<existing-eventhub-namespace>\")\n\ndef main():\n    if SUBSCRIPTION_ID == \"<your-subscription-id>\" or \\\n       RESOURCE_GROUP_NAME == \"<existing-resource-group>\" or \\\n       EVENTHUB_NAMESPACE_NAME == \"<existing-eventhub-namespace>\":\n        print(\"Please set AZURE_SUBSCRIPTION_ID, AZURE_RESOURCE_GROUP_NAME, and AZURE_EVENTHUB_NAMESPACE_NAME environment variables or replace placeholders.\")\n        return\n\n    credential = DefaultAzureCredential()\n    client = EventHubManagementClient(credential, SUBSCRIPTION_ID)\n\n    print(f\"Listing Event Hub Namespaces in resource group '{RESOURCE_GROUP_NAME}':\")\n    try:\n        namespaces = client.namespaces.list_by_resource_group(RESOURCE_GROUP_NAME)\n        for namespace in namespaces:\n            print(f\"- {namespace.name} (Location: {namespace.location})\")\n            \n            # List Event Hubs within this namespace\n            print(f\"  Listing Event Hubs in namespace '{namespace.name}':\")\n            event_hubs = client.event_hubs.list_by_namespace(RESOURCE_GROUP_NAME, namespace.name)\n            for event_hub in event_hubs:\n                print(f\"  - {event_hub.name} (Partitions: {event_hub.partition_count})\")\n    except Exception as e:\n        print(f\"An error occurred: {e}\")\n        print(\"Ensure the resource group and namespace exist and your credentials have access.\")\n\nif __name__ == \"__main__\":\n    main()","lang":"python","description":"This quickstart demonstrates how to authenticate with `DefaultAzureCredential` and use the `EventHubManagementClient` to list existing Event Hub namespaces and Event Hubs within a specified resource group. Ensure you have an existing Azure resource group and Event Hub namespace, and appropriate environment variables set for authentication or log in via Azure CLI (`az login`)."},"warnings":[{"fix":"Migrate your authentication code to use `azure.identity.DefaultAzureCredential` or other `azure.identity` credential types. Install `azure-identity` if not already present (`pip install azure-identity`).","message":"Older versions (prior to v4/v5) of Azure management libraries used `msrestazure.azure_active_directory` for authentication. Current stable versions (v11+) require `azure.identity` for credential handling.","severity":"breaking","affected_versions":"< 4.0.0"},{"fix":"Refer to the official documentation and samples for the specific version (11.x.x) you are using. Methods like `create_or_update` now typically accept dedicated model objects (e.g., `EventHubNamespace`) directly, rather than individual parameters.","message":"The API surface and method signatures for creating and updating resources have significantly changed across major versions, particularly from older track 1 SDKs to the current track 2 SDKs. Object models for resource properties are also different.","severity":"breaking","affected_versions":"All versions, especially major transitions (e.g., < 4.0.0 to 11.x.x)"},{"fix":"Always iterate directly over the `ItemPaged` object or explicitly convert it to a list if necessary. Do not assume it's a synchronous list operation.","message":"Many list operations (e.g., `list_by_resource_group`, `list_by_namespace`) return `azure.core.paging.ItemPaged` objects, which are iterators. If you expect a plain list, you might need to convert it (e.g., `list(client.namespaces.list_by_resource_group(...))`) if you need random access or length upfront.","severity":"gotcha","affected_versions":">= 4.0.0"},{"fix":"Always call `.result()` on the poller returned by `begin_*` methods (e.g., `poller = client.namespaces.begin_create_or_update(...); namespace = poller.result()`).","message":"Resource creation methods (e.g., `namespaces.begin_create_or_update`) are often long-running operations and return a poller object. You must call `.result()` on the poller to wait for the operation to complete and get the final resource object.","severity":"gotcha","affected_versions":">= 4.0.0"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}