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
prices = [
    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(
    prices=prices,
    low_price_threshold=Decimal("35"),
    min_selections=2,
    min_consecutive_selections=1,
    max_gap_between_periods_between_periods=1,
    max_gap_between_periods_from_start=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(
    prices=hourly_prices,
    low_price_threshold=Decimal("0.05"),  # 5 cents per kWh
    min_selections=3,
    min_consecutive_selections=3,  # 3-hour minimum
    max_gap_between_periods=2      # Allow 2-hour gaps between periods
)

Cloud Computing Cost Optimization

# Find most cost-effective periods for batch processing
optimal_windows = get_cheapest_periods(
    prices=aws_spot_prices,
    low_price_threshold=Decimal("0.10"),  # $0.10 per hour
    min_selections=5,
    min_consecutive_selections=4,  # 4-hour processing windows
    max_gap_between_periods=1      # Minimal gaps between windows
)

Resource Planning

# Plan maintenance windows during low-cost periods
maintenance_slots = get_cheapest_periods(
    prices=resource_costs,
    low_price_threshold=budget_threshold,
    min_selections=2,
    min_consecutive_selections=8,  # 8-hour maintenance windows
    max_gap_between_periods=0      # No gaps allowed
)

API Reference

get_cheapest_periods(prices, low_price_threshold, min_selections, min_consecutive_selections=1, max_gap_between_periods=0, max_gap_from_start=0)

Find the cheapest periods in a price sequence.

Parameters:

  • prices (List[Decimal]): Sequence of prices to analyze
  • low_price_threshold (Decimal): Maximum price for valid periods
  • min_selections (int): Number of periods to find
  • min_consecutive_selections (int, optional): Minimum period length. Defaults to 1.
  • max_gap_between_periods (int, optional): Maximum gap between periods. Defaults to 0.
  • max_gap_from_start (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.2.11.tar.gz (48.9 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.2.11-cp313-cp313-manylinux_2_34_x86_64.whl (269.1 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

spot_planner-0.2.11-cp313-cp313-manylinux_2_34_aarch64.whl (258.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

spot_planner-0.2.11-cp312-cp312-manylinux_2_34_x86_64.whl (269.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

spot_planner-0.2.11-cp312-cp312-manylinux_2_34_aarch64.whl (259.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

spot_planner-0.2.11-cp311-cp311-manylinux_2_34_x86_64.whl (269.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

spot_planner-0.2.11-cp311-cp311-manylinux_2_34_aarch64.whl (259.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

spot_planner-0.2.11-cp310-cp310-manylinux_2_34_x86_64.whl (269.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

spot_planner-0.2.11-cp310-cp310-manylinux_2_34_aarch64.whl (259.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

File details

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

File metadata

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

File hashes

Hashes for spot_planner-0.2.11.tar.gz
Algorithm Hash digest
SHA256 13fa9c42ab081e06298e456ea1f7ca2227549f45f6e222989e22d8a31735c37a
MD5 50a648a4b282b7c6c7000d3deb4e5794
BLAKE2b-256 2b1e05d8c0bae8544f22b0972fc0fba8cdf3d12e51e8fdd3da3d9bc0159e9a5c

See more details on using hashes here.

File details

Details for the file spot_planner-0.2.11-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for spot_planner-0.2.11-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f561819a999e65bd2936673c61ae18a47b9a9d6ccca17dc5124de6868a0f867a
MD5 b40702f0557d74724c63e0b83db898ba
BLAKE2b-256 1aaba06a27d8b73b41804eee6b5e47b2862ec2e87e33cd2195655b9f8a8dcf01

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.11-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 8ed18a4b30d6468482b97b1d557ffa58a6d40cd3ae2ad76dbd3d6428cdad9b6f
MD5 7734862271efde4b0687a683bf9edb62
BLAKE2b-256 72825d48b3268eb789d04a0009dd883a048c95a9d249e699c1f28a25940e5673

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.11-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 c2cadf87d34ed5453809da975b82505dc9f7c6361f06d805f294778b09eba853
MD5 d746300294ef909efa04b18dc7cde080
BLAKE2b-256 e7d83b47294c1bc49a25b353dddee2b72e7121eb4afcb39ba616b7d56bbd482a

See more details on using hashes here.

File details

Details for the file spot_planner-0.2.11-cp312-cp312-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for spot_planner-0.2.11-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 2767abb9a09bb6924399dc3c1077f4bb5d279f64e11c6968b038ae7e80c3c5aa
MD5 78e56303656c006204dbdc568697b1a9
BLAKE2b-256 e93716af0e670bbe6d18785444616c1a2dbb573ca8a612b207471206a37f6fac

See more details on using hashes here.

File details

Details for the file spot_planner-0.2.11-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for spot_planner-0.2.11-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 326e8d2026de72239154449dc79b86360942e8585bced62355645ef410c03b12
MD5 4cb1611fe5307e77a67428d609b31968
BLAKE2b-256 334f3dea6f76374fd362340eed9e81f8625a3112db3e5936ad8641aeb7ff9af9

See more details on using hashes here.

File details

Details for the file spot_planner-0.2.11-cp311-cp311-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for spot_planner-0.2.11-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 2238706f7fb4ee70bfca9f8d1ba1c944e0f931304ad17ecb91aa677747f470a9
MD5 4d55a7d1697679faa0fffd3d63f93b4e
BLAKE2b-256 762bd7aa14232c171af86cdffc6b1a35e91549b9e5517b84b97670011f4840ef

See more details on using hashes here.

File details

Details for the file spot_planner-0.2.11-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for spot_planner-0.2.11-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 46230258ff454b89e952a297b49784614e33b4c52157f75b39980b5d16020a02
MD5 e076f4a74c2667f8a0753def147723e3
BLAKE2b-256 6aada8fc93cc95789ffe3e2019c0f27c8216381b1724c362e1370518cdfa6af1

See more details on using hashes here.

File details

Details for the file spot_planner-0.2.11-cp310-cp310-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for spot_planner-0.2.11-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 a42f1a4ed6b6a6599d10628a8c46b13e7f5767e2fdbe942eea858d5720c01ff3
MD5 675c8f79e46d09110fe19a06bb608e53
BLAKE2b-256 b8d14fc5a92d678d1b1816c6e0f725c9d11ad7657ddbedcd3dd9a206aa7e8b33

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