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.7.tar.gz (40.8 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.7-cp313-cp313-manylinux_2_34_x86_64.whl (267.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

spot_planner-0.2.7-cp313-cp313-manylinux_2_34_aarch64.whl (257.6 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

spot_planner-0.2.7-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.7-cp312-cp312-manylinux_2_34_aarch64.whl (257.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

spot_planner-0.2.7-cp311-cp311-manylinux_2_34_x86_64.whl (267.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

spot_planner-0.2.7-cp311-cp311-manylinux_2_34_aarch64.whl (257.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

spot_planner-0.2.7-cp310-cp310-manylinux_2_34_x86_64.whl (267.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

spot_planner-0.2.7-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.7.tar.gz.

File metadata

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

File hashes

Hashes for spot_planner-0.2.7.tar.gz
Algorithm Hash digest
SHA256 6f54c016cac4406bc11aff5db78ea7d811409f25fbdb53df018955274ab41548
MD5 c8693c73cfa2331e674d4d64281fb8fb
BLAKE2b-256 94f46018c4117bbf9da1e325b5038f48449dfb587f8da1818560a79982cadbdd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.7-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 b37b89dd4d064644d4331333c6fe3829bcea570dd353c5541ae6ee8629b2ba4e
MD5 bb9dfec299775735c55cf185b86b05a5
BLAKE2b-256 2d2fd10444b15d83e46d479de6f98498bc7d32d0e99a36befa00fb3fb3db40e6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.7-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 f88a9c53b718f3412929e681c7ab11b866f81e2b18170281db557ff20ed1e089
MD5 299bde253dcf8e51b652af80cf58e680
BLAKE2b-256 542bd578b4a4949dc95fecc2871b0a7cff09b4eafc0c09ca5be408016741e859

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.7-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 42c340ddff50f5173891ae134847f716beceb0463b0a660ea97ae31c562ee264
MD5 603bce3f9eb7953697b7b9991070f1c7
BLAKE2b-256 b1450bc479b7b7dc00b33a3bd31bc5c43d9e5f036bab68bb7c8e3a97b3fd776c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.7-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 43295fde0d1a71d554026512b24453fa5a179648fc5a8298c99a2539c3f7bc9f
MD5 b2c32e12066651d184c592e707e601fc
BLAKE2b-256 472826100e2ecce4d551ce9ec38b12aff0391d8aaca566cf5ba9577558330928

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.7-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 24aa90ac55379b1292789960e815189d40f43abf62977a237bdcd779c13998e7
MD5 3e2fa4a6e9220bdd4e71a259e084f049
BLAKE2b-256 0c60a28136821993ea2d7d3aa40d3e83cbb33841dc13108c21ad155adf193d2a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.7-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 c263cc1c120024aac97df1c3281046ed8cf0e2863233e4f69d0b116f104b49f6
MD5 0f2cc9eb3d7dd93722ae2ac34e4428f7
BLAKE2b-256 d6d0c885bafa56f68acc8a8309415e2ba6aef0026d347e4786019994caec8f7e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.7-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 190078a8e655d9f2b41175198ad92fbc63acb2ec95dab2441fdf285b90457c4d
MD5 32cf663b6db0cc30e459007039605f33
BLAKE2b-256 61730acf750235e6def9a41e354ea7942edd6e1475a31ccee78ea1fced0f5808

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.7-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 152abd758d987f347365d849be29393d06ffaedaaeb2627abb85eb73bee4816f
MD5 b31de3e73a737d8dcabd17bd9516e2f1
BLAKE2b-256 ef7edbebb8f33ba83bc7d93df0fa3ea26984b33a85c95a232bbbf1f4ec21838c

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