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.12.tar.gz (45.3 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.12-cp313-cp313-manylinux_2_34_x86_64.whl (268.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

spot_planner-0.2.12-cp313-cp313-manylinux_2_34_aarch64.whl (258.2 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

spot_planner-0.2.12-cp312-cp312-manylinux_2_34_x86_64.whl (268.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

spot_planner-0.2.12-cp312-cp312-manylinux_2_34_aarch64.whl (258.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

spot_planner-0.2.12-cp311-cp311-manylinux_2_34_x86_64.whl (268.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

spot_planner-0.2.12-cp311-cp311-manylinux_2_34_aarch64.whl (259.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

spot_planner-0.2.12-cp310-cp310-manylinux_2_34_x86_64.whl (268.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

spot_planner-0.2.12-cp310-cp310-manylinux_2_34_aarch64.whl (259.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

File details

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

File metadata

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

File hashes

Hashes for spot_planner-0.2.12.tar.gz
Algorithm Hash digest
SHA256 c5a77ff52557224d569ef8abbd93ab5c4998dff8c9127a13a5114bfac873089c
MD5 e842ba7e2172059119d96d8ce26f700c
BLAKE2b-256 1cbcb3cc4874923ad8190187fe4776dc729cbcfb2076e0c26a8e3b5a67907afb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.12-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 0b25ad98d8efa586b20ec9a56d633c8fa420f3d02da40c48142ba66897828ca8
MD5 11a33297951892e63a76de7ef49d4eb3
BLAKE2b-256 a89d21319a75b5d6fd91ebd499e30dda96fce1311868588e5a1eb9a305911401

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.12-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 befe217ee972089a06d22f4dc0db76747cccd0b13849a10e263a9cd515b76e98
MD5 6848586841866353b1bc170215b5593b
BLAKE2b-256 2f9ff51aad4cd5612605dfaf4faf119178799a041d62c04320cc1d3f2384eea4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.12-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 76dda7fbb9cb7c808c206e1fcf018d02d30851e00e7d80219b03bdd4e693b907
MD5 457780d7e55852365f9c6dd50795d96a
BLAKE2b-256 395862c45cbd387237a3b4a830a11934d1fbd42c2d0a22ebc18a560496f546d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.12-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 5853c909dd408106fe964b706031f5b5071e91e7c92f61eade7ddf7d2cb6aaf6
MD5 0565f3822d18fa2166844152ad491277
BLAKE2b-256 0bdc239863e966650fd872a0ce7f7b7d40eaab16d28e5b21dd8e999c59e4135d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.12-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 168cc930962073d3fbab1ebe1c6088b0b9706fe9abdb51637ac69b5d6dedb05d
MD5 833fcd71719e284c900b6eb9fc6443dc
BLAKE2b-256 c16ba983a1c97ab6cc1809ce0b7b336252abc84fc19dd333a85046162c78794c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.12-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 efdd0bf8c46501d7705853703dfe9b8bb386f25061a37bce59d262f00379bae1
MD5 2d76fe0f78362cee0e2e9e43d1203073
BLAKE2b-256 4f0f36da0161998ba059b64cbf81c8249e584c2b1ca4d07c4ee7320d86d56b15

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.12-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a6ae91fd94e826a189b656a0a7cc21015e9d20b63cfaa58c45d5c368625404da
MD5 93520b8591843ccf73ce3a07bbe9c137
BLAKE2b-256 bbb0a1a8f650743a3aedfde2f91039e5c22c43e239c171132719d560ccd5c7b0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.12-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 e3df6f0268733e57c2828cbfc5b063fb1ebf3d40844cce4f9bec6224f2628dd2
MD5 67a699295259976920d1daed1dbf63c6
BLAKE2b-256 4637debebba4cd5f3d52a43e10d5737077d27291774db4f024c3697d04eb8869

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