For majority of the compute providers Libcloud provides estimated pricing information. Pricing information is available via the price attribute on the NodeSize object. price attribute is a float() type and tells user how much it costs (in US dollars) to run a Node with a specified NodeSize for an hour.

Example below shows how to retrieve pricing for NodeSize objects using list_sizes() method.

from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

EC2_ACCESS_ID = 'your access id'
EC2_SECRET_KEY = 'your secret key'

cls = get_driver(Provider.EC2)
driver = cls(EC2_ACCESS_ID, EC2_SECRET_KEY)
sizes = driver.list_sizes()

# >>> sizes[:2]
# [<NodeSize: id=t1.micro, name=Micro Instance, ram=613 disk=15 bandwidth=None
#   price=0.02 driver=Amazon EC2 ...>,
# <NodeSize: id=m1.small, name=Small Instance, ram=1740 disk=160 bandwidth=None
#  price=0.065 driver=Amazon EC2 ...>,
# >>> sizes[0].price
# 0.02
# >>>

As noted above this pricing information is an estimate and should only be used as such. You should always check your provider website / control panel for accurate pricing information and never rely solely on Libcloud pricing data.

Besides that, many cloud providers also offer different pricing scheme based on the volume, term commitment and discounts for reserved instances. All of this information is not taken into account in the simplistic “price per hour” pricing scheme available in Libcloud.

Where does the Libcloud pricing data come from?

Most of the providers don’t provide pricing information via the API which means most of the pricing information is scraped directly from the provider websites.

Pricing data which is scraped from the provider websites is located in a JSON file (data/pricing.json) which is bundled with each release. This pricing data is only updated once you install a new release which means it could be out of date.

Using a custom pricing file


This functionality is only available in Libcloud 0.14.0 and above.

By default Libcloud reads pricing data from data/pricing.json file which is included in the release package. If you want to use a custom pricing file, simply move your custom pricing file to ~/.libcloud.pricing.json.

If ~/.libcloud.pricing.json file is available, Libcloud will use it instead of the default pricing file which comes bundled with the release.

Updating pricing


This functionality is only available in Libcloud 0.14.0 and above.

Currently only way to update pricing is programmatically using libcloud.pricing.download_pricing_file() function. By default this function retrieves the latest pricing file from our git repository and saves it to ~/.libcloud.pricing.json.

libcloud.pricing.download_pricing_file(file_url=';a=blob_plain;f=libcloud/data/pricing.json', file_path='/home/docs/.libcloud/pricing.json')[source]

Download pricing file from the file_url and save it to file_path.

  • file_url (str) – URL pointing to the pricing file.
  • file_path (str) – Path where a download pricing file will be saved.