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.14.tar.gz (50.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.2.14-cp313-cp313-manylinux_2_34_x86_64.whl (272.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

spot_planner-0.2.14-cp313-cp313-manylinux_2_34_aarch64.whl (262.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

spot_planner-0.2.14-cp312-cp312-manylinux_2_34_x86_64.whl (272.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

spot_planner-0.2.14-cp312-cp312-manylinux_2_34_aarch64.whl (262.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

spot_planner-0.2.14-cp311-cp311-manylinux_2_34_x86_64.whl (272.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

spot_planner-0.2.14-cp311-cp311-manylinux_2_34_aarch64.whl (263.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

spot_planner-0.2.14-cp310-cp310-manylinux_2_34_x86_64.whl (272.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

spot_planner-0.2.14-cp310-cp310-manylinux_2_34_aarch64.whl (263.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

File details

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

File metadata

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

File hashes

Hashes for spot_planner-0.2.14.tar.gz
Algorithm Hash digest
SHA256 429e1cea43caadd74cc197c2f14bec0b64c90f3b1164af220ad8e59ff10694c9
MD5 2c8066eafbb51ff2800e916f307d6524
BLAKE2b-256 8a52a4074ca04596e34666a4e923af05f7493a8011e766eb4c8176e8f5a27f36

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.14-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 ba132a0ceddccd971811188985dcb037bb54d0caa6265ee2262f47f7b5aa2a01
MD5 e20c4fbea2d78879e2469c196859dc32
BLAKE2b-256 6c9d53dc0f27d43488f678cfac450241292570f3d29b89c2ddf69a266209e290

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.14-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 a49b54a9092cd92f637a94050a66836086a3427cdfdc186b8b859be9aebe73d1
MD5 c2e91ab70db98b3787ab77b998e84236
BLAKE2b-256 89b56e32d9ea614ed257f94e8b21f3f0f36a201069c58f61114f2670ff9a9c8b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.14-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 19ce720daab605aa65a0ea9f5883802278a85fd2e95b419761fcc234c17edf88
MD5 e0384ec90b13ea0ce591ae4e9e73a21c
BLAKE2b-256 8905b2c4375e1add3815569b8b4d2105442ed312f9a7dfa308b423a5e6e9a7f6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.14-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 8e65e590411c2ee3dfeebff133ec50c416b242577124c2d7a074cb2dae766abb
MD5 5ed57139dda82d2529bfc2889331c66e
BLAKE2b-256 2fe7b1a0fcb401185fb238e6e567b57e7069a4aa729d9155af0fa58e80619180

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.14-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f818c529ef241e4466d8090f71875d413614cfe3160b0cbe74b8947e392c01a4
MD5 c1a942b9834d2ef682ddebb113349389
BLAKE2b-256 a89e98a977ab2fc688623d5db96893d5473e32a286aa8d0aa15a884c30324c32

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.14-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 2f1a283739d0532908ac63016ab1183b8cd6b75ef4fb9a6f495bd8bbc1d256be
MD5 b2ea562926ee5ee5bf32531ede97946a
BLAKE2b-256 88c4c1c83b995a97a8597d0f862ae97e081d5984e1f885d5f246ea759a0ec5ef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.14-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 b119fbfec6eb5df2f29dd44bbac493f8460be046bfa638013907b5c2f852318e
MD5 7de4177230bbaa0029b7d54ff93fa53d
BLAKE2b-256 4453f246e11fa4d1380ed3e6654b069a296c66bd34da3142a564269e78683fc1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.14-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 b9b73f4ef88156addb969b6faa62912bc7a7d68c9644ea94d09ebcb2f8a638e4
MD5 5cbaa7c0d825e422f240209ad14b01f7
BLAKE2b-256 698b96d4263e0b61fa6e56979447076814637f19b3c098ce3ccfd8af34a59512

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