{"id":1374,"library":"azure-mgmt-network","title":"Azure Network Management Client Library","description":"The Microsoft Azure Network Management Client Library for Python provides programmatic access to manage network resources within Azure subscriptions, including virtual networks, public IPs, network security groups, and more. It is part of the broader Azure SDK for Python and is currently at version 30.2.0, with regular updates aligning with Azure service API changes.","status":"active","version":"30.2.0","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/network/azure-mgmt-network","tags":["azure","cloud","network","resource management","microsoft"],"install":[{"cmd":"pip install azure-mgmt-network azure-identity","lang":"bash","label":"Install core library and authentication"}],"dependencies":[{"reason":"Core management client functionality","package":"azure-mgmt-core","optional":false},{"reason":"Common Azure utilities and types","package":"azure-common","optional":false},{"reason":"Recommended for modern Azure authentication (e.g., DefaultAzureCredential)","package":"azure-identity","optional":true}],"imports":[{"symbol":"NetworkManagementClient","correct":"from azure.mgmt.network import NetworkManagementClient"},{"symbol":"DefaultAzureCredential","correct":"from azure.identity import DefaultAzureCredential"}],"quickstart":{"code":"import os\nfrom azure.identity import DefaultAzureCredential\nfrom azure.mgmt.network import NetworkManagementClient\n\n# Retrieve subscription ID from environment variable or replace with your ID\n# You must set AZURE_SUBSCRIPTION_ID, AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET\n# (or use other authentication methods supported by DefaultAzureCredential)\nSUBSCRIPTION_ID = os.environ.get(\"AZURE_SUBSCRIPTION_ID\", \"YOUR_SUBSCRIPTION_ID\")\n\nif SUBSCRIPTION_ID == \"YOUR_SUBSCRIPTION_ID\":\n    print(\"Warning: Please set the AZURE_SUBSCRIPTION_ID environment variable.\")\n    print(\"Or replace 'YOUR_SUBSCRIPTION_ID' in the code with your actual ID.\")\n    exit(1)\n\n# Authenticate using DefaultAzureCredential (recommended for most scenarios)\ntry:\n    credential = DefaultAzureCredential()\n    # For local development, ensure Azure CLI is logged in, or relevant env vars are set\n    credential.get_token(\"https://management.azure.com/.default\") # Test token acquisition\nexcept Exception as e:\n    print(f\"Authentication failed: {e}\")\n    print(\"Please ensure you are logged into Azure CLI, have appropriate environment variables set,\")\n    print(\"or use a different credential type.\")\n    exit(1)\n\n# Create a NetworkManagementClient instance\nnetwork_client = NetworkManagementClient(credential, SUBSCRIPTION_ID)\n\n# Example: List all Public IP Addresses in the subscription\nprint(\"Listing Public IP Addresses...\")\npublic_ips = network_client.public_ip_addresses.list_all()\n\nfor ip in public_ips:\n    print(f\"  - Name: {ip.name}, IP Address: {ip.ip_address or 'N/A'}, Resource Group: {ip.id.split('/')[4]}\")\n\nprint(\"Public IP Address listing complete.\")","lang":"python","description":"This quickstart demonstrates how to authenticate with Azure using `DefaultAzureCredential` and list all public IP addresses across your subscription using the `NetworkManagementClient`. Ensure you have `AZURE_SUBSCRIPTION_ID` and other necessary authentication environment variables set for `DefaultAzureCredential` to work correctly (e.g., `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET` for service principal, or log in via Azure CLI)."},"warnings":[{"fix":"Migrate your authentication code to use `azure.identity.DefaultAzureCredential` or other specific `azure.identity` credential types. Ensure `azure-identity` is installed via `pip install azure-identity`.","message":"Authentication method changes: The Azure SDK for Python (v20.0.0 and later) deprecated legacy credential classes like `ServicePrincipalCredentials` in `azure.common.credentials`. Modern authentication exclusively uses classes from `azure.identity` (e.g., `DefaultAzureCredential`).","severity":"breaking","affected_versions":"Prior to v20.0.0 (legacy) to v20.0.0 and later."},{"fix":"Always call `.result()` on the `LROPoller` object to wait for the operation's completion and retrieve its final outcome (e.g., the created resource). Example: `virtual_network = network_client.virtual_networks.begin_create_or_update(...).result()`.","message":"Long-Running Operations (LROs) now return a poller object. Operations like `create_or_update`, `delete`, and `begin_xyz` (prefixed) for resource provisioning or modification are asynchronous. They return an `LROPoller` object, not the final resource or `None` directly.","severity":"gotcha","affected_versions":"All versions, but the expectation of immediate return changed significantly around v20.0.0."},{"fix":"Refer to the official Azure SDK for Python migration guides for `azure-mgmt-network` to update method calls and model property access. List methods now return auto-paginated iterators, so direct iteration over the result is sufficient.","message":"Significant API changes and refactoring occurred around v20.0.0. This includes changes to client method signatures, model classes, and how collection methods (`list`) are handled. Direct access to `.value` on list results is no longer necessary; iterators are returned.","severity":"breaking","affected_versions":"Prior to v20.0.0 to v20.0.0 and later."}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}