Azure AI Projects Client Library

2.0.1 · active · verified Thu Apr 09

The Azure AI Projects Client Library for Python provides client access to manage Azure AI Studio resources, including projects, connections, and deployments. It is currently at version 2.0.1 and is actively developed by Microsoft, with regular updates to support new Azure AI Studio features and API versions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with Azure AI Studio using `DefaultAzureCredential` and list AI projects within a specified resource group. Ensure your environment is configured for Azure authentication (e.g., `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`, or logged in via Azure CLI).

import os
from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIStudioClient

# Replace with your Azure Subscription ID and Resource Group Name
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "YOUR_SUBSCRIPTION_ID")
resource_group_name = os.environ.get("AZURE_RESOURCE_GROUP", "YOUR_RESOURCE_GROUP_NAME")
project_name = os.environ.get("AZURE_AI_PROJECT_NAME", "my-ai-project")

try:
    # Authenticate using DefaultAzureCredential
    # This will try various methods: environment variables, managed identity, Azure CLI, etc.
    credential = DefaultAzureCredential()

    # Create a client for Azure AI Studio Projects
    client = AIStudioClient(
        credential=credential,
        subscription_id=subscription_id,
        resource_group_name=resource_group_name,
    )

    # List projects within the specified resource group
    print(f"Listing projects in resource group '{resource_group_name}'...")
    projects_iterator = client.projects.list(resource_group_name=resource_group_name)
    for project in projects_iterator:
        print(f"- Project Name: {project.name}, Location: {project.location}")

    # Example: Get a specific project (if it exists)
    # Make sure 'project_name' exists in your resource group
    # project = client.projects.get(project_name=project_name)
    # print(f"\nRetrieved project: {project.name}, ID: {project.id}")

except Exception as e:
    print(f"An error occurred: {e}")
    print("Please ensure AZURE_SUBSCRIPTION_ID, AZURE_RESOURCE_GROUP, and other necessary credentials are set.")

view raw JSON →