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.9.tar.gz (45.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.9-cp313-cp313-manylinux_2_34_x86_64.whl (267.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

spot_planner-0.2.9-cp313-cp313-manylinux_2_34_aarch64.whl (257.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

spot_planner-0.2.9-cp312-cp312-manylinux_2_34_x86_64.whl (267.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

spot_planner-0.2.9-cp312-cp312-manylinux_2_34_aarch64.whl (258.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

spot_planner-0.2.9-cp311-cp311-manylinux_2_34_x86_64.whl (267.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

spot_planner-0.2.9-cp311-cp311-manylinux_2_34_aarch64.whl (257.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

spot_planner-0.2.9-cp310-cp310-manylinux_2_34_x86_64.whl (267.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

spot_planner-0.2.9-cp310-cp310-manylinux_2_34_aarch64.whl (258.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

File details

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

File metadata

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

File hashes

Hashes for spot_planner-0.2.9.tar.gz
Algorithm Hash digest
SHA256 5f43b00cf3725d328b5bdde8c5251046afe482dd1ac5d5234b36f0c0c74aac4b
MD5 b2e5709a2e6a03970cf093c30d9d45a5
BLAKE2b-256 9e04019bee0b5f16bf5bd9f460812457ba0f494f63dcb00ee9b4b2aade97549b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.9-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 9c235306b18bb5bc1f6c95a1cc476a1eb2611f742ffae37e8f00edad31f0670e
MD5 299a1fd7ed0156cee7a9fb176addc44a
BLAKE2b-256 7f2fadc9bcf850d5686f96fa63cdb3620e9f43d3bf1b4e026283bfdcedc3950b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.9-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 ea40bc9c4da29b0e1ebec0e7cb3984a0146ff23690390ea256cb3fd73068b2a2
MD5 72f7f9e130a818b7a304cf0a36f94e7f
BLAKE2b-256 9c95038ba2b837ea1a91f23f2f1307a3a8a4c4eedf48212a883a4f9b59481b35

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.9-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 dc37e039da767dfc73928bfa7f819cd10b891b6ef3c996c23f10eb69c1aee1f7
MD5 9e97566657b551e34d1d1ef5f9de2d94
BLAKE2b-256 e06a3692d9c96dbc5e6a98e1b603bc3770bbe00de70389e3eb9d0b66c127cfdd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.9-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 b471d0191c0104bf38061ca21e85a811a7ff81e7cc78a2bf8e07c46982dd4441
MD5 604d3f3b9b073e9247afde915ae818db
BLAKE2b-256 62be6953009a0d9572f72ac2a467ff37b40c1a7a7f49a2a308791337e239ed74

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.9-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 3477e7cd4fffe5e0f3aa8fc7cd878d0f121359dd84e0864f0658c4d0b3eb035f
MD5 32071a900435a34231b323ffef3483a8
BLAKE2b-256 a8ec8b27874f8cb2ee9909201990616f3f525cb1949ec6189665f145002fe846

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.9-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 ef0c96f6bf80e86eabb0127b02025633f7348e486b7da8e4be28eed33707b56e
MD5 86c554298aa953b0dd6f3823a2b645ce
BLAKE2b-256 6725cc525a93fb27c17553e4a2fa24eba88d4421455a273b1e379046756a1363

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.9-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 74b312baf2036877f22f7d20437f7afa785785aba3a34da8aec5040fb9b88723
MD5 2f83df7d10791b64e5538659e2f388f1
BLAKE2b-256 1893f4585bc15c16f6f7a75a5808b88b720076b04abfd430545d7dfba1d6a6b1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.9-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 f3765cb4c95404fcadc0ad07b4b832aec937105d169fc476d257daeab336228a
MD5 fbed78aa4fb09e331aed02cea089b250
BLAKE2b-256 93b6c8aa14dd11f02645f7f3152ee9e38ffd1e6df826770334fa285834655973

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