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.6.tar.gz (38.0 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.6-cp313-cp313-manylinux_2_34_x86_64.whl (261.6 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

spot_planner-0.2.6-cp313-cp313-manylinux_2_34_aarch64.whl (252.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

spot_planner-0.2.6-cp312-cp312-manylinux_2_34_x86_64.whl (261.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

spot_planner-0.2.6-cp312-cp312-manylinux_2_34_aarch64.whl (252.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

spot_planner-0.2.6-cp311-cp311-manylinux_2_34_x86_64.whl (261.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

spot_planner-0.2.6-cp311-cp311-manylinux_2_34_aarch64.whl (252.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

spot_planner-0.2.6-cp310-cp310-manylinux_2_34_x86_64.whl (261.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

spot_planner-0.2.6-cp310-cp310-manylinux_2_34_aarch64.whl (252.6 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

File details

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

File metadata

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

File hashes

Hashes for spot_planner-0.2.6.tar.gz
Algorithm Hash digest
SHA256 fa4e4e748fa574a48c8a55a4cb4d549a0b72a02cba143436eb2fdc07a01a060f
MD5 a0b3ef00020cf3a55e3d1cbced81f275
BLAKE2b-256 7270f9b2aa44bc601dcff6aae278030e4d325fd061e0d9aca067b9c6c2432f13

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.6-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a558cd13b5df89c19db8720c254147d7167bbf03dea0ad1dbd9bbd3295e44d42
MD5 36f7875f526e3228e349793c2f0d61be
BLAKE2b-256 11aca56d43bc76690d8dc6c981ad961a7ce53b1c44ff86a2ead9dacd67a34904

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.6-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 571dbedeb312edfe47b7af139a4487f3bf7b192c22a275ac34ae1feb2c3ee371
MD5 63fc1d4251cb917bf364acf1aba00cad
BLAKE2b-256 be4ac53bfe78b3cb9d914046b4a4960c0cc4064729971eb59efb05b5ba87e003

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.6-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f16ca85f71ba7399df89813bd8e7492dfedd54189c0cdb6e22b466f57f2aa3c5
MD5 7ae70b55b992118ad30939ef07667516
BLAKE2b-256 51379ed070d4cfb12a40d0407f64a8752f62f97ff74aaa61a3814ae69bc4f98c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.6-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 71d3e3b5343c12e6d2199bc05ab364c5d32cfd23a886b7798967c22675211f01
MD5 cba4755daad52931f10dbc7527b0306f
BLAKE2b-256 20d254e81c72cf24b5848139c1331f76daf73e2e31fd6eb52492c55518d5f0ef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.6-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 d1a0637136f540c94b13ab7fbc7f7f10980a911511bf05823d4267414729a5a7
MD5 49afa5e07713352cc0bf71883bd2f439
BLAKE2b-256 c23f430b2df9bc891843f284b66ceaf3c56e1552873c2fd1aeb66579c6399a92

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.6-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 36ab42480b8ae5e851bbeb4055b528460f6640d707a31cc5e69538cf8b07a881
MD5 150145f63f8fc7ecfafcdf9e1c0933f1
BLAKE2b-256 055f092a1ed5d55da2bf36f048bf64bbd1a06c65a81ff0d3746b7ca8e14c40ee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.6-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 bbec386b010ebab253867d7b232efdc9c566b506c6bec88b3455e8c9888735c0
MD5 ed80f219b478f306a2ee3425186be323
BLAKE2b-256 dd0447036f850574748309494f6bf9e2b519f3ec00a880567d1a18349321e54c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.2.6-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 497d90260617976403a54fb06813f68c4edd1fcbec8f13e778e2e0683f9c6f3a
MD5 9d604698988a8dce7c8f0d0969a18169
BLAKE2b-256 662291c922810a0be4f9264ed1c6e29f48cc661c4a5a164e004b6eff8a9f2fd6

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