Microsoft Azure Web Apps Management Client Library for Python
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Management of Azure Static Web Apps including build configuration, custom domains, user authentication, and API integration.
azure.mgmt.web.operations.StaticSitesOperationsclient.static_sitesfrom azure.mgmt.web import WebSiteManagementClient
from azure.mgmt.web.models import (
StaticSiteARMResource, StaticSiteBuildARMResource,
StaticSiteUserARMResource, StaticSiteCustomDomainOverviewARMResource
)
from azure.identity import DefaultAzureCredentialfrom azure.mgmt.web import WebSiteManagementClient
from azure.identity import DefaultAzureCredential
credential = DefaultAzureCredential()
client = WebSiteManagementClient(credential, subscription_id)
# List all static sites in subscription
static_sites = client.static_sites.list()
for site in static_sites:
print(f"Site: {site.name}, Location: {site.location}")
# Get specific static site details
site_details = client.static_sites.get_static_site(
resource_group_name="my-resource-group",
name="my-static-site"
)
print(f"Default hostname: {site_details.default_hostname}")Create a new static web app or update an existing one.
def create_or_update_static_site(
self,
resource_group_name: str,
name: str,
static_site_envelope: StaticSiteARMResource,
**kwargs
) -> StaticSiteARMResource:
"""
Create or update a static site.
Args:
resource_group_name: Name of the resource group
name: Name of the static site
static_site_envelope: Static site configuration
Returns:
StaticSiteARMResource object
"""Usage Example:
from azure.mgmt.web.models import StaticSiteARMResource, StaticSiteBuildProperties
# Create a new static site
static_site_config = StaticSiteARMResource(
location="Central US",
sku=SkuDescription(name="Free", tier="Free"),
repository_url="https://github.com/user/my-static-site",
branch="main",
build_properties=StaticSiteBuildProperties(
app_location="/",
api_location="api",
output_location="dist"
)
)
static_site = client.static_sites.create_or_update_static_site(
resource_group_name="my-resource-group",
name="my-static-site",
static_site_envelope=static_site_config
)
print(f"Created static site: {static_site.name}")Retrieve details for a specific static site.
def get_static_site(
self,
resource_group_name: str,
name: str,
**kwargs
) -> StaticSiteARMResource:
"""
Get static site details.
Args:
resource_group_name: Name of the resource group
name: Name of the static site
Returns:
StaticSiteARMResource object
"""Get all static sites in a subscription or resource group.
def list(self, **kwargs) -> List[StaticSiteARMResource]:
"""
List all static sites in the subscription.
Returns:
List of StaticSiteARMResource objects
"""
def list_static_sites_by_resource_group(
self,
resource_group_name: str,
**kwargs
) -> List[StaticSiteARMResource]:
"""
List static sites in a resource group.
Args:
resource_group_name: Name of the resource group
Returns:
List of StaticSiteARMResource objects
"""Remove a static site and all its resources.
def delete_static_site(
self,
resource_group_name: str,
name: str,
**kwargs
) -> None:
"""
Delete a static site.
Args:
resource_group_name: Name of the resource group
name: Name of the static site
"""Get all builds for a static site.
def get_static_site_builds(
self,
resource_group_name: str,
name: str,
**kwargs
) -> List[StaticSiteBuildARMResource]:
"""
List builds for the static site.
Args:
resource_group_name: Name of the resource group
name: Name of the static site
Returns:
List of StaticSiteBuildARMResource objects
"""Retrieve details for a specific build.
def get_static_site_build(
self,
resource_group_name: str,
name: str,
pr_id: str,
**kwargs
) -> StaticSiteBuildARMResource:
"""
Get build details.
Args:
resource_group_name: Name of the resource group
name: Name of the static site
pr_id: Pull request ID or environment name
Returns:
StaticSiteBuildARMResource object
"""Remove a specific build environment.
def delete_static_site_build(
self,
resource_group_name: str,
name: str,
pr_id: str,
**kwargs
) -> None:
"""
Delete a build environment.
Args:
resource_group_name: Name of the resource group
name: Name of the static site
pr_id: Pull request ID or environment name
"""Usage Example:
# List all builds
builds = client.static_sites.get_static_site_builds(
resource_group_name="my-resource-group",
name="my-static-site"
)
for build in builds:
print(f"Build: {build.name}, Status: {build.status}")
# Get specific build details
build_details = client.static_sites.get_static_site_build(
resource_group_name="my-resource-group",
name="my-static-site",
pr_id="1"
)
print(f"Build hostname: {build_details.hostname}")Get all custom domains configured for a static site.
def list_static_site_custom_domains(
self,
resource_group_name: str,
name: str,
**kwargs
) -> List[StaticSiteCustomDomainOverviewARMResource]:
"""
List custom domains for the static site.
Args:
resource_group_name: Name of the resource group
name: Name of the static site
Returns:
List of StaticSiteCustomDomainOverviewARMResource objects
"""Add a custom domain to a static site.
def create_or_update_static_site_custom_domain(
self,
resource_group_name: str,
name: str,
domain_name: str,
**kwargs
) -> StaticSiteCustomDomainOverviewARMResource:
"""
Create or update a custom domain.
Args:
resource_group_name: Name of the resource group
name: Name of the static site
domain_name: Custom domain name
Returns:
StaticSiteCustomDomainOverviewARMResource object
"""Check if a custom domain can be added to the static site.
def validate_custom_domain_can_be_added_to_static_site(
self,
resource_group_name: str,
name: str,
domain_name: str,
**kwargs
) -> None:
"""
Validate that a custom domain can be added.
Args:
resource_group_name: Name of the resource group
name: Name of the static site
domain_name: Domain name to validate
"""Usage Example:
# Validate custom domain
client.static_sites.validate_custom_domain_can_be_added_to_static_site(
resource_group_name="my-resource-group",
name="my-static-site",
domain_name="www.mydomain.com"
)
# Add custom domain
custom_domain = client.static_sites.create_or_update_static_site_custom_domain(
resource_group_name="my-resource-group",
name="my-static-site",
domain_name="www.mydomain.com"
)
print(f"Custom domain added: {custom_domain.domain_name}")Get all users with access to the static site.
def list_static_site_users(
self,
resource_group_name: str,
name: str,
authprovider: str,
**kwargs
) -> List[StaticSiteUserARMResource]:
"""
List users for the static site.
Args:
resource_group_name: Name of the resource group
name: Name of the static site
authprovider: Authentication provider name
Returns:
List of StaticSiteUserARMResource objects
"""Modify user permissions for the static site.
def update_static_site_user(
self,
resource_group_name: str,
name: str,
authprovider: str,
userid: str,
static_site_user_envelope: StaticSiteUserARMResource,
**kwargs
) -> StaticSiteUserARMResource:
"""
Update user roles and permissions.
Args:
resource_group_name: Name of the resource group
name: Name of the static site
authprovider: Authentication provider
userid: User ID
static_site_user_envelope: User configuration
Returns:
Updated StaticSiteUserARMResource object
"""Remove user access from the static site.
def delete_static_site_user(
self,
resource_group_name: str,
name: str,
authprovider: str,
userid: str,
**kwargs
) -> None:
"""
Delete user access.
Args:
resource_group_name: Name of the resource group
name: Name of the static site
authprovider: Authentication provider
userid: User ID
"""Retrieve configuration settings for the static site.
def get_static_site_functions_app_settings(
self,
resource_group_name: str,
name: str,
**kwargs
) -> StringDictionary:
"""
Get function app settings for the static site.
Args:
resource_group_name: Name of the resource group
name: Name of the static site
Returns:
StringDictionary with settings
"""Modify configuration settings.
def create_or_update_static_site_functions_app_settings(
self,
resource_group_name: str,
name: str,
app_settings: StringDictionary,
**kwargs
) -> StringDictionary:
"""
Update function app settings.
Args:
resource_group_name: Name of the resource group
name: Name of the static site
app_settings: Application settings
Returns:
Updated StringDictionary
"""Usage Example:
from azure.mgmt.web.models import StringDictionary
# Get current settings
current_settings = client.static_sites.get_static_site_functions_app_settings(
resource_group_name="my-resource-group",
name="my-static-site"
)
# Update settings
new_settings = StringDictionary(
properties={
"API_KEY": "your-api-key",
"DATABASE_URL": "your-database-url",
"ENVIRONMENT": "production"
}
)
updated_settings = client.static_sites.create_or_update_static_site_functions_app_settings(
resource_group_name="my-resource-group",
name="my-static-site",
app_settings=new_settings
)class StaticSiteARMResource:
"""Represents a static site resource."""
id: Optional[str]
name: Optional[str]
type: Optional[str]
location: str
tags: Optional[Dict[str, str]]
sku: Optional[SkuDescription]
default_hostname: Optional[str]
repository_url: Optional[str]
branch: Optional[str]
custom_domains: Optional[List[str]]
private_endpoint_connections: Optional[List[ResponseMessageEnvelopeRemotePrivateEndpointConnection]]
build_properties: Optional[StaticSiteBuildProperties]
content_distribution_endpoint: Optional[str]
key_vault_reference_identity: Optional[str]
user_provided_function_apps: Optional[List[StaticSiteUserProvidedFunctionApp]]class StaticSiteBuildARMResource:
"""Represents a static site build."""
id: Optional[str]
name: Optional[str]
type: Optional[str]
build_id: Optional[str]
hostname: Optional[str]
created_time_utc: Optional[datetime]
last_updated_on: Optional[datetime]
status: Optional[str]
user_provided_function_apps: Optional[List[StaticSiteUserProvidedFunctionApp]]class StaticSiteCustomDomainOverviewARMResource:
"""Represents a custom domain for a static site."""
id: Optional[str]
name: Optional[str]
type: Optional[str]
domain_name: Optional[str]
created_date: Optional[datetime]
status: Optional[str]
validation_token: Optional[str]
error_message: Optional[str]class StaticSiteUserARMResource:
"""Represents a user with access to a static site."""
id: Optional[str]
name: Optional[str]
type: Optional[str]
provider: Optional[str]
user_id: Optional[str]
display_name: Optional[str]
roles: Optional[str]Install with Tessl CLI
npx tessl i tessl/pypi-azure-mgmt-web