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.3.12.tar.gz (1.9 MB 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.3.12-cp314-cp314-manylinux_2_34_x86_64.whl (288.0 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

spot_planner-0.3.12-cp314-cp314-manylinux_2_34_aarch64.whl (278.9 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ ARM64

spot_planner-0.3.12-cp313-cp313-manylinux_2_34_x86_64.whl (288.5 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

spot_planner-0.3.12-cp313-cp313-manylinux_2_34_aarch64.whl (279.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

spot_planner-0.3.12-cp312-cp312-manylinux_2_34_x86_64.whl (288.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

spot_planner-0.3.12-cp312-cp312-manylinux_2_34_aarch64.whl (279.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

spot_planner-0.3.12-cp311-cp311-manylinux_2_34_x86_64.whl (290.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

spot_planner-0.3.12-cp311-cp311-manylinux_2_34_aarch64.whl (281.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

spot_planner-0.3.12-cp310-cp310-manylinux_2_34_x86_64.whl (291.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

spot_planner-0.3.12-cp310-cp310-manylinux_2_34_aarch64.whl (281.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

File details

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

File metadata

  • Download URL: spot_planner-0.3.12.tar.gz
  • Upload date:
  • Size: 1.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","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.3.12.tar.gz
Algorithm Hash digest
SHA256 a0b1be51ed70f351891b4061cedaeaf3dc0931b1972b2bc8e8e594a49bf062fc
MD5 2517da0f929874e313240a8adfc6cbac
BLAKE2b-256 bb06a901e3487b3c6e99c180993657967951fdb5380e1da987ca4d805c96587b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.12-cp314-cp314-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 288.0 kB
  • Tags: CPython 3.14, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","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.3.12-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f5dc7ef4f6ca5c2b11fe31a8a0b656872f0c0083fac1643ad5316e55580809b2
MD5 75792b3c6b0ccc4218bdaf29ea7e8522
BLAKE2b-256 d469b63c1ce65b466fe838abb8a5a1d3c740c2cde0828fa949e97fabfa63db16

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.12-cp314-cp314-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 278.9 kB
  • Tags: CPython 3.14, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","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.3.12-cp314-cp314-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 87544e22c78be1be50085bd94355e63d4b26a4e01faeb9039f408e4698da2616
MD5 2e8c8624914779b6795f28b0b7209050
BLAKE2b-256 29656294557bcba904ed86812990c70fdeb3d849bb5ab5ab808cd82f8ff27cc1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.12-cp313-cp313-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 288.5 kB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","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.3.12-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 aa8299aa5123123e630f606561d4788a8517db5f596a6201a0257844fe7dca15
MD5 f5191c044adfc4ceecd887dbf60e34a7
BLAKE2b-256 6eed62e462bf8b7463b7711d1f3484a58b0429fb1602887d5538de8e343004c1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.12-cp313-cp313-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 279.4 kB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","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.3.12-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 476024d12e59d7be90b63f710b2fc14fe892d07d186ebd3e3be84b024d56c650
MD5 37e0466da01cbddcafcc00c07818bb10
BLAKE2b-256 e5688643ade9af586c099f56d1b34f907355e4422902f167f4fb37e025548967

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.12-cp312-cp312-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 288.9 kB
  • Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","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.3.12-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 161574489807b4854a2187606c67ee721d792bebf99385b40b7b1a8427efb1df
MD5 cb679ba4d233e907dbd28c5a32a36b69
BLAKE2b-256 dd1cdc40cd7b3417e1c5e0776463381a6ce9df3cdbf606594e72f866cb81ace3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.12-cp312-cp312-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 279.7 kB
  • Tags: CPython 3.12, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","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.3.12-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 bd41b2233745ef4bbb03521f743c80cfb9111cb47003694b8b9ba076fbee9876
MD5 abdf114e4049263ef8099e828fdc419b
BLAKE2b-256 5debaa3475fe7def62d9455cec0deb827353a955a0ae4779fd7a887f6fb55faf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.12-cp311-cp311-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 290.9 kB
  • Tags: CPython 3.11, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","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.3.12-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 c8301e59389b160d125fff0753d4af4861a31c76e2e939b6b10b42a5fb3e2718
MD5 8b884c0f31eee45660993af45ddf54b5
BLAKE2b-256 beb5a22b08c5648ac58237d871df6c4ac7b46d3abe33f3cfd216a44043bc57ec

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.12-cp311-cp311-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 281.6 kB
  • Tags: CPython 3.11, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","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.3.12-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 6d8a4ee6817313f31e822b98f3d66c83e5b2334285f448575e4aa9004ef4cb22
MD5 3eea814586b4df56e001f0f07697c58a
BLAKE2b-256 8c8d3f46f9fcb636383aba169b86923520f111e48a7b8dd58509daf51b602ff3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.12-cp310-cp310-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 291.0 kB
  • Tags: CPython 3.10, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","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.3.12-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 47dc7357e667f996a9acf1131f37784adaecb9671ef7981101e52d96249159ff
MD5 b9d12bafce86f1e034fe13ea1b9a1f25
BLAKE2b-256 c3b6138c4958dcac5d77009508a380431a6d510bf065c61506fdd419d364dad2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.12-cp310-cp310-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 281.4 kB
  • Tags: CPython 3.10, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","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.3.12-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 35300c613acc2dbebc458bea6bc2e5c124bb637ed4ea42ea7468af8b6d1ac620
MD5 33762787842aa3e2a50d056a172c36c9
BLAKE2b-256 9292547dec80961b131cfd6a6d37d627254ebe45ccc5a3a66da8aff685581ead

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