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.13.tar.gz (48.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.13-cp313-cp313-manylinux_2_34_x86_64.whl (272.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

spot_planner-0.2.13-cp313-cp313-manylinux_2_34_aarch64.whl (262.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

spot_planner-0.2.13-cp312-cp312-manylinux_2_34_x86_64.whl (272.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

spot_planner-0.2.13-cp312-cp312-manylinux_2_34_aarch64.whl (262.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

spot_planner-0.2.13-cp311-cp311-manylinux_2_34_x86_64.whl (272.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

spot_planner-0.2.13-cp311-cp311-manylinux_2_34_aarch64.whl (262.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

spot_planner-0.2.13-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.13-cp310-cp310-manylinux_2_34_aarch64.whl (263.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

File details

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

File metadata

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

File hashes

Hashes for spot_planner-0.2.13.tar.gz
Algorithm Hash digest
SHA256 4fcc4e72d435f5dabe22bb0491e0eceb0b7463aa66b874385343358092207c3c
MD5 dd64fdc99ac2bfbf41beac94da40ea6b
BLAKE2b-256 745375eb7a77a5cd47049071da90770066fef32d64907a751e90077552bfb4eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.13-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 00f689cb5652446ee563470169d520ddcb66b8971c5fe02087587c8653400e0e
MD5 dd569658383b2038a1f80a4d106eaed0
BLAKE2b-256 7b0e593aebb73e93e6db982cb94204d006531a04b1788a77905f53079fe460ee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.13-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 534c244c629fc70124f2bdce9b899ebc6630fe2dca965a51f14393c7af230592
MD5 f6a52288b5cfc938b0e73fb2fb84a012
BLAKE2b-256 61784d82b9320cd5aacaf9848ae50103d001a6711d0c37af2c367caa8354d15b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.13-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 53785d8b4d9f970f05cbe0f275f61e05125511d7058a8f1d9fb7d0253acc920c
MD5 2d8be1c76cee02eee6e2a1bb70f1cc25
BLAKE2b-256 f9898e2937b9a413b764b6c1b9a00ec3a1530e792ff41cc9ff04292f091d7c39

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.13-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 7c468e7ea4105478a92e9356601a23aeeab8d1c802488c2d14d4b6f7098f1df3
MD5 228b182d8e6f7205fdcf7bd8e42378dd
BLAKE2b-256 7f2a7cde3a48b7d79362cb8da15ed9678eb38fcefe7d7984c04888f316fd21c1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.13-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a04ef957180ef065efbe03d55586a8c6b2e319733770f41d43ed019a702e1ae2
MD5 67b619475816b9012c0bb46c29e5a286
BLAKE2b-256 ad95b5c7f64b69094bcfab3dc25cd0002af5078a1fcb6f913cadb2476373a492

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.13-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 404ab41edb3109053c309f8cf104238e193fa78fc408d4f06372696aee7fc1e7
MD5 fa40c723233c912f53b42b98d5c24c69
BLAKE2b-256 417f69e3f332f4dd7699f2941ee8f85aa90fbf02f98bacf90dfbe0ca230ec295

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.13-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 28dc2fd24c5d8233d860ed8562e6ee57e53c2c8e12130671d1fab7e38b3a7e0e
MD5 3ed7bca2fded5f596f913c804b6b7201
BLAKE2b-256 a56b4bdf6c5b3a50f1d75808e95c2a326ea8f2c93a9cf6b2d1eee073bde2e738

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.13-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 d0786b1a0c1afc4c1f538333a18a06ff5dfde19a0a7ded041613523bc9805275
MD5 413351a1ea2562bf1fcb611ebb5e10f0
BLAKE2b-256 44496a57623ad3455c89c2359165b7ac738b1504883fe72cbc04942f05c35676

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