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.5.tar.gz (36.2 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.5-cp313-cp313-manylinux_2_34_x86_64.whl (261.6 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

spot_planner-0.2.5-cp313-cp313-manylinux_2_34_aarch64.whl (252.2 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

spot_planner-0.2.5-cp312-cp312-manylinux_2_34_x86_64.whl (261.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

spot_planner-0.2.5-cp312-cp312-manylinux_2_34_aarch64.whl (252.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

spot_planner-0.2.5-cp311-cp311-manylinux_2_34_x86_64.whl (261.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

spot_planner-0.2.5-cp311-cp311-manylinux_2_34_aarch64.whl (252.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

spot_planner-0.2.5-cp310-cp310-manylinux_2_34_x86_64.whl (261.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

spot_planner-0.2.5-cp310-cp310-manylinux_2_34_aarch64.whl (252.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

File details

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

File metadata

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

File hashes

Hashes for spot_planner-0.2.5.tar.gz
Algorithm Hash digest
SHA256 c76bf3c28d5ccb8c5a47fe00bba8511616e393df2c49cac7190d368b5627daf9
MD5 15469661799e7de4ed4463b4d1d4ba11
BLAKE2b-256 b49dd39ea2c59f1f1d362769bb6af81dc358263e7a3c99c1b7336f8d1f50e5d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.5-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 68163bb26e44d043a297c0d3d7b1fcf2def0f7d855c7ab1f432e7fee748ccf0c
MD5 e06bdc32c4f5f976547ed1f5ee3f26e2
BLAKE2b-256 4af6e7467833e42e8730f3ab88205fe5f1963ac897ceca6bef57b9eeee04f649

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.5-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 b97c71d8b47ded91c38e5cd5a11b47b0f9a17b638abf44a991d0af558ae564c8
MD5 21956cb4724ea6c28ad4d5b2b34598a6
BLAKE2b-256 ce4bd537fc7076f967f991f5794a2b2ba2ce8709a9f6ae8f7316f4e0d830999b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.5-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 8f8c579a47c95bdeb21a6e7893d8578bcc94f0608edaddafc857b535ad5b9b9f
MD5 bb3a1b8309fe15e7763defc1d1fc729f
BLAKE2b-256 47cfc63a3e243aaa51fe5143ef631c262c139ad4a05235a9ed284f321277107b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.5-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 4b0bb3cb78049f8f20324eeb5038b1b3039d15e85272006f088ea6cf6c06731e
MD5 84915126c5791a31f94538527e8a7a5d
BLAKE2b-256 dabaa75f82f817dfa98e4250d487d5e1dfa9bc8426074230e1e62052ff817ac7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.5-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 d34bcddfdc63dbdd4fb7ba69deb2fd6bb117b786ce63de33db21a780de16693c
MD5 6a93183a4165ae0c261aae9314ff6ab1
BLAKE2b-256 79b1ccce97bd2e3e18b110b05a3c045e8a9d5908320b02f119dce886aef0a358

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.5-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 9e9a0c10be6a20af8acfd3c13f1cb3c8dc771aa9b864653ada142592ab727a65
MD5 ad0866208f55c9233dd408d4d36bd26b
BLAKE2b-256 e2035a171d6539d98aca8245eb54bce2d73bab436f205057be8b8688167b2c61

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.5-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 1a058531048002497666871d14cca4a1ceac0f1adcda33d4d43ac2617b1e3849
MD5 a242e3b776336216f0a58b25755fdf37
BLAKE2b-256 44c52b47ac7aa981eca8fe72d66b55a921e974333e43e24cb2c4fd7efc8631b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.5-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 829d5b7e32b995fb744f01ca1617a2108424d04346fe77ff53542e344e98bcdf
MD5 42df256974cd41b60545db34b17b7402
BLAKE2b-256 3438bafbf8024935fbbe93191993fdce731daded9ba6d2d74181c24675d97137

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