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.4.0.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.4.0-cp314-cp314-manylinux_2_34_x86_64.whl (279.4 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

spot_planner-0.4.0-cp314-cp314-manylinux_2_34_aarch64.whl (270.4 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ ARM64

spot_planner-0.4.0-cp313-cp313-manylinux_2_34_x86_64.whl (279.5 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

spot_planner-0.4.0-cp313-cp313-manylinux_2_34_aarch64.whl (270.5 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

spot_planner-0.4.0-cp312-cp312-manylinux_2_34_x86_64.whl (279.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

spot_planner-0.4.0-cp312-cp312-manylinux_2_34_aarch64.whl (270.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

spot_planner-0.4.0-cp311-cp311-manylinux_2_34_x86_64.whl (281.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

spot_planner-0.4.0-cp311-cp311-manylinux_2_34_aarch64.whl (272.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

spot_planner-0.4.0-cp310-cp310-manylinux_2_34_x86_64.whl (282.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

spot_planner-0.4.0-cp310-cp310-manylinux_2_34_aarch64.whl (273.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

File details

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

File metadata

  • Download URL: spot_planner-0.4.0.tar.gz
  • Upload date:
  • Size: 1.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","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.4.0.tar.gz
Algorithm Hash digest
SHA256 e7906831ee7918f354b9361bf33c6bb54bff2c8e83c3b519c8ac46f3537c8896
MD5 37887e0c3c78ea0fb8471ff65f31cae2
BLAKE2b-256 fbf26fafc6e013a63dd7f4d9b9bfe0910705aedf123e14b8c4c3a7fc1cea46c8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.4.0-cp314-cp314-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 279.4 kB
  • Tags: CPython 3.14, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","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.4.0-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 6e4b0a34c8c8b2fdfc2b5725f5709bf34e0dbaf1d3f2a47421bbe797686f1f9c
MD5 01e754d3a7d0e202bc4876c75ba9171c
BLAKE2b-256 1d33c4b188f2c534b84bd3cb68cf2787e1f9f84dc8db231f0debf21448a62f43

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.4.0-cp314-cp314-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 270.4 kB
  • Tags: CPython 3.14, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","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.4.0-cp314-cp314-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 8b6a54a38567511aa1548f22fcaed48c4cb39c921a8fc7fc26665e99b6141693
MD5 31fcbf29ffdeadb3b1b0fb4c63c34bd0
BLAKE2b-256 17d7474352f0dc283609b038396297d24ea9c1cb1eb10a85183ff6ab2e7b44c5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.4.0-cp313-cp313-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 279.5 kB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","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.4.0-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 0129b39c0109fbcc0c7ecf000330997e9fba2b6e262cb5214f2cefd42c20f391
MD5 089f0d540fda3940e831fb15b2699884
BLAKE2b-256 d5b66f90e8e2b80182d234a82649aa34995a2840e8e743757112a78251e3bd7e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.4.0-cp313-cp313-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 270.5 kB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","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.4.0-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 9ed33bcd58003b2b0c3d1d8d093554a0fc03cf7227eeb63ccf8b489efe7a0cfd
MD5 eb8cdb7945be5ee6efdcea810f15a908
BLAKE2b-256 1ee6f056d4a38f0bcefd4ff3c57b89755e1d96dd961b9f36d27e4fe2eb0c7e36

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.4.0-cp312-cp312-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 279.4 kB
  • Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","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.4.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 d6c04f603974d49ade82a37f996bea7f3214df75bc7ad4e022de01a94ed8831f
MD5 7da9fa5575aa2d9ccb34581c81c4d84a
BLAKE2b-256 656b41aefc24467da933346809feee88164229e45edaf9dd138d1fdc5b03be15

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.4.0-cp312-cp312-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 270.2 kB
  • Tags: CPython 3.12, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","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.4.0-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 ebd87cb34021cf2de10e172282bb734c20724703184b9d52481708d835b94f5d
MD5 00d977bda8daf80a8a72add75a98f334
BLAKE2b-256 783110e0372a97f4bdca1a5f0d9f3736e2cf8139acd6f9392a53e1142fa44f37

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.4.0-cp311-cp311-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 281.8 kB
  • Tags: CPython 3.11, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","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.4.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 69a5da6a58ab6c7d1dcd1cb8f3d741d4b718a31e67aa6512708bb7fc86145cf2
MD5 f352b98f655ba5d84e548291e51774cd
BLAKE2b-256 c3fc0ddde8c5e3c70afd222298bbf885192931e5e57be958812c213ca7965fe1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.4.0-cp311-cp311-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 272.8 kB
  • Tags: CPython 3.11, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","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.4.0-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 3e50fe37fb43b0804e294f95479ccb4ef35b38ee60ef56ce2a1f2abc94034493
MD5 9a41681d770c61a74d0957675fb73f11
BLAKE2b-256 5dbdd93a70e43e36afd4ab586d9655a2b88cebd3d34c4e2c6b0c6d24abe6e86f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.4.0-cp310-cp310-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 282.1 kB
  • Tags: CPython 3.10, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","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.4.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 ce21d0c9024d86be075e08ea52acceb63b4ebae358991cc8a768be072e2ebee2
MD5 038006b77086a9b18ae2414fe3ea7a18
BLAKE2b-256 db0d1c547e3e16f2927cd22a1d767dbeb66f454340134e3bebe18aab9405032a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.4.0-cp310-cp310-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 273.0 kB
  • Tags: CPython 3.10, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","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.4.0-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 bbf234f8f26945a4aa1ba2e1575db91fc9822a77ff746bf54191afcddf9a9527
MD5 bb36288e3fdfc1de09d112f0d47ff45c
BLAKE2b-256 f81a2566d719ba3b54467b3a6b2c9f955427e30ddfce0ce67eed28d28437aaa8

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