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.2.tar.gz (936.9 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.2-cp313-cp313-manylinux_2_34_x86_64.whl (278.1 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

spot_planner-0.3.2-cp313-cp313-manylinux_2_34_aarch64.whl (267.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

spot_planner-0.3.2-cp312-cp312-manylinux_2_34_x86_64.whl (278.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

spot_planner-0.3.2-cp312-cp312-manylinux_2_34_aarch64.whl (268.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

spot_planner-0.3.2-cp311-cp311-manylinux_2_34_x86_64.whl (278.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

spot_planner-0.3.2-cp311-cp311-manylinux_2_34_aarch64.whl (268.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

spot_planner-0.3.2-cp310-cp310-manylinux_2_34_x86_64.whl (278.6 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

spot_planner-0.3.2-cp310-cp310-manylinux_2_34_aarch64.whl (268.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

File details

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

File metadata

  • Download URL: spot_planner-0.3.2.tar.gz
  • Upload date:
  • Size: 936.9 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.2.tar.gz
Algorithm Hash digest
SHA256 5997b5e410cdbf95925a3238596f780a5bccc347e2b21a31e64f4ac29a4dc02f
MD5 0744a3ff245be9c764eb415adec27d90
BLAKE2b-256 abe9b02065ff8223b30bda41a4e88d1d4bce4953cb25b26a21beb7e6faca0236

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.2-cp313-cp313-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 278.1 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.2-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 6034a1b6844130033493ecd84954535ffccd4bf2cb459276c0eb2c7f4ccb8c70
MD5 2ab88c171ccedf148efdee9f2afee2be
BLAKE2b-256 d17e5f9ca2823d98cdb00ed70611779dcf232ad389d98705675b4f70dbf32bf3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.2-cp313-cp313-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 267.9 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.2-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 583608de2f85020f63dee2ced0a563a0a7ea71c1764a0bfd6b846d49eabeadd6
MD5 bec1e3d68a312c0a0b00ed0ecd3721d7
BLAKE2b-256 045beaf8a280257f9b1a055b1b575718838026995d903d6c871ba42e78c53ad7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.2-cp312-cp312-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 278.7 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.2-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 4387626ab3dea947a8ddbfc5e6483878bd32ae79b48f519f5b48cb7cd69c5978
MD5 0b7ce75982b9c48ae330c05c10a89d86
BLAKE2b-256 4a671efd75c66ec28d13b35b76807d1a5552b97658dfa4a1751fe4e73f92e037

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.2-cp312-cp312-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 268.4 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.2-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 6086d8c0157ad5aa59d1d5346f5926702b0a5b9362cf4a9ec6bbfa7dc1e4a298
MD5 81c4ba5fc59fe49ce6e7f61651ea12fd
BLAKE2b-256 d132fa503e0a6669ad354e83fbc73805fb7ed84c3db78eea48f9c4d4a47c0808

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.2-cp311-cp311-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 278.5 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.2-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 0af246fa8bef93db563a388b37d50c72035d4d390e81c41d24518f10be530eae
MD5 1bdbe59865b924437b3e7c0293c1f086
BLAKE2b-256 954d4c3a3161afac57f397dc2d13be3e10691004a690a4cc6391aae9b84b3f88

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.2-cp311-cp311-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 268.7 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.2-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 f2ded09eda40127335cefd9cca84ab871fe4e51ae373391832adb0c903c5a09a
MD5 13296603eb572c0fded647ecd552a280
BLAKE2b-256 b522efa10c2720e5ee945376ab09ed720eae5369e7eafc5220d885b1fcced5e0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.2-cp310-cp310-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 278.6 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.2-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 091b488eea4add8d99068f2e9e738b0539459b867bade42e0726a6bef97b4378
MD5 9d429c831a036a92d230f735c833f10f
BLAKE2b-256 8cdcaa08badc22c7436aa51083c639a6d18f2c7649176ef94d35a1e1a42655ea

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.2-cp310-cp310-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 268.7 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.2-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 d1fd70a7328484903da0c3b5d94e91d1bf1187d33ba97b37edb49a790ec4eaae
MD5 9c53b0172e8665bb949d50184186a3ee
BLAKE2b-256 20430bceae2fc9ae71f9c98c369217d9ba8054e95042ec236b9243fb5a619f4e

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