Skip to content

Usage Based Pricing API Reference

This page documents the API for the business KPIs module in Pypulate.

Usage Pricing Module

This module provides functions for calculating usage-based pricing.

calculate_usage_price(usage_metrics, metric_rates, minimum_charge=0.0, maximum_charge=None)

Calculate price based on usage metrics.

Parameters:

Name Type Description Default
usage_metrics dict

Dictionary of metric names and their usage values

required
metric_rates dict

Dictionary of metric names and their per-unit rates

required
minimum_charge float

Minimum charge to apply

0.0
maximum_charge float

Maximum charge cap

None

Returns:

Type Description
float

Total usage-based price

Examples:

>>> metrics = {'api_calls': 1000, 'storage_gb': 50}
>>> rates = {'api_calls': 0.001, 'storage_gb': 0.10}
>>> calculate_usage_price(metrics, rates)
6.0  # (1000 * 0.001) + (50 * 0.10)
>>> calculate_usage_price(metrics, rates, minimum_charge=10.0)
10.0  # Max of calculated price and minimum charge

calculate_volume_discount(base_price, volume, discount_tiers)

Calculate price with volume-based discounts.

Parameters:

Name Type Description Default
base_price float

Base price per unit

required
volume int

Number of units

required
discount_tiers dict

Dictionary of volume thresholds and discount rates Format: {100: 0.05, 500: 0.10, 1000: 0.15}

required

Returns:

Type Description
float

Total price after volume discount

Examples:

>>> tiers = {100: 0.05, 500: 0.10, 1000: 0.15}
>>> calculate_volume_discount(10.0, 750, tiers)
6750.0  # 750 * 10.0 * (1 - 0.10)