If you've ever struggled to understand your Azure costs through the portal's cluttered interface, you're not alone. That's why I created azurecost - a straightforward command-line tool that gives you instant visibility into your Azure spending.
The Problem
Azure's Cost Management portal is powerful, but sometimes you just want quick answers:
- "How much did I spend last month?"
- "Which services are costing me the most?"
- "What's the cost breakdown by resource group?"
Navigating through the Azure portal for these simple questions feels like overkill. You need something faster.
The Solution
azurecost is a Python CLI tool that brings Azure cost data directly to your terminal. No clicking through menus, no waiting for the portal to load - just type a command and get your answer.
Key Features
-
Simple by default: Just run
azurecostand see your monthly costs by service - Flexible dimensions: Group costs by resource group, service name, location, or any combination
- Multiple time ranges: View daily or monthly costs for any time period
- Auto-currency detection: Displays costs in your subscription's billing currency
- Python API: Use it programmatically in your scripts and automation
Getting Started
Installation is one line:
pip install azurecost
Make sure you're logged in with Azure CLI:
az login
Then run it:
azurecost -s my-subscription
You'll see something like this:
(JPY) 2023-08 2023-09
------------------ --------- ---------
total 492.77 80.28
Cognitive Services 492.77 80.28
Bandwidth 0 0
Storage 0 0
Clean, readable, instant.
Real-World Examples
Multi-dimensional Analysis
Want to see costs broken down by both resource group and service? Easy:
azurecost -s my-subscription -d ResourceGroup -d ServiceName
Daily Monitoring
Tracking costs during a migration or deployment? Switch to daily granularity:
azurecost -s my-subscription -g DAILY -a 7
This shows you the last 7 days of costs, broken down by day.
Focused Investigation
Need to check costs for a specific resource group?
azurecost -s my-subscription -r production-rg -a 3
Shows 3 months of costs for just that resource group.
Why I Built This
The idea for azurecost came from a recurring frustration in my daily work as a cloud engineer. Every morning, I wanted to do a quick cost check - nothing fancy, just a sanity check to make sure nothing was unexpectedly spiking. But this simple task meant:
- Opening a browser
- Navigating to the Azure portal (and waiting for it to load)
- Finding the right subscription
- Clicking through to Cost Management
- Waiting for the cost analysis page to render
- Configuring the time range and dimensions I wanted
- Waiting again for the data to load
By the time I got my answer, 2-3 minutes had passed. Multiply that by every time someone on the team needed to check costs, and we're talking about hours of wasted time per week.
I realized I was doing the same exact query every time. I didn't need the portal's full power - I needed something as simple as running git status or docker ps. Something that gave me the information I needed in 2 seconds, not 2 minutes.
Then there were the times when I was SSH'd into a server or working in a restricted environment where opening a browser wasn't convenient. Or when I wanted to pipe cost data into a script for automated reporting. The portal simply wasn't designed for these workflows.
So I built azurecost. The goal was simple: make checking Azure costs feel as natural as any other command-line operation. No ceremony, no waiting, no clicking.
What started as a personal productivity hack turned into something my team adopted, then colleagues at other companies started using it, and eventually it made sense to release it as an open-source tool.
The philosophy behind azurecost is that most of the time, you don't need 100 different options and visualizations. You need a fast, reliable answer to a simple question. The tool does one thing well: show you your Azure costs quickly and clearly.
Using It in Your Scripts
The Python API makes it easy to integrate cost monitoring into your automation:
from azurecost import Azurecost
core = Azurecost(
debug=False,
granularity="DAILY",
dimensions=["ServiceName", "ResourceGroup"],
subscription_name="my-subscription"
)
total_results, results = core.get_usage(ago=7)
text = core.convert_tabulate(total_results, results)
print(text)
Perfect for:
- Daily cost reports sent to Slack
- Budget alerts in your CI/CD pipeline
- Cost attribution in team dashboards
- Custom reporting for finance teams
Configuration Tips
Set environment variables to avoid typing the same options repeatedly:
export AZURE_SUBSCRIPTION_ID=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
export AZURE_RESOURCE_GROUP=production-rg
Now just run azurecost with no arguments. It'll use your configured subscription and resource group automatically.
What's Next
The tool is actively maintained and open to contributions. Some ideas I'm exploring:
- Cost anomaly detection
- Budget tracking and alerts
- Cost forecasting based on historical trends
- Integration with other cloud providers
Try It Out
The tool is open source and available on PyPI. Give it a try:
pip install azurecost
azurecost -s your-subscription
Check out the GitHub repository for full documentation, examples, and to report issues or contribute.
Azure cost management doesn't have to be complicated. Sometimes the best tool is the simplest one.
Links
- 🔗 GitHub: toyama0919/azurecost
- 📦 PyPI: azurecost
- 🐍 Python: 3.8+
Have questions or feedback? Open an issue on GitHub or drop a comment below!
Top comments (0)