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.2.tar.gz (31.9 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.2-cp313-cp313-manylinux_2_34_x86_64.whl (260.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

spot_planner-0.2.2-cp313-cp313-manylinux_2_34_aarch64.whl (250.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

spot_planner-0.2.2-cp312-cp312-manylinux_2_34_x86_64.whl (260.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

spot_planner-0.2.2-cp312-cp312-manylinux_2_34_aarch64.whl (251.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

spot_planner-0.2.2-cp311-cp311-manylinux_2_34_x86_64.whl (260.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

spot_planner-0.2.2-cp311-cp311-manylinux_2_34_aarch64.whl (251.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

spot_planner-0.2.2-cp310-cp310-manylinux_2_34_x86_64.whl (260.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

spot_planner-0.2.2-cp310-cp310-manylinux_2_34_aarch64.whl (251.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

File details

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

File metadata

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

File hashes

Hashes for spot_planner-0.2.2.tar.gz
Algorithm Hash digest
SHA256 29c7e7713e1dccb0e7c55a724a2f4fd0ceecc063e7b6dd888aec86204b257d83
MD5 926703a061d4f9f1ece44caaf7a8ada9
BLAKE2b-256 f9507d4be616fd47acdff9e9937195df358134fb67be4aa3a5d161eb1e4aa5ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.2-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e29d4d9c8e3575df406d0d6e0057368f993c635f4134ccaf196d7e381ad63407
MD5 f8c4c276ec5d9c3ccb9de4e1ef7640f3
BLAKE2b-256 b0c91290fc83e7667ddc79806632cb5bb84241f3fc1964486309c545acf75794

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.2-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 6e015b48dc2dee1cb6f080ed63d4a1871bad9ffd94fb6a5468209181e03ae474
MD5 828a4deaa64dd1a812c7e9e3677fe6e0
BLAKE2b-256 0f118e5b6f271491a302d6d731b7ccd7dbaa40d8a218d31a34148be71f53a604

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.2-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 4f8a2b178cdff4cdaea8e67545f364095809a9ca54428086e5611166c5e606dd
MD5 20445289108a7ac61629c8024a879a1d
BLAKE2b-256 d181cda9f6f8e61d3a7285075fe81894fbaecf0dcda516cfe57145d12406c838

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.2-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 681c61c3f07637e0826541a3bbcba09dbbfb898c51bb95d36b48c61c6c7a6341
MD5 8c6a48912ebe1f4333f6faca9944c1de
BLAKE2b-256 2466efe20e19a053989d4a503330d392cceda61bcd95f4759844bd86d7e25fd2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.2-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 69db883b1dd4a829f26a5f4ac83eb5caf5254c2fb641f5980d6e7cb2863014b7
MD5 bffc35b8646282aa280bd09edf70bf66
BLAKE2b-256 5d1c5a30eb47ac552faf96b98fd126088c514793834ae7933a32c6ccd75990fc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.2-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 81f01debd88cc9280dafedbf000b8f2d46a885490c36a0e4bbb38940e040a281
MD5 a0de901d9adcb8b3d6be65583eccb614
BLAKE2b-256 97a639f4625aaf70f74e40c8c9724dc91f9b029a9969d5d11a8b4f1ce8a778c8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.2-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f449faffed61ae039d9af651162971abca2f7c8fe17eda99ab1fcbe62dfd7b29
MD5 667228a2de64d27321c22500d9b96048
BLAKE2b-256 4b326bb64a4c4b9e1dfb2a0819cd1ee2074270c345b4e147ba5ceb293b3462e3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.2-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 b162611e8aeaa597b08b912bd6c052f41f39ac54a2313f90082865d4a97e6df0
MD5 40bdc6ae4ccfa0d0b6aa55c1f827549e
BLAKE2b-256 639acfdfd6212af841455615b88a5da4339c277a536f2c75d66486bdbbc66b3c

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