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

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

spot_planner-0.3.8-cp314-cp314-manylinux_2_34_aarch64.whl (276.3 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ ARM64

spot_planner-0.3.8-cp313-cp313-manylinux_2_34_x86_64.whl (285.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

spot_planner-0.3.8-cp313-cp313-manylinux_2_34_aarch64.whl (276.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

spot_planner-0.3.8-cp312-cp312-manylinux_2_34_x86_64.whl (286.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

spot_planner-0.3.8-cp312-cp312-manylinux_2_34_aarch64.whl (277.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

spot_planner-0.3.8-cp311-cp311-manylinux_2_34_x86_64.whl (288.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

spot_planner-0.3.8-cp311-cp311-manylinux_2_34_aarch64.whl (279.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

spot_planner-0.3.8-cp310-cp310-manylinux_2_34_x86_64.whl (288.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

spot_planner-0.3.8-cp310-cp310-manylinux_2_34_aarch64.whl (279.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

File details

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

File metadata

  • Download URL: spot_planner-0.3.8.tar.gz
  • Upload date:
  • Size: 1.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","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.8.tar.gz
Algorithm Hash digest
SHA256 08a46c386d80bc36575a8c0daee68570b82ca7cbe75ff7a38c0ef21b5bb302f1
MD5 1acee61266f12e30cbefafe8fdcf45b2
BLAKE2b-256 dfc8cb7bc5101b3d1a4998734a70b0590316af1cb9a2efe2f6420d578ab9fe89

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.8-cp314-cp314-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 285.4 kB
  • Tags: CPython 3.14, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","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.8-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 77a40addb5adce5119898fcf52f7b3473081823ea20908fc878172c73995cc8b
MD5 945c6a32891e3769131abcac1532aef3
BLAKE2b-256 94c1401098372f861d69d47b05939737cde095c539ee9842bd6c3816263056e2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.8-cp314-cp314-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 276.3 kB
  • Tags: CPython 3.14, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","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.8-cp314-cp314-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 26e14d2d3426fe8ebaea1e7ccc2744f979ee99ae6bd7bead2e9774b78e3cc663
MD5 daf72ca68f0ea38410cb6a24b81e5f01
BLAKE2b-256 2572bc1e784d5b994a9421d0e27a089ca71ed9b8841adcb61483398a50b079ef

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.8-cp313-cp313-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 285.9 kB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","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.8-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e0f916d7fef119b6c1bf7553340594672f58a10ec4e70ab275d52eb228f6503b
MD5 e2e276cfa414d54c1e32a8bd607c7d65
BLAKE2b-256 0fa0975542722b5a245016cc30767c46f5b220a706080d19d843fbb92124b378

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.8-cp313-cp313-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 276.8 kB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","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.8-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 a17116f86a25ae719b06bdbb69461c9352c3716955d6cbe29ff6628c7024e165
MD5 8e2ed1403ae6de3a5abf56132af3d7a5
BLAKE2b-256 846b78bfd77f8c9c71cf642c1f88792ab7ffb46b600678b9e2d78aa20deab865

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.8-cp312-cp312-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 286.3 kB
  • Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","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.8-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 09db63b3e6807d93b69bcc6cbd8253f62f00bcd8c4068b7edc503e2cd0b2c5d9
MD5 45b337e021a445258a1a2abf5c6a1105
BLAKE2b-256 7cf12ef46768cbb306cbbfc239179a42c028b6aa8abeb1af25ef8528fc7567a5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.8-cp312-cp312-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 277.2 kB
  • Tags: CPython 3.12, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","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.8-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 4e258bd77d14354dad083a9a79023b6a4f914129cf54eba5abfb8ab5580d7254
MD5 dc80d77cee77cf9e536d6246c961bf8c
BLAKE2b-256 0b7a8d1dd9b651607d6abca1e5f3bbf431e6022b682b566b161a543da44f7290

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.8-cp311-cp311-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 288.3 kB
  • Tags: CPython 3.11, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","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.8-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 556271546872274cbd5415066e95fdb7034decc3a373c32abbdd24b7abd4ee9e
MD5 fef9b6dcae70a04eacc2ffbd142550da
BLAKE2b-256 ddb13361f15974a0cfaad843c5e22fb6b901a7b3e3ad441983da000fed8ef8c9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.8-cp311-cp311-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 279.4 kB
  • Tags: CPython 3.11, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","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.8-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 d8381148097dc6aeb2f58df71d75d2e2166bd1c17154f5ff071bcb4de78a74b4
MD5 d9e585b869cf6260a7c59ae4ea5d4f3d
BLAKE2b-256 098d93ba268a8b5e4f5b65bced763d5ba2486601b1267cac6a2f503e0c876e22

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.8-cp310-cp310-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 288.4 kB
  • Tags: CPython 3.10, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","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.8-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 2e63d3e3bbb54bb213b27f019b74a1b4595a6c965843af2819af193824e2085c
MD5 86ac0d3f096f7918ec5224e73262a30e
BLAKE2b-256 83fe434a19c4aa040c27edd2cda376de68f93afa791c28b822deace49d1f680e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.8-cp310-cp310-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 279.3 kB
  • Tags: CPython 3.10, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","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.8-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 ed9814b97bf031e7b8bba7a19ba6d5b88897cd83c30a3b5500e33f0d49422c03
MD5 4c4a445a316c8fecab543f076f5b4abc
BLAKE2b-256 a438e609d91bd8b6c3ec6ca576d6ad00eabfea5f78d824e410004c717ef948d4

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