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.0.tar.gz (29.5 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.0-cp313-cp313-manylinux_2_34_x86_64.whl (258.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

spot_planner-0.2.0-cp313-cp313-manylinux_2_34_aarch64.whl (249.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

spot_planner-0.2.0-cp312-cp312-manylinux_2_34_x86_64.whl (258.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

spot_planner-0.2.0-cp312-cp312-manylinux_2_34_aarch64.whl (250.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

spot_planner-0.2.0-cp311-cp311-manylinux_2_34_x86_64.whl (258.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

spot_planner-0.2.0-cp311-cp311-manylinux_2_34_aarch64.whl (249.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

spot_planner-0.2.0-cp310-cp310-manylinux_2_34_x86_64.whl (259.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

spot_planner-0.2.0-cp310-cp310-manylinux_2_34_aarch64.whl (250.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

File details

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

File metadata

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

File hashes

Hashes for spot_planner-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3ce759a025751db649435081a47e611a235050c7ae757388a9a6079a48e53670
MD5 3c84847a2aa8175d318ee13cce3e7439
BLAKE2b-256 8a4111027307f60bb0b1b72e093ceb16b9c7d358acfcae3b397c85aa8b965ecd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.0-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 5f1522a70d11f1361ffad2794be1fd33fd9119936e2d722828dc40b6e0fdc046
MD5 0d47950856902c6590946efc3582ef9f
BLAKE2b-256 3f4ca3169ea7e96d7bd1e4c89a5fe93835d32419766cbdad676601c3036788e4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.0-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 044c58f70f79b05c1b240d233bd6f94d27ee73a97ab1e3abf6c28f711e95714a
MD5 5ce54f4a83571acad6ce13324169ca0c
BLAKE2b-256 fe4b8867441cd0b0dfef0e7151f6ade3da3c461128d2645f13ae60839c66cce2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 5e35588d0746001dbb243e9ee8e3000e4d22b533c4bb654d66639ef23b4a1181
MD5 d698b8b65ecb522abc3a4268f36f2302
BLAKE2b-256 1add197b8f235792049136b7906e17d9af8c265b01f99982c27b812b867b8bfa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.0-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 ab36f2cf20997a368ee00ef5843466074fbe12489fee0391437cdbff5ca46375
MD5 94d774fe7b095fadbb681eaaafd608d6
BLAKE2b-256 4a1e9c39eabe7eac8906037847f93792772d100b65ff7103e6c8a938f018333b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a140ec8d8a6260683b37c92b49490f8cf4908f5f2ed6f79f417c14cc2b57828c
MD5 0b4292ddd9918188d5c16339d569664a
BLAKE2b-256 565acd4f2abc7dee0c545468eacf18485803ee10d8ba899855e65060d166a0e1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.0-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 bed075fa307b7fdffd075c32e64185125f634eff099ff9ab17c8d3121e1ad4b8
MD5 8309dc5c5cc3233249ac145b3e6e730e
BLAKE2b-256 ec484377d3fe6d4481a6b9cee04a0b6b90d0274c1d8247e04a0d1e6debcc1577

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 0a7a0a15be7a04349b0413c3719d49efb784b805b2606c091530c850fe2cf7d9
MD5 fe3bc4adafaa2313fbaf827048cec36d
BLAKE2b-256 5081bf1a6316dd81c7819a41368f149da71cbe11099faca8e595311d707396bd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.0-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 84c174ff445046a0c17398978e13defe435e60d4c87a9f66effe6ddc7d392d26
MD5 c7fdfc700e932f1caf2b0c7a009d7709
BLAKE2b-256 96091970b9075eabef4f12bfcf2c9425c7ee78950b70c898d065b8c92f9f5fc1

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