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

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

spot_planner-0.2.1-cp313-cp313-manylinux_2_34_aarch64.whl (249.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

spot_planner-0.2.1-cp312-cp312-manylinux_2_34_x86_64.whl (258.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

spot_planner-0.2.1-cp312-cp312-manylinux_2_34_aarch64.whl (250.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

spot_planner-0.2.1-cp311-cp311-manylinux_2_34_x86_64.whl (258.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

spot_planner-0.2.1-cp311-cp311-manylinux_2_34_aarch64.whl (249.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

spot_planner-0.2.1-cp310-cp310-manylinux_2_34_x86_64.whl (259.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

spot_planner-0.2.1-cp310-cp310-manylinux_2_34_aarch64.whl (250.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

File details

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

File metadata

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

File hashes

Hashes for spot_planner-0.2.1.tar.gz
Algorithm Hash digest
SHA256 e96d21d85b4b7921457f04007d7b98a3418ddec0eef8995ca6c4d476c833efa4
MD5 f871dd55c3037a60e16a94b8491f43c6
BLAKE2b-256 8585ba13fd07ae8567a7ecb950d4816b54bf9e6c2a9348df04cfed904b23a53d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.1-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 1ef9143d621d584c42a9590feddac92cd0d64c1d6588ea4b470d94b4e178fadb
MD5 9907e9ecb41dd4b883a6193a98b29b5c
BLAKE2b-256 484048d5b2a135d7396994770744db0ac727d7e3ab078f70431e2d54887d06af

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.1-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 1ba416ae27711fd26b61d9261e10076ac6bbc8c3cccc8086d0eaacd59ca4c11e
MD5 b42cc725a04353a063ccebdd2a06cc5f
BLAKE2b-256 f2553e71d8d4f180132c0f7b224971eac2d71ab66c5dc13424a0fd6a9aa3c93d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.1-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 bf187f8bd03040df0e24dc7b0eb81d46b99b9889a2fdc9b2cda3f9d5b03bbb8a
MD5 77f8905d9fa7fb9edb08e71eb29b3aa7
BLAKE2b-256 e92491ee7998d564a1bbfa79cb56800cf9aef473272370fe625ac85a12fb0a45

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.1-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 f6e27bba0620868268fa21dd74a5373d94af323b61befa4af95c62f8eda07410
MD5 a07a43e284e78a6c6031c82173ea318d
BLAKE2b-256 c3241dc04f33346e64f29a06345d521a4740ad7c1e30924bf0c5c1fb79bc7391

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.1-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 473ddb7ca2aa7e50e641cd8b8d576999d486d86d4cd5a3783c21509f606928bc
MD5 26a65dae8743135a6ca27f6db6b29e19
BLAKE2b-256 56135257f71d906b1acc858f5527997b63978c43e510e71c6283de686f19ccb3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.1-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 25a2c97a93081e10749fe9f9c955d0b8d7339b8b986694de104b4517aaa9c236
MD5 84dba150df0fb22cef9561dd82a294b8
BLAKE2b-256 dc4b2cc68cc6a37008b8168e9762a59780b7fa5695d1d4e3c5c5b6d1bfa0025c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.1-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 feecf2faf4965f0556ecf49663ff87470a72d601eae5e5abddae95a95c293dbf
MD5 ec4ba15320fab5f57b634e7c0e4ea65d
BLAKE2b-256 e802c88b5da9c9b6f5845013b677cc767db5f344d6fe01c6516e31d68735463e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.1-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 6953278790db06d3fa2c0ec7e5c7386844bfe21cb8efe474de000330b1755244
MD5 7eb68d977ec144e7f6d0bf4babdceae3
BLAKE2b-256 bc81d2e08bba5747ec1d5803edef71dac7be4dcad17975c24bf92415b10b92e4

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