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.4.tar.gz (36.1 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.4-cp313-cp313-manylinux_2_34_x86_64.whl (260.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

spot_planner-0.2.4-cp313-cp313-manylinux_2_34_aarch64.whl (251.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

spot_planner-0.2.4-cp312-cp312-manylinux_2_34_x86_64.whl (261.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

spot_planner-0.2.4-cp312-cp312-manylinux_2_34_aarch64.whl (252.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

spot_planner-0.2.4-cp311-cp311-manylinux_2_34_x86_64.whl (260.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

spot_planner-0.2.4-cp311-cp311-manylinux_2_34_aarch64.whl (252.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

spot_planner-0.2.4-cp310-cp310-manylinux_2_34_x86_64.whl (261.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

spot_planner-0.2.4-cp310-cp310-manylinux_2_34_aarch64.whl (252.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

File details

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

File metadata

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

File hashes

Hashes for spot_planner-0.2.4.tar.gz
Algorithm Hash digest
SHA256 71d18e3b5b950f35f33b108263a94f7523de32e90cfd916f3567177bccc36f9c
MD5 ab65a0a9341c993bc9ff2d037283eb4e
BLAKE2b-256 110956495c80080d760e187f14d635326bb2c308c76f32547a083b59effe5651

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.4-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 1c83580f4a50c70dc1b8454488ea30686777799ab2441cc6822dbc3018ba5c01
MD5 1184bbedf81450590392ead61bbb6229
BLAKE2b-256 e23f8d1933a0a6ff4bb21207748f59733f4b6a75e6a93ef8206b03d5a7e8efe7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.4-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 140b551a3dbcfa8fb5cfb7379b1108cb5f98689b5edb95adb1f816d98dbb21e3
MD5 c1c2ef9b9e321333e87d7775a7fb15b8
BLAKE2b-256 b01b22a75c90a5b426887d6bafe913f9856d828c9ad5b35ef86d3965cab96880

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.4-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 6f241b2663e9c88473cb633bb3afad2e95e87ae6b46933cefcf3013f86e51bad
MD5 b948858e98d87b1cfbce14ee8e989875
BLAKE2b-256 94a64ff8853d7c08af4fc1c04ce0b287d50989136816ec0bd414c245b47309e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.4-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 43ffe2cbcf73f1d2d13415e79681c0635d582b71c7a583d5abe6a33135c9407e
MD5 b8a12c2cc9d857fa9928033e01ae95c4
BLAKE2b-256 07529e9f91f9ca5ee7d46639e7a33c4d94f50720436f39a9292d8891bfc8c5a6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.4-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 cce151ac607123c82e7d4f879c04f1f735701a68111dac14411bf61f00d9fe5b
MD5 2a296142cf5115ab74c232a394f77f9f
BLAKE2b-256 fb5e11dbc7057c6cdbb35b40f5c0272efead8106ce083899d1b17b0237b5aaaf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.4-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 f94fe3d2cd9f81f0c5cd7c3c8ae26f61e5e5b7f012ecfaa6d5bb823c4d97236d
MD5 4e992da4025a2dd974e89d2bbf9b7177
BLAKE2b-256 26428f70fec90938081791d102d28c549cc23c38388580f0aef0542cd5dd4f65

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.4-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 328882c7f65b4f7e06cef4b0e9952adb116f2179d83d71347fcbbc9fae5957be
MD5 045558a2c558d3927b46daaaa06a3b27
BLAKE2b-256 5efbf63e6018a780033d02bdff0175f330c9b5bd6d039674ca0d31214bf6537a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.4-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 ee93b838e353b10064d1fdca62b016d0afc9d8c02047783419f512da7606be01
MD5 eb29c31b96c00d9bbc8e7d3edbf13368
BLAKE2b-256 b78ac20a541e8a2f9cc188a0d64c4ac16aed0a695750227269cfda4719f6dc80

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