Comparing Cloud Vendor Costs with Python
"Just how much will the cloud cost over a full year?" is the question that always comes up during mid-year budget reviews or when a new project kicks off. Checking each vendor's pricing page and tallying manually is slow and error-prone. This article provides an extensible Python script that stores per-vendor unit prices in a dictionary, computes monthly and annual costs in one go, and sorts the results automatically. The script doesn't aim for precision — it standardizes the comparison so the same CPU, RAM, and term sit on one table, and the expensive option stands out immediately.
The script
plans = {
"aliyun": {"cpu": 18, "ram": 7, "base": 10},
"tencent": {"cpu": 17, "ram": 6.5, "base": 9},
"vultr": {"cpu": 10, "ram": 4.5, "base": 4},
"aws": {"cpu": 15, "ram": 6, "base": 8},
"hetzner": {"cpu": 6, "ram": 3, "base": 3},
}
def monthly_cost(cpu_core: int, ram_gb: int) -> dict:
result = {}
for name, p in plans.items():
result[name] = round(p["base"] + p["cpu"] * cpu_core + p["ram"] * ram_gb, 2)
return dict(sorted(result.items(), key=lambda x: x[1]))
def yearly_cost(cpu_core: int, ram_gb: int) -> dict:
monthly = monthly_cost(cpu_core, ram_gb)
return {name: round(cost * 12, 2) for name, cost in monthly.items()}
print(monthly_cost(2, 4))
print(yearly_cost(2, 4))
Reference: official pricing pages of each vendor (always trust the live quotes before ordering)
Adding more vendors
Add a line to the plans dictionary: fill in the per-core price, per-GB-RAM price, and base fee for each vendor. For DigitalOcean, write "do": {"cpu": 10, "ram": 5, "base": 4}. If a vendor uses tiered pricing (first-year discounts, volume pricing), replace base with a function or add conditions inside monthly_cost. To add more vendors, just keep appending — the sorting and aggregation logic needs no changes.
Example output
For a 2-core / 4GB configuration, the script prints:
monthly: {'hetzner': 27.0, 'vultr': 42.0, 'aws': 62.0, 'tencent': 69.0, 'aliyun': 74.0}
yearly: {'hetzner': 324.0, 'vultr': 504.0, 'aws': 744.0, 'tencent': 828.0, 'aliyun': 888.0}
The price parameter table
| Vendor | Price per core | Price per GB RAM | Base fee |
|---|---|---|---|
| aliyun | 18 | 7.0 | 10 |
| tencent | 17 | 6.5 | 9 |
| vultr | 10 | 4.5 | 4 |
| aws | 15 | 6.0 | 8 |
| hetzner | 6 | 3.0 | 3 |
A real scenario
A team needs a three-year budget for a content site running on 2 cores / 4GB with 1TB of monthly traffic. The script's annual figures range from hetzner's 324 to aliyun's 888 — a spread of more than 1,600 over three years. That gap is large enough to drive the server selection decision, especially when cost-effectiveness is an explicit requirement. The scenario also shows that if most of the budget goes to traffic, folding each vendor's traffic-billing rules into the comparison is closer to reality than comparing spec prices alone.
Feeding the script into a monthly report
Budget comparison shouldn't be a one-off exercise. Pipe yearly_cost output into your monthly report and run it every month to watch how each vendor's cost moves with configuration changes. It's straightforward: have the script write CSV via Python's csv module, then hand it to a reporting tool or a simple table template. When a vendor adjusts prices, the report reflects it right away instead of you finding out at renewal time. Show both a three-month trend and a yearly estimate in the report so management can judge cost direction at a glance.
Annual budgets and reserved instances
Annual cost here is 12 full-price months. For stable workloads, reserved instances or yearly plans typically save another 30%+; write the discount factor into the script, e.g. multiply by 0.7 in yearly_cost, to get a number closer to the real contract price. When purchasing, weigh monthly flexibility against annual discounts together.
Keeping the price data fresh
- Trust live quotes over anything else. The numbers in the script are approximations; plug in current vendor promotions and the actual configuration before ordering.
- Fold in the hidden costs. Egress traffic, snapshot backups, and load balancers are all extra — the breakdown in the server cost calculator covers this.
- Re-check regularly. Cloud pricing changes often; update the parameter table quarterly so long-term decisions don't rest on stale numbers.
- Mind regional differences. The same vendor can charge 20-40% more in one region than another — put the target region into the comparison too.
FAQ
Can I place an order based on this output? No. It assumes linear pricing, while real plans have tiers, promos, and regional differences; always check the live official quotes before ordering. Why do Alibaba and Tencent look more expensive than overseas vendors? These are simplified parameters, not real quotes; domestic vendors often have new-user discounts and annual plans, so fold promotions into the comparison. Is annual cost the same as one-time yearly payment? No — this sums 12 full-price months; yearly payment usually has a discount, so multiply in the discount factor. Can the output render on a web page? Yes — serialize the results to JSON and render them with a table component, or generate a static HTML page on a cron schedule. Can the USD figures be converted to CNY? Yes — multiply by an exchange-rate factor before output, or rewrite the prices in plans to CNY quotes; just keep the basis consistent.
Notes
- The script assumes a linear per-core/per-GB model; real plans often use tiered pricing, so check the bundle price directly for large machines.
- Annual cost here is 12 full-price months, ignoring reserved-instance discounts. For stable workloads, reserved instances typically save another 30%+.
- This is a comparison tool, not an ordering tool. The final decision should follow the vendor contract and the server selection guide.
For more head-to-head comparisons, browse the server selection category.