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.10.tar.gz (1.7 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.10-cp314-cp314-manylinux_2_34_x86_64.whl (286.3 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

spot_planner-0.3.10-cp314-cp314-manylinux_2_34_aarch64.whl (277.1 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ ARM64

spot_planner-0.3.10-cp313-cp313-manylinux_2_34_x86_64.whl (286.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

spot_planner-0.3.10-cp313-cp313-manylinux_2_34_aarch64.whl (277.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

spot_planner-0.3.10-cp312-cp312-manylinux_2_34_x86_64.whl (287.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

spot_planner-0.3.10-cp312-cp312-manylinux_2_34_aarch64.whl (278.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

spot_planner-0.3.10-cp311-cp311-manylinux_2_34_x86_64.whl (289.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

spot_planner-0.3.10-cp311-cp311-manylinux_2_34_aarch64.whl (280.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

spot_planner-0.3.10-cp310-cp310-manylinux_2_34_x86_64.whl (289.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

spot_planner-0.3.10-cp310-cp310-manylinux_2_34_aarch64.whl (280.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

File details

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

File metadata

  • Download URL: spot_planner-0.3.10.tar.gz
  • Upload date:
  • Size: 1.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.5 {"installer":{"name":"uv","version":"0.10.5","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.10.tar.gz
Algorithm Hash digest
SHA256 4bae3c2c068846e511e3914019c9f436d9b94b932f8728895defee111499641a
MD5 0b919d1999df998a1b91a4136478b791
BLAKE2b-256 59796c8146731e35d7d63f9237771c717cf001bd82f8d8ce0dba55b379a50635

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.10-cp314-cp314-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 286.3 kB
  • Tags: CPython 3.14, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.5 {"installer":{"name":"uv","version":"0.10.5","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.10-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 63d53da03e6d5e004897a2f67e2b91e27f1482429b219b800813616f0c03d21a
MD5 df8458019b5c9073c23a4198af2deab6
BLAKE2b-256 a0dad4bb19179203cc0ff564c488efc3e0883e9560ae9e98324f97d22ee9a323

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.10-cp314-cp314-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 277.1 kB
  • Tags: CPython 3.14, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.5 {"installer":{"name":"uv","version":"0.10.5","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.10-cp314-cp314-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 1c9a206b1d9015630238e7e72365a396898c6a427fe0f4844150e0591f47f98d
MD5 c47799e6aa631cfe42ce0d66487569e1
BLAKE2b-256 af47e1313ec08904c732717fab532dd91e1b9600e92857886c75c10f2592d1ea

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.10-cp313-cp313-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 286.8 kB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.5 {"installer":{"name":"uv","version":"0.10.5","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.10-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 c2dce1a85f361d40d0954ecec0a7a0b7536d4c6b455d6418583c6e045e2ebe13
MD5 40c41ea5b59d195b7afed31b201b6535
BLAKE2b-256 3fbfc62bb2de1ad845da415bf9bf407245bef7d9ffe61d7c72b6806987b82d28

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.10-cp313-cp313-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 277.7 kB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.5 {"installer":{"name":"uv","version":"0.10.5","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.10-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 27c93cfdcc17a9167ec4c61eff771152088d07fba6bc20192961d9f48397da38
MD5 a181228d59d49c5b533e6bb0177b45ea
BLAKE2b-256 afac4081e89808f61b73b7afc3b2efc17eb251e4baaeb39eb753c7d2ba2faf72

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.10-cp312-cp312-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 287.1 kB
  • Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.5 {"installer":{"name":"uv","version":"0.10.5","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.10-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 4d8d60ff43fc9c0eb7c7eac158bf29b79059dd6acf1d215a2171318a7c7779e9
MD5 8b43d7949389a0dcc45a8217c2bed48b
BLAKE2b-256 4bea7eac732fa3873c963ab19ff7efbd8bcb540498b14cf064596f5ac86e7204

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.10-cp312-cp312-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 278.0 kB
  • Tags: CPython 3.12, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.5 {"installer":{"name":"uv","version":"0.10.5","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.10-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 1c1cf84edfbf582be5c8d184029d2aacc7b5957a3dfe3f2ff029facb972275f4
MD5 8085351b0267e907c353a299825c7e8a
BLAKE2b-256 a3946c735d6dff1faaab59212521905b6375f629958a57968f607013d22a39a9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.10-cp311-cp311-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 289.5 kB
  • Tags: CPython 3.11, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.5 {"installer":{"name":"uv","version":"0.10.5","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.10-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 c743e47c2c8037ae5bb4ff4603021eacf1df8e899ad180199055f65bb20f91f3
MD5 1a01cd629102b0003fcd5cbd3d4c6453
BLAKE2b-256 fa84f2c9e12f3faa9e1b343e9490f412d8d6e44ff67d91562e6a90313ac9a90f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.10-cp311-cp311-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 280.2 kB
  • Tags: CPython 3.11, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.5 {"installer":{"name":"uv","version":"0.10.5","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.10-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 10ff6156b1a8ab94928e5774987ea8314d814f2230ef66c08a8192dc79d1fbb1
MD5 662e630e14beaa56e5074eed69b0ce5e
BLAKE2b-256 98e728809d9411657eceb1d6efc005b878f8b0c42537941e19b8d1ae5257302d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.10-cp310-cp310-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 289.4 kB
  • Tags: CPython 3.10, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.5 {"installer":{"name":"uv","version":"0.10.5","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.10-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 48b688f455b6f8ab167031ebe7cc0ddaa3ea0fe693ce1b939ed338cd7d7e1ff0
MD5 ec0450188db31727468ea01e99fdd9c0
BLAKE2b-256 561f197daa2e35a9f4a4808916a22b5b15059aa5896701f7a3a37a06f72b5ba8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.10-cp310-cp310-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 280.1 kB
  • Tags: CPython 3.10, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.5 {"installer":{"name":"uv","version":"0.10.5","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.10-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 d220463f49e691025e281e5e9ac12a7b6bfd893ffaf94681f6c80a0fbebacf50
MD5 006d5e28a0f509e0c274495de5edfc01
BLAKE2b-256 7d101f0cfa24c0a21245f4bf36971237cf9d24b69d412af628edc38573e3e1c8

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