Azure Python SDK Reference Documentation

repository·main·Indexed 41 days ago

https://github.com/microsoftdocs/azure-docs-sdk-python

Technical reference documentation and API details for the Azure Python SDK. Includes guides for the azure-ai-agents library, including AgentsClient, ToolSet, and FileSearchTool, as well as deprecated information for azure-communication-administration and its replacements, azure-communication-identity and azure-communication-phonenumbers.

Tokens
301.1K
Snippets
780
Records
1K
Agent score
51%

What's inside Azure Python SDK

  1. Overview of Azure AI Inference client library capabilities

    main

    The Azure AI Inference client library (currently in preview, version 1.0.0b9) allows developers to interact with various AI models through a unified interface.

    Core capabilities:

    • Authenticate against supported AI services.
    • Retrieve metadata and information about AI models.
    • Perform chat completions.
    • Generate text embeddings.
    • Generate image embeddings.

    Supported services:

    • GitHub Models: Free-tier endpoint for various AI models.
    • Serverless API and Managed Compute endpoints: Models deployed via Azure AI Foundry.
    • Azure OpenAI Service: OpenAI models deployed via Azure AI Foundry. While the official openai library is recommended for production, this library allows for easy performance comparison between OpenAI and other models using consistent code.
  2. Overview of Azure AI Content Understanding

    main

    Azure AI Content Understanding is a multimodal AI service designed to transform unstructured content (documents, video, audio, and images) into structured, machine-readable data. It is optimized for retrieval-augmented generation (RAG) and automated workflows.

    Key capabilities include:

    • Document Extraction: Extract text, tables, figures, layout information, and structured markdown from PDFs, images (including handwriting), and Office documents.
    • Audio Analysis: Transcribe audio with speaker diarization and timing information.
    • Video Analysis: Extract visual frames, transcribe audio tracks, and generate structured summaries.
    • Prebuilt Analyzers: Use industry-specific analyzers for finance (invoices, receipts), identity (passports, licenses), mortgage (loan applications), procurement (purchase orders), and utilities.
    • Custom Analyzers: Build domain-specific analyzers for all four modalities.
    • Classification: Automatically categorize documents and video by type.
  3. Overview of Azure AI Projects client capabilities

    main

    The AIProjectClient provides access to several specialized sub-clients and properties for managing Microsoft Foundry resources:

    • .agents: Create and run Agents, including Hosted Agents.
    • .toolboxes: Create and version toolboxes that bundle tools and skills.
    • .deployments: Enumerate AI Models deployed to your project.
    • .connections: Enumerate connected Azure resources.
    • .datasets: Upload documents and create Datasets.
    • .indexes: Create and enumerate Search Indexes.
    • .evaluation_rules, .beta.evaluators, etc.: Tools to assess generative AI performance.
    • .beta.voice_agents: Build real-time speech-to-speech agents via WebSocket or telephony.
    • .beta.memory_stores: Manage memory for Agent conversations.

    Important regarding Preview features:

    • Features available through stable methods require setting allow_preview=True when constructing the client.
    • Features exposed via .beta sub-clients do not require this flag but are not recommended for production use.
  4. Capabilities of Azure ML Python SDK v2

    main

    The SDK v2 provides a consistent object model for several machine learning tasks:

    • Standalone Jobs: Run discrete activities locally or in the cloud. Supported types include Command (Python, R, Shell, etc.) and Sweep (hyperparameter sweeps).
    • Pipelines: Run series of commands stitched into a pipeline or use reusable Components.
    • Inferencing: Use models for Managed Online inferencing or batch inferencing.
    • Resource Management: Manage workspaces, compute, datastores, datasets, environments, and models.
    • AutoML: Run standalone training for tasks including Classification, Regression, Time Series Forecasting, Image Classification, Image Object Detection, Image Instance Segmentation, and NLP tasks (Text Classification, NER).
  5. Overview of Azure Identity credential classes

    main

    The Azure Identity client library provides various credential classes to authenticate applications against Azure services. These are categorized by their primary usage pattern:

    Credential Chains

    • DefaultAzureCredential: A simplified authentication experience for rapid development in Azure.
    • ChainedTokenCredential: Allows composing multiple credentials into a custom authentication flow.

    Azure-hosted Applications

    • EnvironmentCredential: Uses credentials specified in environment variables.
    • ManagedIdentityCredential: Uses the managed identity of an Azure resource (supports system-assigned and user-assigned).
    • WorkloadIdentityCredential: Supports Microsoft Entra Workload ID on Kubernetes.

    Service Principals

    • AzurePipelinesCredential: Supports Microsoft Entra Workload ID on Azure Pipelines.
    • CertificateCredential: Authenticates using a certificate.
    • ClientAssertionCredential: Authenticates using a signed client assertion.
    • ClientSecretCredential: Authenticates using a client secret.

    User Authentication

    • AuthorizationCodeCredential: Uses a previously obtained authorization code.
    • DeviceCodeCredential: Interactively authenticates on devices with limited UI.
    • InteractiveBrowserCredential: Interactively authenticates via the default system browser (Note: does not support GitHub Codespaces; use DeviceCodeCredential instead).
    • OnBehalfOfCredential: Propagates delegated user identity through a request chain.

    Development Tools

    • AzureCliCredential: Uses the Azure CLI.
    • AzureDeveloperCliCredential: Uses the Azure Developer CLI.
    • AzurePowerShellCredential: Uses Azure PowerShell.
    • VisualStudioCodeCredential: Uses Visual Studio Code.
  6. What is ActivityAgentServerHost?

    main

    ActivityAgentServerHost is an AgentServerHost subclass designed for Activity Protocol traffic. It exposes a protocol endpoint with required Foundry headers, tracing, and error behavior. Its primary purpose is to provide the POST /activity/messages endpoint for inbound activities.

    Depending on how you initialize it, it can either build a full M365 stack automatically or act as a thin wrapper for a custom request pipeline.

  7. What are Evaluators in Azure AI Evaluation?

    main

    Evaluators are classes or functions designed to measure the quality of outputs from language models or generative AI applications. They can be:

    1. Built-in Evaluators: Prebuilt classes provided by Microsoft for performance, quality, risk, and safety metrics.
    2. Custom Evaluators: User-defined code-based or prompt-based functions tailored to specific needs.

    Evaluators can be used individually by calling them directly, or collectively using the evaluate API.

  8. How Attestation works in Azure Attestation

    main

    Attestation is the process of validating evidence from a Trusted Execution Environment (TEE) to ensure it meets both the Azure baseline and customer-defined policies.

    Runtime and InitTime Data

    • RuntimeData: Data presented to the Intel SGX Quote generation logic or OpenEnclave APIs. If runtime_data is provided to the attest API, the service validates that the first 32 bytes of the report_data field in the SGX Quote/OE Report/OE Evidence matches the SHA256 hash of the runtime_data.
    • InitTime Data: Data used to configure the SGX enclave being attested. Note: InitTime data is not supported on Azure DCsv2-Series virtual machines.
  9. Handling Boolean data types in Azure Cosmos DB

    main

    There is a casing difference between Python's boolean types (True/False) and Cosmos DB's JSON boolean types (true/false). The Azure Cosmos DB Python SDK handles this conversion automatically:

    • Writing Data: When you create JSON documents using Python, use the standard Python True and False. The SDK will automatically convert these to lowercase true and false before storing them in Cosmos DB.
    • Reading Data: When you retrieve documents using the Python SDK, the SDK will automatically convert the stored true and false values back into Python's True and False types.
    • Verification: If you view the data directly in the Cosmos DB Portal's Data Explorer, you will see the lowercase true and false values stored in the database.
  10. How Web PubSub connection, recovery, and reconnection work

    main

    Understanding the lifecycle of a connection is critical for building resilient real-time apps:

    • Connection: An individual WebSocket connection to a Hub. Each WebPubSubClient maintains its own exclusive connection with a unique connection ID.
    • Recovery: If a client using a reliable protocol disconnects, the service attempts to re-establish the connection using the lost connection's ID. During this window, the service retains the client's context and messages. Recovery fails if the service returns error 1008 or if the attempt exceeds 30 seconds.
    • Reconnection: If recovery fails, the client starts a new connection with a new connection ID. The service treats this as a brand-new client. Because the context is lost, the client must rejoin its groups. The library handles this automatically via auto_rejoin_groups by default.
    • Hubs and Groups: A Hub is a logical grouping of connections (e.g., a 'chat' hub). A Group is a subset of connections within a hub (e.g., a specific 'room').