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.3.7.tar.gz (1.5 MB 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.3.7-cp314-cp314-manylinux_2_34_x86_64.whl (284.9 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

spot_planner-0.3.7-cp314-cp314-manylinux_2_34_aarch64.whl (275.8 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ ARM64

spot_planner-0.3.7-cp313-cp313-manylinux_2_34_x86_64.whl (285.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

spot_planner-0.3.7-cp313-cp313-manylinux_2_34_aarch64.whl (276.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

spot_planner-0.3.7-cp312-cp312-manylinux_2_34_x86_64.whl (285.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

spot_planner-0.3.7-cp312-cp312-manylinux_2_34_aarch64.whl (276.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

spot_planner-0.3.7-cp311-cp311-manylinux_2_34_x86_64.whl (287.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

spot_planner-0.3.7-cp311-cp311-manylinux_2_34_aarch64.whl (278.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

spot_planner-0.3.7-cp310-cp310-manylinux_2_34_x86_64.whl (287.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

spot_planner-0.3.7-cp310-cp310-manylinux_2_34_aarch64.whl (278.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

File details

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

File metadata

  • Download URL: spot_planner-0.3.7.tar.gz
  • Upload date:
  • Size: 1.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for spot_planner-0.3.7.tar.gz
Algorithm Hash digest
SHA256 ec871dae79195a232d50cb57e740665a725d81d992a157faf72aa65a02115f3f
MD5 edfe5e5c6c85a4af65eca9725ecb731c
BLAKE2b-256 b88389a7ee76f50ea54863c32d9f6aa8125e695867640efa7f35dffd534d34cd

See more details on using hashes here.

File details

Details for the file spot_planner-0.3.7-cp314-cp314-manylinux_2_34_x86_64.whl.

File metadata

  • Download URL: spot_planner-0.3.7-cp314-cp314-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 284.9 kB
  • Tags: CPython 3.14, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for spot_planner-0.3.7-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 453bd1a6498533bd890f7b08ecb9cfbff80dbf0e6536fc69b73aca079a3b2455
MD5 987558c7a25a2e809fe961a019639f10
BLAKE2b-256 4a9c79df857c25a8d70f569bdb0a256653745e30df69d435f98c89387b1c841a

See more details on using hashes here.

File details

Details for the file spot_planner-0.3.7-cp314-cp314-manylinux_2_34_aarch64.whl.

File metadata

  • Download URL: spot_planner-0.3.7-cp314-cp314-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 275.8 kB
  • Tags: CPython 3.14, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for spot_planner-0.3.7-cp314-cp314-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 bca1dcd5ed7a5ef7aa5046c6f289d8417d56d914341c76a058c13a42ef372a8e
MD5 b96da9ab44729496e0029e7d92dcc33a
BLAKE2b-256 28c6df1c81c21b986e6be5db397e3b91a1b625144a47f72f6bc5132c7fa9f999

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.7-cp313-cp313-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 285.4 kB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for spot_planner-0.3.7-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 5a736a15d0958aae897e864a3d0675f7b7cdd132bc11cb8e8c430892bd79e7c3
MD5 b3adb32a5464cd0ec5b54be4ee0a2f3d
BLAKE2b-256 b853b385754bd16d69f259f88eb4b904cada4b1555b347519abf934aec173d21

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.7-cp313-cp313-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 276.3 kB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for spot_planner-0.3.7-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 3a6ce745beebe5f2a8c3753a207916235316a7d29713e9fcf22b1f432522052b
MD5 ba1fea4227caff342a2f5330bb25f0ed
BLAKE2b-256 172d7e6e0034dc750e04120e534f95798ba66db1bd8910664c1fc3e321aaf9b3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.7-cp312-cp312-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 285.7 kB
  • Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for spot_planner-0.3.7-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 15af86dc763790506e7841cd645d27d54c13fe747f9a5521dcfbd379b15223cc
MD5 e77fbf12796f1eeeec99d262cdca3d72
BLAKE2b-256 8afc4fdbc98908126624a61c1e353d140d5892814b8638bd5623727eb91cc95a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.7-cp312-cp312-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 276.6 kB
  • Tags: CPython 3.12, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for spot_planner-0.3.7-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 305448dda906631c3a334b7dbc554bafa0dd61353f4a2d74dca7b8e8c502e258
MD5 dfa1edd3990d9e332951b53f40a98365
BLAKE2b-256 69af58f952472011e2676d324c481064c0a5c06ad871313cf873fcca6b228d07

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.7-cp311-cp311-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 287.7 kB
  • Tags: CPython 3.11, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for spot_planner-0.3.7-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 7ca97cf097a95e4dbdfa2f595f852e6d29c054945da3e99580b49598521cf821
MD5 6118abba10b35a704e1664b8a70e02ad
BLAKE2b-256 673911e8565f842a60afd3dd208471632c945a08ff94826f5281463065f623e0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.7-cp311-cp311-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 278.5 kB
  • Tags: CPython 3.11, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for spot_planner-0.3.7-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 3946283c4dbcc0d2f5a4879d7cba27a4ba55e694d6c1ef2de3d16f3c7793aff0
MD5 6c919facbad90b70660ca653876236c7
BLAKE2b-256 3ec5a747782f66a6d76eff12349d6b1a6c6122e8aec8f90e04464497d70e1fb6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.7-cp310-cp310-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 287.8 kB
  • Tags: CPython 3.10, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for spot_planner-0.3.7-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 dbe77111f8e8da2e369d787647529a06cc359819a8135d2224c99b8807aaa326
MD5 70daf7b82de26257767fe8aa35d81ab5
BLAKE2b-256 857885abb42d7ab538ecdced359ac6779d30e06f143b61c8e6147ea453b33fd8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.7-cp310-cp310-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 278.3 kB
  • Tags: CPython 3.10, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for spot_planner-0.3.7-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 38ad1bdbd810caafdcbac04daff11573767372d7a51c8df7d4e9bbefb56857ed
MD5 34900ec5c462103854799045bf619692
BLAKE2b-256 1489205699af9ceb045c84b8dd1bb0acc06f0b2c87a31129afa394b1abc086ee

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