Azure Resource Templatespecs Management Client Library for Python
The `azure-mgmt-resource-templatespecs` library is the Microsoft Azure Resource Templatespecs Management Client Library for Python. It allows developers to programmatically manage Azure Template Specs, which are a feature for storing, managing, and versioning Azure Resource Manager (ARM) templates as first-party Azure resources with integrated access control. The current version is 1.0.0b1, and as part of the Azure SDK for Python, it follows an active release cadence with frequent updates, often including beta releases before stable versions.
Warnings
- breaking The `templatespecs` module has been separated from the `azure-mgmt-resource` package into its own independent package, `azure-mgmt-resource-templatespecs`. If you previously imported `TemplateSpecsClient` via `from azure.mgmt.resource import TemplateSpecsClient`, you must update your code to import directly from `azure.mgmt.resource.templatespecs`.
- gotcha Authentication with Azure services often requires setting specific environment variables for `DefaultAzureCredential` to work correctly. Without these, authentication attempts may fail.
- gotcha As a beta package (`1.0.0b1`), the API surface or behavior of `azure-mgmt-resource-templatespecs` may change before its stable 1.0.0 release, potentially introducing breaking changes without a major version increment.
- gotcha When deploying ARM templates using Template Specs, especially with linked templates, you might encounter 'Unable to retrieve the template artifact' errors if linked templates are not accessible (e.g., local files not uploaded or incorrect paths).
Install
-
pip install azure-mgmt-resource-templatespecs azure-identity
Imports
- TemplateSpecsClient
from azure.mgmt.resource.templatespecs import TemplateSpecsClient
- DefaultAzureCredential
from azure.identity import DefaultAzureCredential
- TemplateSpecsClient
Quickstart
import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.resource.templatespecs import TemplateSpecsClient
# Set environment variables for authentication and subscription:
# AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET (for service principal)
# AZURE_SUBSCRIPTION_ID
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "")
# Authenticate using DefaultAzureCredential
# This credential type attempts to authenticate via various methods
# (environment variables, managed identity, Azure CLI, etc.)
credential = DefaultAzureCredential()
# Create a TemplateSpecsClient
client = TemplateSpecsClient(credential=credential, subscription_id=subscription_id)
# Example: List all template specs in the subscription
print("Listing Template Specs...")
for template_spec in client.template_specs.list_by_subscription():
print(f" Template Spec Name: {template_spec.name}, Location: {template_spec.location}")
# Note: This is a basic example. For more complex operations like creating,
# updating, or deploying Template Specs, refer to the official Azure SDK samples.