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.9.tar.gz (1.6 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.9-cp314-cp314-manylinux_2_34_x86_64.whl (286.0 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

spot_planner-0.3.9-cp314-cp314-manylinux_2_34_aarch64.whl (276.8 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ ARM64

spot_planner-0.3.9-cp313-cp313-manylinux_2_34_x86_64.whl (286.5 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

spot_planner-0.3.9-cp313-cp313-manylinux_2_34_aarch64.whl (277.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

spot_planner-0.3.9-cp312-cp312-manylinux_2_34_x86_64.whl (286.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

spot_planner-0.3.9-cp312-cp312-manylinux_2_34_aarch64.whl (277.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

spot_planner-0.3.9-cp311-cp311-manylinux_2_34_x86_64.whl (289.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

spot_planner-0.3.9-cp311-cp311-manylinux_2_34_aarch64.whl (279.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

spot_planner-0.3.9-cp310-cp310-manylinux_2_34_x86_64.whl (289.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

spot_planner-0.3.9-cp310-cp310-manylinux_2_34_aarch64.whl (279.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

File details

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

File metadata

  • Download URL: spot_planner-0.3.9.tar.gz
  • Upload date:
  • Size: 1.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","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.9.tar.gz
Algorithm Hash digest
SHA256 74ccf167dd91ad8892e76f24f5114fb00fc40a9c5d653b19b3c9f103e0e9cf74
MD5 aeed54fbfb1f250f84c5270622756b72
BLAKE2b-256 d31d1a697ccba0ce0345ff16d2934f9c362347fb47e8a6343fad295848476ee2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.9-cp314-cp314-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 286.0 kB
  • Tags: CPython 3.14, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","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.9-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 fe6b6533700ea52ceb89f8641866394804a41ab883deece2b9068ee298eabac0
MD5 0c1613a1135ece5dfa9917b6cf216a06
BLAKE2b-256 fe7c597b611d23936ee9733a5b9804728e7011609f5018b2957e20f18901c175

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.9-cp314-cp314-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 276.8 kB
  • Tags: CPython 3.14, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","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.9-cp314-cp314-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 3bd8a79c30b3eef57f82628bcc08f5e08c961873168d98503c96a38397b50d47
MD5 20e4bbc42e462a80ea42eb13d33cb644
BLAKE2b-256 69887e5a4a03e030c09471273baaabd6a8bc567e99ed262e8bb23596146272e7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.9-cp313-cp313-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 286.5 kB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","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.9-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a893c859eef860a2af90de0f7a1176ee478a424f755978484b77333e0c470590
MD5 18829e07a50b6f67ee8e71f94ffed02c
BLAKE2b-256 7fdee5276fc08dd85b9b6b7a161c641b78140444257468bc44ee9264862fe02c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.9-cp313-cp313-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 277.4 kB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","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.9-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 1274639129cbaa7a5c40956c0d8f3a3ffd423bf91062a7ad89aeb4f5b8477349
MD5 701bf87ac9bbbda7164e6a92952a7382
BLAKE2b-256 907c60536ac76d10c7453404535265cc774608da3b4447500aaa4854f3804697

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.9-cp312-cp312-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 286.8 kB
  • Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","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.9-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 7aabe4eecab8730a55311c91efa16c3ad93ddb30bfd54d7b06b3c3015708f033
MD5 9d96f19ca8f4d434cd39e1c7704c0529
BLAKE2b-256 e47b11edba188da4a8593411230559a76c9961e4eeac09b4ff33847c6460bad9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.9-cp312-cp312-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 277.6 kB
  • Tags: CPython 3.12, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","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.9-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 d49907dbdea5804e9bc348cc0fe48cb65f69270c8fb92e2693f3a005e5efef4a
MD5 4df3de71691629eed8738db5f9f19fa5
BLAKE2b-256 659a7dc0b70d9b29a29ce05fd2755c3f80cbf3ebe5fd3938f2a8d343bc6ec5f4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.9-cp311-cp311-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 289.2 kB
  • Tags: CPython 3.11, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","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.9-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 89f155f34041ec1723b6f5fa8a1e4614bcfbe2d1a4fecac0b2cef54614363700
MD5 811214fb64c8da2aa1b1071d0b2e053d
BLAKE2b-256 7f7ec7572d154f9a34b81e1948d266e8a9319bb7dc9f86e5f84e061f2884f12f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.9-cp311-cp311-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 279.9 kB
  • Tags: CPython 3.11, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","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.9-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 9ae74c6669cc0e4ed3ed5de7fcb7331b9aa0072667920129170a01b6f23b3e20
MD5 6c8cca47b6d0f44ccecd4511c2dbdbc2
BLAKE2b-256 f61c772a73693a1ecbe19611d322623f9d3e761f2faba9ee21da61c4bddb0813

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.9-cp310-cp310-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 289.1 kB
  • Tags: CPython 3.10, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","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.9-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 1a62802998bcfe105319dba1d6d318ccddf5c63d039d5403334c41f5162ec189
MD5 73379df2d0b2280f9cebe6e9d718a6f9
BLAKE2b-256 66e7f8f61c1d26cfe12c6371f9b58ac035bdedfd1e6b1f8fbaeb518062dc58ee

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.9-cp310-cp310-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 279.7 kB
  • Tags: CPython 3.10, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","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.9-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 d010d043ebf09c0339a7647c07c9d262af849cbc180c2ff5edca00e5e2e8db5f
MD5 795e0817bacdb5ef1c758d1f9bb382ea
BLAKE2b-256 b6e164b433bb0d64573876bcb6f3c1f66ed84c029cb470be98f47089868020d4

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