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.3.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.3-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.3-cp313-cp313-manylinux_2_34_aarch64.whl (251.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

spot_planner-0.2.3-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.3-cp312-cp312-manylinux_2_34_aarch64.whl (252.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

spot_planner-0.2.3-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.3-cp311-cp311-manylinux_2_34_aarch64.whl (252.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

spot_planner-0.2.3-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.3-cp310-cp310-manylinux_2_34_aarch64.whl (252.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

File details

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

File metadata

  • Download URL: spot_planner-0.2.3.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.3.tar.gz
Algorithm Hash digest
SHA256 4436447b2623e11b48605c3dbf08ae983288adc4c0eb0ff40240d67842b913e9
MD5 95d34ced72d68d7fed28d1e00802fb77
BLAKE2b-256 50d10f83730497053d2e26fdb5ada006c7022c6955b153c61752ac8ddea0c495

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.3-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 8746cc2b7eb53b796b0c18c2e1ea8338f27839b12f9d735012952d5ee5905d71
MD5 2dc1df8c10c12cabf91f8b6dcdea0857
BLAKE2b-256 22ccc3024d293b4ed1ccc433f11cfdfa5b7b5ef5899d41dddaf49294c52101e5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.3-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 c118196083929162f4613d733506ce64dc4506716f4c68a148a93f5669581e1a
MD5 bf3ec14e75cfc7793a4690a3c631de59
BLAKE2b-256 3396abd97a19071c5c6ff5fdcdfe21de204ce07755cd26ed357740811af64208

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.3-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 74ed3f5a7bf5bbdada90622bebede8618c128f8c3a606887011dc38c6d616ee5
MD5 2cb5635d41a9997d0553c93209c39776
BLAKE2b-256 4d5f9d41f4558cf14ba813d40a079af3d6fc051245de95472c113bf35da3928f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.3-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 0b70b2ee70dfd304a32e2239cd79cb87c764be2aa5751f65e94a4e4c3c11857f
MD5 9173af9513fa5c31c86e0485fc054d33
BLAKE2b-256 5cc5240ac8d96405df26757624202b43b00ba7bc69b0a9dcfe1d25b16fa09ccc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.3-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 09723c9d7160b4cb11432a696ccd87e6f6de024cd752105b7f8519798cd150da
MD5 8692d9b138f62a0327dfbfc7334e856d
BLAKE2b-256 7a784394f2b5dabb28500c48bb05271418d48cdd9e37f5f88a2c1c8cf78af650

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.3-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 1be2b8621025210745dfc8bf0877ee3b3f654686142bf166a573bbaba8b85fe9
MD5 c9df3dc13dc9b376bbef098fc102f088
BLAKE2b-256 1c5d179e4b79a00f323ab5c9d1f7e4cee0510a012f8253aa75da751946737ae9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.3-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a0e1ba66287bda19297c399d6a85331dc26392afa8589265eed485f294c4d615
MD5 27cddacf97c2ed6d0b1bce682b13abd6
BLAKE2b-256 414731c477fffa5e4f74d57341b022abb801650d500192881c7f7aa5133aa1d7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.3-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 010ae08af9c0109b61d448cbd79b5edd3ab45bd7cd797de564ac84de6b7cd7a6
MD5 b61f65e845de28f7c050c82c00e07cad
BLAKE2b-256 1b6adf7379e6efb3289fb1b24e1f5ec27a2a4f0224dc51bc9fc49e759fae8cda

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