Microsoft Azure Web Apps Management Client Library for Python
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Comprehensive deployment operations including source control integration, continuous deployment, deployment slots, backups, and application deployment from various sources.
azure.mgmt.web.operations.WebAppsOperationsclient.web_appsfrom azure.mgmt.web import WebSiteManagementClient
from azure.mgmt.web.models import (
Deployment, BackupRequest, BackupItem, RestoreRequest,
SiteSourceControl, SourceControl
)
from azure.identity import DefaultAzureCredentialfrom azure.mgmt.web import WebSiteManagementClient
from azure.identity import DefaultAzureCredential
credential = DefaultAzureCredential()
client = WebSiteManagementClient(credential, subscription_id)
# List all deployments for a web app
deployments = client.web_apps.list_deployments(
resource_group_name="my-resource-group",
name="my-web-app"
)
for deployment in deployments:
print(f"Deployment ID: {deployment.id}")
print(f"Status: {deployment.status}")
print(f"Author: {deployment.author}")
print(f"Message: {deployment.message}")Get all deployments for a web application.
def list_deployments(
self,
resource_group_name: str,
name: str,
**kwargs
) -> List[Deployment]:
"""
List all deployments for the specified web app.
Args:
resource_group_name: Name of the resource group
name: Name of the web app
Returns:
List of Deployment objects
"""Usage Example:
# List deployments for a web app
deployments = client.web_apps.list_deployments(
resource_group_name="my-resource-group",
name="my-web-app"
)
for deployment in deployments:
print(f"ID: {deployment.id}, Status: {deployment.status}")Retrieve details for a specific deployment.
def get_deployment(
self,
resource_group_name: str,
name: str,
id: str,
**kwargs
) -> Deployment:
"""
Get deployment details by ID.
Args:
resource_group_name: Name of the resource group
name: Name of the web app
id: Deployment ID
Returns:
Deployment object
"""Create a new deployment for a web application.
def create_deployment(
self,
resource_group_name: str,
name: str,
id: str,
deployment: Deployment,
**kwargs
) -> Deployment:
"""
Create a new deployment.
Args:
resource_group_name: Name of the resource group
name: Name of the web app
id: Deployment ID
deployment: Deployment configuration
Returns:
Created Deployment object
"""Usage Example:
from azure.mgmt.web.models import Deployment
from datetime import datetime
# Create a new deployment
deployment_config = Deployment(
status=4, # Success status
author="Automated Deploy",
author_email="deploy@company.com",
message="Automated deployment from CI/CD pipeline",
start_time=datetime.utcnow(),
end_time=datetime.utcnow()
)
deployment = client.web_apps.create_deployment(
resource_group_name="my-resource-group",
name="my-web-app",
id="deployment-001",
deployment=deployment_config
)Remove a deployment record.
def delete_deployment(
self,
resource_group_name: str,
name: str,
id: str,
**kwargs
) -> None:
"""
Delete a deployment by ID.
Args:
resource_group_name: Name of the resource group
name: Name of the web app
id: Deployment ID
"""Retrieve source control settings for a web app.
def get_source_control(
self,
resource_group_name: str,
name: str,
**kwargs
) -> SiteSourceControl:
"""
Get source control configuration.
Args:
resource_group_name: Name of the resource group
name: Name of the web app
Returns:
SiteSourceControl object
"""Configure source control integration.
def create_or_update_source_control(
self,
resource_group_name: str,
name: str,
site_source_control: SiteSourceControl,
**kwargs
) -> SiteSourceControl:
"""
Create or update source control configuration.
Args:
resource_group_name: Name of the resource group
name: Name of the web app
site_source_control: Source control configuration
Returns:
Updated SiteSourceControl object
"""Usage Example:
from azure.mgmt.web.models import SiteSourceControl
# Configure GitHub integration
source_control = SiteSourceControl(
repo_url="https://github.com/user/repository.git",
branch="main",
is_manual_integration=False,
is_mercurial=False,
deployment_rollback_enabled=True
)
updated_source_control = client.web_apps.create_or_update_source_control(
resource_group_name="my-resource-group",
name="my-web-app",
site_source_control=source_control
)Trigger a manual sync from the configured repository.
def sync_repository(
self,
resource_group_name: str,
name: str,
**kwargs
) -> None:
"""
Sync the repository and trigger deployment.
Args:
resource_group_name: Name of the resource group
name: Name of the web app
"""Usage Example:
# Trigger manual repository sync
client.web_apps.sync_repository(
resource_group_name="my-resource-group",
name="my-web-app"
)Create a backup of a web application.
def backup(
self,
resource_group_name: str,
name: str,
request: BackupRequest,
**kwargs
) -> BackupItem:
"""
Create a backup of the web app.
Args:
resource_group_name: Name of the resource group
name: Name of the web app
request: Backup configuration
Returns:
BackupItem object representing the created backup
"""Usage Example:
from azure.mgmt.web.models import BackupRequest, DatabaseBackupSetting
# Configure backup settings
backup_request = BackupRequest(
backup_name="automated-backup-001",
enabled=True,
storage_account_url="https://mystorageaccount.blob.core.windows.net/backups",
backup_schedule=BackupSchedule(
frequency_interval=1,
frequency_unit="Day",
keep_at_least_one_backup=True,
retention_period_in_days=30
),
databases=[
DatabaseBackupSetting(
database_type="SqlAzure",
name="MyDatabase",
connection_string_name="DefaultConnection"
)
]
)
# Create backup
backup = client.web_apps.backup(
resource_group_name="my-resource-group",
name="my-web-app",
request=backup_request
)
print(f"Backup created: {backup.name}")Retrieve all backups for a web application.
def list_backups(
self,
resource_group_name: str,
name: str,
**kwargs
) -> List[BackupItem]:
"""
List all backups for the web app.
Args:
resource_group_name: Name of the resource group
name: Name of the web app
Returns:
List of BackupItem objects
"""Restore a web application from a backup.
def restore(
self,
resource_group_name: str,
name: str,
backup_id: str,
request: RestoreRequest,
**kwargs
) -> None:
"""
Restore web app from backup.
Args:
resource_group_name: Name of the resource group
name: Name of the web app
backup_id: ID of the backup to restore from
request: Restore configuration
"""Usage Example:
from azure.mgmt.web.models import RestoreRequest
# Configure restore operation
restore_request = RestoreRequest(
storage_account_url="https://mystorageaccount.blob.core.windows.net/backups",
blob_name="backup-001.zip",
overwrite=True,
site_name="my-web-app",
databases=[
DatabaseBackupSetting(
database_type="SqlAzure",
name="MyDatabase",
connection_string_name="DefaultConnection"
)
]
)
# Restore from backup
client.web_apps.restore(
resource_group_name="my-resource-group",
name="my-web-app",
backup_id="backup-001",
request=restore_request
)Get all deployment slots for a web application.
def list_slots(
self,
resource_group_name: str,
name: str,
**kwargs
) -> List[Site]:
"""
List deployment slots for the web app.
Args:
resource_group_name: Name of the resource group
name: Name of the web app
Returns:
List of Site objects representing deployment slots
"""Create a new deployment slot.
def create_or_update_slot(
self,
resource_group_name: str,
name: str,
slot: str,
site_envelope: Site,
**kwargs
) -> Site:
"""
Create or update a deployment slot.
Args:
resource_group_name: Name of the resource group
name: Name of the web app
slot: Name of the deployment slot
site_envelope: Slot configuration
Returns:
Created/updated Site object
"""Swap content between deployment slots.
def swap_slot(
self,
resource_group_name: str,
name: str,
slot_swap_entity: CsmSlotEntity,
**kwargs
) -> None:
"""
Swap deployment slots.
Args:
resource_group_name: Name of the resource group
name: Name of the web app
slot_swap_entity: Slot swap configuration
"""Usage Example:
# List deployment slots
slots = client.web_apps.list_slots(
resource_group_name="my-resource-group",
name="my-web-app"
)
for slot in slots:
print(f"Slot: {slot.name}")
# Swap staging slot to production
from azure.mgmt.web.models import CsmSlotEntity
swap_config = CsmSlotEntity(
target_slot="production",
preserve_vnet=True
)
client.web_apps.swap_slot(
resource_group_name="my-resource-group",
name="my-web-app",
slot_swap_entity=swap_config
)class Deployment:
"""Represents a deployment record."""
id: Optional[str]
status: Optional[int]
message: Optional[str]
author: Optional[str]
author_email: Optional[str]
deployer: Optional[str]
start_time: Optional[datetime]
end_time: Optional[datetime]
active: Optional[bool]
details: Optional[str]class BackupRequest:
"""Configuration for creating a backup."""
backup_name: str
enabled: Optional[bool]
storage_account_url: str
backup_schedule: Optional[BackupSchedule]
databases: Optional[List[DatabaseBackupSetting]]class SiteSourceControl:
"""Source control configuration for a web app."""
repo_url: Optional[str]
branch: Optional[str]
is_manual_integration: Optional[bool]
is_mercurial: Optional[bool]
deployment_rollback_enabled: Optional[bool]
is_git_hub_action: Optional[bool]Install with Tessl CLI
npx tessl i tessl/pypi-azure-mgmt-web