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
price_data = [
    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(
    price_data=price_data,
    price_threshold=Decimal("35"),
    desired_count=2,
    min_period=1,
    max_gap=1,
    max_start_gap=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(
    price_data=hourly_prices,
    price_threshold=Decimal("0.05"),  # 5 cents per kWh
    desired_count=3,
    min_period=3,  # 3-hour minimum
    max_gap=2      # Allow 2-hour gaps between periods
)

Cloud Computing Cost Optimization

# Find most cost-effective periods for batch processing
optimal_windows = get_cheapest_periods(
    price_data=aws_spot_prices,
    price_threshold=Decimal("0.10"),  # $0.10 per hour
    desired_count=5,
    min_period=4,  # 4-hour processing windows
    max_gap=1      # Minimal gaps between windows
)

Resource Planning

# Plan maintenance windows during low-cost periods
maintenance_slots = get_cheapest_periods(
    price_data=resource_costs,
    price_threshold=budget_threshold,
    desired_count=2,
    min_period=8,  # 8-hour maintenance windows
    max_gap=0      # No gaps allowed
)

API Reference

get_cheapest_periods(price_data, price_threshold, desired_count, min_period=1, max_gap=0, max_start_gap=0)

Find the cheapest periods in a price sequence.

Parameters:

  • price_data (List[Decimal]): Sequence of prices to analyze
  • price_threshold (Decimal): Maximum price for valid periods
  • desired_count (int): Number of periods to find
  • min_period (int, optional): Minimum period length. Defaults to 1.
  • max_gap (int, optional): Maximum gap between periods. Defaults to 0.
  • max_start_gap (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.1.0.tar.gz (20.7 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.1.0-cp314-cp314-manylinux_2_34_x86_64.whl (283.8 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

spot_planner-0.1.0-cp314-cp314-manylinux_2_34_aarch64.whl (274.3 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ ARM64

spot_planner-0.1.0-cp313-cp313-manylinux_2_34_x86_64.whl (284.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

spot_planner-0.1.0-cp313-cp313-manylinux_2_34_aarch64.whl (274.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

spot_planner-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl (284.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

spot_planner-0.1.0-cp312-cp312-manylinux_2_34_aarch64.whl (274.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

spot_planner-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl (287.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

spot_planner-0.1.0-cp311-cp311-manylinux_2_34_aarch64.whl (278.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

spot_planner-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl (287.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

spot_planner-0.1.0-cp310-cp310-manylinux_2_34_aarch64.whl (277.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

File details

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

File metadata

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

File hashes

Hashes for spot_planner-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3e201d636fa9aadbe242bb54d36fe1673324cfd9f6401421a9b92492496c0a6f
MD5 b3be5123b82f222c3f3b73ce8be15a95
BLAKE2b-256 fede21ebf7186a03d14ac0c4c452eca13558ace345510fc12c954e54059ccde6

See more details on using hashes here.

File details

Details for the file spot_planner-0.1.0-cp314-cp314-manylinux_2_34_x86_64.whl.

File metadata

  • Download URL: spot_planner-0.1.0-cp314-cp314-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 283.8 kB
  • Tags: CPython 3.14, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for spot_planner-0.1.0-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 41a13d16e47d00137086ea1161b707f7eac052300305d59836b148712f84e544
MD5 a0ee8736cda20898fae5503ff9ea6f64
BLAKE2b-256 979b866179a9ce32ecbc6f7843265f0a51caebacaa80eb6573cd4e025ba65a9d

See more details on using hashes here.

File details

Details for the file spot_planner-0.1.0-cp314-cp314-manylinux_2_34_aarch64.whl.

File metadata

  • Download URL: spot_planner-0.1.0-cp314-cp314-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 274.3 kB
  • Tags: CPython 3.14, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for spot_planner-0.1.0-cp314-cp314-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 6b01b2cb025e48a988204692d6b7bf7ed51a82627627bac85f39b732a41f7429
MD5 869a9c42bbf8947413527668d8695d0f
BLAKE2b-256 11861958ebaa980d5cbd00dc5ef30aa2639445f47b29f84316f4800788533d89

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.1.0-cp313-cp313-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 284.0 kB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for spot_planner-0.1.0-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f82fd8aef0f60e14abf7cd0bc81392e9d92a07cc58bf7490553b1f5b7aab172c
MD5 2496d469add92b0a7187237fa4212554
BLAKE2b-256 98d3e544e6ef6cedace4dcfb1f3ad88805a6020faa23d46f87c2ca8a2070a6c0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.1.0-cp313-cp313-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 274.7 kB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for spot_planner-0.1.0-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 cbca026f53fbeb60808854495efb3a725b0593116827ae04b3bd87beeea34ce3
MD5 eb97338b37154e601059e036f70f926c
BLAKE2b-256 7b53c74345c5092048c6a1d23b02994a46886193105af6c5c68a4f997cff228a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 284.1 kB
  • Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for spot_planner-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 1780af9fcc61c3d71440bc6e10c8c5a58d6dbfde38b9fea62ab0d8d5dd9750e0
MD5 654867597dd2373d686e3232608de084
BLAKE2b-256 efa6527881cc0eec4753db10777f7aec0c4664658c8ee2b5b1e0e9840a82c988

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.1.0-cp312-cp312-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 274.9 kB
  • Tags: CPython 3.12, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for spot_planner-0.1.0-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 4fa8c987a3e50a1213442a4fa56f4bdb547c60f417673904fb0d99201163aceb
MD5 5b689660effa9af8115e13442eb07247
BLAKE2b-256 729cf0762d9d445828eae71dbc4ee28edbdf0d8ef1d4cf9c75fa655762f7bdd8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 287.1 kB
  • Tags: CPython 3.11, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for spot_planner-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 2269f006a5f4e0ee228e93ff36d9caf342798f923379367055344c785504cdae
MD5 f414805d578731dedff0e9d961328327
BLAKE2b-256 3083a42274066816172ec512d513853e955a550f8d150cef8bc43b07ae17a33d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.1.0-cp311-cp311-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 278.0 kB
  • Tags: CPython 3.11, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for spot_planner-0.1.0-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 3433ea12416db93a8262fa05a27fca50cabc9c233799ee4870aaeb9b3e347e40
MD5 0c9f311025b34824e4044266678bdc3b
BLAKE2b-256 2ed3d5484733e02bb75b3fdfdf6e7202217a8aac5313a16cbda16cee37a3e8b7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 287.1 kB
  • Tags: CPython 3.10, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for spot_planner-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 c69cb48be416dcbfc33c27e4b80ded1375b2dfa3d54f77576e7b3ccf88cb3d38
MD5 8173a5244dae40478e2b1793dc632759
BLAKE2b-256 c7926f571531562a4ec5e7821c5852de91f8c91dda582f3016403db444441d97

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.1.0-cp310-cp310-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 277.8 kB
  • Tags: CPython 3.10, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for spot_planner-0.1.0-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 bb34489abf2179c558455aabd3d250f246246fabb477f83531508a375cc83a8d
MD5 665988839ce7317f36be81bad7a34942
BLAKE2b-256 7cf01c6848e5e8744045917eacd8fc96024e3aa4d0b9bf76071c5e514d8cf68d

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