Tools
Introducing azurecost: Azure Cost Management Made Simple
2025-12-16
0 views
admin
The Problem ## The Solution ## Key Features ## Getting Started ## Real-World Examples ## Multi-dimensional Analysis ## Daily Monitoring ## Focused Investigation ## Why I Built This ## Using It in Your Scripts ## Configuration Tips ## What's Next ## Try It Out 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. Azure's Cost Management portal is powerful, but sometimes you just want quick answers: Navigating through the Azure portal for these simple questions feels like overkill. You need something faster. 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. Installation is one line: Make sure you're logged in with Azure CLI: You'll see something like this: Clean, readable, instant. Want to see costs broken down by both resource group and service? Easy: Tracking costs during a migration or deployment? Switch to daily granularity: This shows you the last 7 days of costs, broken down by day. Need to check costs for a specific resource group? Shows 3 months of costs for just that resource group. 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: 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. The Python API makes it easy to integrate cost monitoring into your automation: Set environment variables to avoid typing the same options repeatedly: Now just run azurecost with no arguments. It'll use your configured subscription and resource group automatically. The tool is actively maintained and open to contributions. Some ideas I'm exploring: The tool is open source and available on PyPI. Give it a try: 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. Have questions or feedback? Open an issue on GitHub or drop a comment below! Templates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse COMMAND_BLOCK:
pip install azurecost Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
pip install azurecost COMMAND_BLOCK:
pip install azurecost CODE_BLOCK:
az login Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
azurecost -s my-subscription Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
azurecost -s my-subscription CODE_BLOCK:
azurecost -s my-subscription CODE_BLOCK:
(JPY) 2023-08 2023-09
------------------ --------- ---------
total 492.77 80.28
Cognitive Services 492.77 80.28
Bandwidth 0 0
Storage 0 0 Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
(JPY) 2023-08 2023-09
------------------ --------- ---------
total 492.77 80.28
Cognitive Services 492.77 80.28
Bandwidth 0 0
Storage 0 0 CODE_BLOCK:
(JPY) 2023-08 2023-09
------------------ --------- ---------
total 492.77 80.28
Cognitive Services 492.77 80.28
Bandwidth 0 0
Storage 0 0 CODE_BLOCK:
azurecost -s my-subscription -d ResourceGroup -d ServiceName Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
azurecost -s my-subscription -d ResourceGroup -d ServiceName CODE_BLOCK:
azurecost -s my-subscription -d ResourceGroup -d ServiceName CODE_BLOCK:
azurecost -s my-subscription -g DAILY -a 7 Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
azurecost -s my-subscription -g DAILY -a 7 CODE_BLOCK:
azurecost -s my-subscription -g DAILY -a 7 CODE_BLOCK:
azurecost -s my-subscription -r production-rg -a 3 Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
azurecost -s my-subscription -r production-rg -a 3 CODE_BLOCK:
azurecost -s my-subscription -r production-rg -a 3 CODE_BLOCK:
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) Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
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) CODE_BLOCK:
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) CODE_BLOCK:
export AZURE_SUBSCRIPTION_ID=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
export AZURE_RESOURCE_GROUP=production-rg Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
export AZURE_SUBSCRIPTION_ID=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
export AZURE_RESOURCE_GROUP=production-rg CODE_BLOCK:
export AZURE_SUBSCRIPTION_ID=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
export AZURE_RESOURCE_GROUP=production-rg COMMAND_BLOCK:
pip install azurecost
azurecost -s your-subscription Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
pip install azurecost
azurecost -s your-subscription COMMAND_BLOCK:
pip install azurecost
azurecost -s your-subscription - "How much did I spend last month?"
- "Which services are costing me the most?"
- "What's the cost breakdown by resource group?" - Simple by default: Just run azurecost and 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 - 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 - Daily cost reports sent to Slack
- Budget alerts in your CI/CD pipeline
- Cost attribution in team dashboards
- Custom reporting for finance teams - Cost anomaly detection
- Budget tracking and alerts
- Cost forecasting based on historical trends
- Integration with other cloud providers - 🔗 GitHub: toyama0919/azurecost
- 📦 PyPI: azurecost
- 🐍 Python: 3.8+
how-totutorialguidedev.toaiserverswitchdockerpythongitgithub