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.1.tar.gz (843.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.3.1-cp313-cp313-manylinux_2_34_x86_64.whl (275.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

spot_planner-0.3.1-cp313-cp313-manylinux_2_34_aarch64.whl (265.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

spot_planner-0.3.1-cp312-cp312-manylinux_2_34_x86_64.whl (276.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

spot_planner-0.3.1-cp312-cp312-manylinux_2_34_aarch64.whl (266.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

spot_planner-0.3.1-cp311-cp311-manylinux_2_34_x86_64.whl (276.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

spot_planner-0.3.1-cp311-cp311-manylinux_2_34_aarch64.whl (266.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

spot_planner-0.3.1-cp310-cp310-manylinux_2_34_x86_64.whl (276.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

spot_planner-0.3.1-cp310-cp310-manylinux_2_34_aarch64.whl (266.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

File details

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

File metadata

  • Download URL: spot_planner-0.3.1.tar.gz
  • Upload date:
  • Size: 843.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","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.1.tar.gz
Algorithm Hash digest
SHA256 438e7983c8bd69ce503d2eb2be872c0e659d20cdaa52063e0a20631cdd175641
MD5 a294dcf161cee678817251ab22bfa947
BLAKE2b-256 688366855ed90833c008c9e34e3e52540b58ac7e5ae68e277524604a3c1f6cb6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.1-cp313-cp313-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 275.8 kB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","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.1-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 935a4828ef50950c2c339261a2d894675f164a52f849cc4ac96e3f31982a204f
MD5 228ccf4d7b9b2bb0c0cb637043084cce
BLAKE2b-256 7e8f386b063441a173de70992e108605df0dfac0a1c7a01a71dad288e8f87234

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.1-cp313-cp313-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 265.7 kB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","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.1-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 60e226ab19022641ebb139505e22d0595ce0b469d89f7045c8230a6192ffdfaa
MD5 32f4f0674d9a00faf1da2e2a22035bda
BLAKE2b-256 0ab5e90e81d58c1dac827f6145d0f17d3ef274b1fd23221ed6bc44aadba44856

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.1-cp312-cp312-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 276.4 kB
  • Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","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.1-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e0358422a884f54cce56cc789e30f70cea3e9c1879e7c145a4cc5f1241d98669
MD5 43b36de6901b4fee838b834a2f3c3ad5
BLAKE2b-256 977e5b2176d170d337aa832ca42a03e164212d669610e47343cb7b7559e07143

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.1-cp312-cp312-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 266.1 kB
  • Tags: CPython 3.12, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","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.1-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 9ba6ce1f83e38d63c2ca397496a335fc74470bad52f42b4281e67b21109cd406
MD5 f819db8b7b85b248d5569e51f9322ab3
BLAKE2b-256 bfd3fda27dd32bdf3d1ec2cd5dabadf7a9bdad6a1af1fbb4892ff75402652767

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.1-cp311-cp311-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 276.2 kB
  • Tags: CPython 3.11, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","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.1-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 446535101fd60bc56d0624cfac93ede8015198e580ff566aad078e0f53aedb28
MD5 a8c81797f094b9f35ab34f04087ee2e7
BLAKE2b-256 284653086f145961f0c7737cbf113ec086b2ee60ecd56c90505e8ef1f37665e3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.1-cp311-cp311-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 266.4 kB
  • Tags: CPython 3.11, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","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.1-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 aa106b8495005719fd6dbe03a3387865c18ac0011078b12f7df4aa882ed8a8b5
MD5 31659aff8da5ac6442cd9cf290a9d3b1
BLAKE2b-256 1693ef6a1710e6ccc1ce723c5c80be1ce6f8c25fbaa04ac3c463ca05749c1b4c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.1-cp310-cp310-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 276.3 kB
  • Tags: CPython 3.10, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","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.1-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 cdf6a91ba13ed6e6d3b16e1cd78af38e4ae4e725b785e88658edf11a2a7f2d47
MD5 9f73e83cfa68f177ecef51845f01341b
BLAKE2b-256 9fdaaffb57384cbc6b786998aa637159dae182373ad1ba0f741793d4553904c7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.1-cp310-cp310-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 266.4 kB
  • Tags: CPython 3.10, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","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.1-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 1004bba3567e1015044a55738e0106d71bbc72634f81b0ce1e1ece30730f43d3
MD5 83c68f0c9e518fc96357269011296f99
BLAKE2b-256 41dbc4c0536d23972595eb86d748fdb0874d45137c3e418ab95ce956493ded19

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