Azure AI Projects Client Library
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
- breaking Version 2.0.0 introduced significant API changes and a new design for interacting with Azure AI Studio. Code written for 1.x versions will likely require substantial updates.
- gotcha Authentication requires proper setup for `DefaultAzureCredential`. Without correct environment variables or Azure CLI login, the client will fail to authenticate.
- gotcha Operations often require context like `subscription_id` and `resource_group_name` for client initialization, and potentially the specific AI Studio project name for resource-specific actions.
Install
-
pip install azure-ai-projects azure-identity
Imports
- AIStudioClient
from azure.ai.projects import AIStudioClient
- DefaultAzureCredential
from azure.identity import DefaultAzureCredential
Quickstart
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.")