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.10.tar.gz (46.5 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.10-cp313-cp313-manylinux_2_34_x86_64.whl (271.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

spot_planner-0.2.10-cp313-cp313-manylinux_2_34_aarch64.whl (261.1 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

spot_planner-0.2.10-cp312-cp312-manylinux_2_34_x86_64.whl (272.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

spot_planner-0.2.10-cp312-cp312-manylinux_2_34_aarch64.whl (261.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

spot_planner-0.2.10-cp311-cp311-manylinux_2_34_x86_64.whl (272.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

spot_planner-0.2.10-cp311-cp311-manylinux_2_34_aarch64.whl (261.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

spot_planner-0.2.10-cp310-cp310-manylinux_2_34_x86_64.whl (272.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

spot_planner-0.2.10-cp310-cp310-manylinux_2_34_aarch64.whl (261.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

File details

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

File metadata

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

File hashes

Hashes for spot_planner-0.2.10.tar.gz
Algorithm Hash digest
SHA256 161343232f9597cfea4c9ebbc9bed73138f8301d8ea2d40ff01451195e261eb8
MD5 15f060ce0c67e7bd56adb844f2006acf
BLAKE2b-256 b5ccc7ea0139aed556564e43379ff0768d0997258044d1e8703da8fb99402b18

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.10-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 dba63dab31cd7ba44ed29b8e1036f012a733b84e24e6c307af87655ffa523d6a
MD5 dd78a03ffb65980d7caa4b3a64bec744
BLAKE2b-256 16a9806b40d0b506c8d5e3d607e90e04040069b7442e0256a2d6d5deef2405db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.10-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 5e6084d8bac37335362cacf261c1b9cb28080edda0bb3489841cf9d834361f99
MD5 4f12f3d64916260a7fea2fab6dbd6e7f
BLAKE2b-256 e2a91ad1ac8eb151fb9680dc94932be43e5156ef66182d9c61dbf925b4f6a857

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.10-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 6d75861fe3aff4f644f168918b20d078dc95c2db7c357378dcc1bdbd328af1ef
MD5 188aaa6f8a14c5b24b608ac5bbb02507
BLAKE2b-256 9ebae071280328e5298fb936f8086f93b0688b5fa6c5b0d0aa6110627aa6247b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.10-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 52eb9d3b8e635b9010be0db12e168ae74307be5c93f90955f39f8b3b425f3c9e
MD5 18a8cced69498b543a15958b60017400
BLAKE2b-256 532033d88e65a9aaf2ba2c803dd9f2d2f0efbb73163920a90178d509091ac9eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.10-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 09688d4e4951a231cb0af0ef441dd57eac17c45455f146d22da3e1e03313f1ae
MD5 960a8dad479233203a50ca69d95410cd
BLAKE2b-256 5372f3e412469734f764878c050cc6e06f19db052cb5f8558e2c2fa242a0d3ba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.10-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 7603c9aacd0de6cc8563e6a4482488f483c786663324c67e6cb0bc5dd418475f
MD5 52a07dcf2d0e5135c0b9f90fc757d06d
BLAKE2b-256 ac7496c198b11afe25c8d4564d1c913cde26c2c6ca14f6225fe72171c9c416ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.10-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 c5a6a2be2942d85996186f5a183bdeb5274647e63747ce256c9393dc9d3352e5
MD5 002a5453186320030ecc355c47bca9c1
BLAKE2b-256 c12c2ea654db69ef8c78aa003ed237db2df59149413563c2cb7158cd391c0beb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.10-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 2792aec6a1d07af0bff5390fe2bdff267305ca33bcde614ea5177db51f3e3ddb
MD5 9d06336a36827cfc7698af370e93c431
BLAKE2b-256 f66ae36f058f673dccd0e734b434270df8b15d43d84ac7dcf7e10fef7bef69a6

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