Skip to main content

azure-resource-sweeper

CI PyPI version Python versions License

An Azure CLI extension that detects and safely cleans up stale and unused resources — unattached disks, dangling NICs, unused public IPs and empty App Service plans that quietly keep costing money.


Why?

Stale resources are easy to create and easy to forget. They never show up on a dashboard you look at, but they always show up on the bill. azure-resource-sweeper uses Azure Resource Graph KQL queries to find them in seconds and removes them with a dry-run-first safety model.


Installation

# Install directly from PyPI
az extension add --name azure-resource-sweeper

# Or from a local wheel (for development)
pip install build
python -m build
az extension add --source dist/azure_resource_sweeper-*-py3-none-any.whl

For local development with azdev

pip install azdev
azdev setup --repo .
azdev extension add resource-sweeper
az sweeper --help

Quick start

# 1. Scan the entire subscription for every stale resource type
az sweeper scan

# 2. Scan for unattached disks and show estimated monthly cost
az sweeper scan --type disk --estimate-cost

# 3. Scan a single resource group and output JSON
az sweeper scan -g my-rg --output json

# 4. Preview what would be deleted (dry-run — nothing is removed)
az sweeper clean --type publicip

# 5. Delete all stale resources without a prompt
az sweeper clean --type all --dry-run false --yes

Supported resource types

Type --type Detection condition Typical monthly cost
Unattached managed disk disk properties.diskState == 'Unattached' ~$0.05 / GB
Disconnected NIC nic isnull(properties.virtualMachine) $0 (blocks IP/VM removal)
Unused public IP publicip isnull(properties.ipConfiguration) ~$3.65 (Standard)
Empty App Service plan appserviceplan properties.numberOfSites == 0 ~$54.75 (Basic B1)
All of the above all (default) — —

Command reference

az sweeper scan

Option Default Description
--resource-group, -g all RGs Limit the scan to one resource group.
--subscription-id active Subscription to scan.
--type all disk / nic / publicip / appserviceplan / all
--estimate-cost off Add an estimatedMonthlyCost (USD) field to each row.

az sweeper clean

Option Default Description
--resource-group, -g all RGs Limit deletion to one resource group.
--subscription-id active Subscription to operate on.
--type all Type of stale resource to delete.
--dry-run true Preview only. Pass --dry-run false to delete for real.
--yes, -y off Skip the interactive confirmation prompt.

Authentication

Authentication uses DefaultAzureCredential — once you have run az login the extension just works. In CI, set the standard Azure SDK environment variables (AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET) or use a managed identity — no extra configuration needed.


Extension architecture

This project follows the official Azure CLI extension format:

Requirement Implementation
azext_ package prefix azext_resource_sweeper/
COMMAND_LOADER_CLS in __init__.py ResourceSweeperCommandsLoader
azure.cli.extensions entry-point setup.py → entry_points
load_command_table + load_arguments commands.py + _params.py
azdev compatible azdev extension add resource-sweeper

Contributing

Contributions are very welcome! See CONTRIBUTING.md for how to set up a local dev environment, run tests, and add a new resource type.


License

Apache 2.0 © Dana Kim

Metadata

Release files for azure-resource-sweeper 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for azure-resource-sweeper 0.2.1
File Size Uploaded
azure_resource_sweeper-0.2.1.tar.gz 15.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for azure-resource-sweeper 0.2.1
File Interpreter ABI Platform
azure_resource_sweeper-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 30.0 kB

Release files / azure_resource_sweeper-0.2.1.tar.gz

Download URL azure_resource_sweeper-0.2.1.tar.gz
Size 15.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b77601ca66de18e8ceea74cacd13d6debaad001e1b75b421ef3a33baf309d7b2
BLAKE2b-256 checksum
How to use checksums
08469c117394ea84d2d22baa57a6f62cbe6150f544d04af83deeec24167ae566
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release files / azure_resource_sweeper-0.2.1-py3-none-any.whl

Download URL azure_resource_sweeper-0.2.1-py3-none-any.whl
Size 15.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e7d768f0f87774eb06523f0d989aaac8e65718e15754384c47abab87f58d8fb8
BLAKE2b-256 checksum
How to use checksums
67b134124cfbd1320f4fcb83a7232093f52948ebc751a6606b02171964b2aed2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page