azurecloud

list of Azure APIs Script


while trying to gather all AWS APIs I use:

> import boto3

# Create a new session
session = boto3.Session()

# Get a list of available services
available_services = session.get_available_services()


# Write the list to a file
with open('aws_services.txt', 'w') as f:
    for service in sorted(available_services):
        f.write(service + '\n')

Is/What a similar way of doing it in Azure?

Thanks!


Solution

  • I tried in my environment and got the below results:

    Is/What is a similar way of doing it in Azure?

    To get the available Azure services and store them in a text file, you can use the Azure SDK for Python and the azure-mgmt-resource and azure-identity packages.

    First, try to log in with your Azure account using the command in the terminal:

    Command:

    az-login
    

    Code:

    from azure.identity import DefaultAzureCredential
    from azure.mgmt.resource import ResourceManagementClient
    
    # Create a ResourceManagementClient using your Azure credentials
    credential = DefaultAzureCredential()
    subscription_id = 'Your azure subscription ID'
    resource_client = ResourceManagementClient(credential, subscription_id)
    
    # Retrieve the list of Azure services
    providers = resource_client.providers.list()
    
    # Write the list of services to a text file
    with open('azure_services.txt', 'w') as f:
        for provider in providers:
            f.write(provider.namespace + '\n')
    

    The above code executed and got the available service and stored in azure_service.txt format.

    Text file.

    enter image description here

    If you need to get the available service without text format you can use the below code:

    Commands:

    from azure.identity import DefaultAzureCredential
    from azure.mgmt.resource import ResourceManagementClient
    
    credential = DefaultAzureCredential()
    subscription_id = 'Your azure subscription ID'
    resource_client = ResourceManagementClient(credential, subscription_id)
    providers = resource_client.providers.list()
    for provider in providers:
        print(provider.namespace)
    

    Output: enter image description here

    Reference: azure-samples-python-management/manage_providers.py at main · Azure-Samples/azure-samples-python-management (github.com)