Skip to main content

Algorithm for finding the cheapest periods in a sequence of prices

Project description

Spot Planner

A high-performance Python library for finding optimal time periods in price sequences. Perfect for spot price analysis, cost optimization, and resource planning.

What is Spot Planner?

Spot Planner helps you identify the most cost-effective periods in a sequence of prices. Whether you're analyzing electricity spot prices, cloud computing costs, or any time-series pricing data, this library efficiently finds periods that meet your criteria.

Key Features

  • 🚀 High Performance: Core algorithm implemented in Rust for maximum speed
  • 🐍 Python Native: Seamless Python integration with automatic fallback
  • 📊 Flexible Criteria: Find periods based on price thresholds, duration, and gaps
  • 🔧 Easy Integration: Simple API that works with any price sequence
  • Zero Dependencies: No external dependencies required

Installation

Using uv (Recommended)

uv add spot-planner

Using pip

pip install spot-planner

Quick Start

from decimal import Decimal
from spot_planner import get_cheapest_periods

# Example: Find cheapest electricity periods
price_data = [
    Decimal("50"),  # 6 AM - expensive
    Decimal("40"),  # 7 AM - moderate
    Decimal("30"),  # 8 AM - cheap
    Decimal("20"),  # 9 AM - very cheap
    Decimal("45"),  # 10 AM - expensive again
]

# Find 2 cheapest periods with price under 35
result = get_cheapest_periods(
    price_data=price_data,
    price_threshold=Decimal("35"),
    desired_count=2,
    min_period=1,
    max_gap=1,
    max_start_gap=1
)

print(result)  # [2, 3] - periods starting at index 2 and 3

Use Cases

Electricity Spot Price Analysis

# Find cheapest 3-hour periods for running high-power equipment
cheap_periods = get_cheapest_periods(
    price_data=hourly_prices,
    price_threshold=Decimal("0.05"),  # 5 cents per kWh
    desired_count=3,
    min_period=3,  # 3-hour minimum
    max_gap=2      # Allow 2-hour gaps between periods
)

Cloud Computing Cost Optimization

# Find most cost-effective periods for batch processing
optimal_windows = get_cheapest_periods(
    price_data=aws_spot_prices,
    price_threshold=Decimal("0.10"),  # $0.10 per hour
    desired_count=5,
    min_period=4,  # 4-hour processing windows
    max_gap=1      # Minimal gaps between windows
)

Resource Planning

# Plan maintenance windows during low-cost periods
maintenance_slots = get_cheapest_periods(
    price_data=resource_costs,
    price_threshold=budget_threshold,
    desired_count=2,
    min_period=8,  # 8-hour maintenance windows
    max_gap=0      # No gaps allowed
)

API Reference

get_cheapest_periods(price_data, price_threshold, desired_count, min_period=1, max_gap=0, max_start_gap=0)

Find the cheapest periods in a price sequence.

Parameters:

  • price_data (List[Decimal]): Sequence of prices to analyze
  • price_threshold (Decimal): Maximum price for valid periods
  • desired_count (int): Number of periods to find
  • min_period (int, optional): Minimum period length. Defaults to 1.
  • max_gap (int, optional): Maximum gap between periods. Defaults to 0.
  • max_start_gap (int, optional): Maximum gap from start to first period. Defaults to 0.

Returns:

  • List[int]: Starting indices of the cheapest periods

Raises:

  • ValueError: If parameters are invalid or no valid periods found

Performance

Spot Planner uses Rust for the core algorithm, providing significant performance improvements over pure Python implementations:

  • 10-100x faster than naive Python approaches
  • Memory efficient with minimal allocations
  • Automatic fallback to Python implementation if Rust module unavailable

License

This project is licensed under the MIT License - see the LICENSE file for details.

Changelog

See CHANGELOG.md for a list of changes and version history.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spot_planner-0.1.1.tar.gz (21.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

spot_planner-0.1.1-cp313-cp313-manylinux_2_34_aarch64.whl (247.2 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

spot_planner-0.1.1-cp312-cp312-manylinux_2_34_x86_64.whl (256.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

File details

Details for the file spot_planner-0.1.1.tar.gz.

File metadata

  • Download URL: spot_planner-0.1.1.tar.gz
  • Upload date:
  • Size: 21.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.22

File hashes

Hashes for spot_planner-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7b01e9d2f2cab131ce2b0cabbef66a24f6e99b0f0a40b448982af4c19ae2c892
MD5 930e52da5260429f416ef301458bdb65
BLAKE2b-256 061a329b314f535a11482209a11d915ffcb5c7143bd0a155b88769676b1abf22

See more details on using hashes here.

File details

Details for the file spot_planner-0.1.1-cp313-cp313-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for spot_planner-0.1.1-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 6202f3f68a6eb57f01fbc7ec8b1a8fc1c05da7189231ec2f162082e684f02b22
MD5 c8bf42b2a6e6d0c2fc0f14f0fda6f506
BLAKE2b-256 5cf50689207498b62262bf1cf35e2512f53be596b64567a26d7234a6e42dac34

See more details on using hashes here.

File details

Details for the file spot_planner-0.1.1-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for spot_planner-0.1.1-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e7314d7e4a965c07ad3100005b8172ecaeaafaa0455e9a81dbc2661b1eeb6066
MD5 d5fe30a29659d12521b48d5d6f468d10
BLAKE2b-256 5f36a2d09d989f5005fe39f81fa174f3ab4836983eedd2b3785f5536f6130528

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page