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.6.tar.gz (1.1 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.6-cp314-cp314-manylinux_2_34_x86_64.whl (284.1 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

spot_planner-0.3.6-cp314-cp314-manylinux_2_34_aarch64.whl (274.7 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ ARM64

spot_planner-0.3.6-cp313-cp313-manylinux_2_34_x86_64.whl (284.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

spot_planner-0.3.6-cp313-cp313-manylinux_2_34_aarch64.whl (275.1 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

spot_planner-0.3.6-cp312-cp312-manylinux_2_34_x86_64.whl (284.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

spot_planner-0.3.6-cp312-cp312-manylinux_2_34_aarch64.whl (275.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

spot_planner-0.3.6-cp311-cp311-manylinux_2_34_x86_64.whl (287.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

spot_planner-0.3.6-cp311-cp311-manylinux_2_34_aarch64.whl (278.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

spot_planner-0.3.6-cp310-cp310-manylinux_2_34_x86_64.whl (287.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

spot_planner-0.3.6-cp310-cp310-manylinux_2_34_aarch64.whl (278.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

File details

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

File metadata

  • Download URL: spot_planner-0.3.6.tar.gz
  • Upload date:
  • Size: 1.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","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.6.tar.gz
Algorithm Hash digest
SHA256 be53e6884fb5077f05675962ce333a638af9e95ab52d5a8b94e96fc828ea9d34
MD5 19d1bc0f66c772eef06736fc45cdf1ae
BLAKE2b-256 005b5935e0a511782e629dec05ba523cdf4ab80005176c9f18b2375500176abf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.6-cp314-cp314-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 284.1 kB
  • Tags: CPython 3.14, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","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.6-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 3236f3c94c3fe70c409102109219649a1a76f2eadd109f910f6cac7445228fa2
MD5 6c59d6d4e2d4b5ada630c73f1ca0df79
BLAKE2b-256 ce88e2c27e8cac43611fa68ba11d0cd65c8ffc6157a06662a82976f7dd07e7e0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.6-cp314-cp314-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 274.7 kB
  • Tags: CPython 3.14, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","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.6-cp314-cp314-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 d0c2608f65940136d2593387545b0a80639fad69d192b9d93e9d483888e895bf
MD5 08a4899e35393e782501ac55a965880b
BLAKE2b-256 70ee38b69de569870ef4a0fe4ab0a493934b5c338159d3bafa92daa16f05618b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.6-cp313-cp313-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 284.3 kB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","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.6-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 fa41d36aa0c491058e0bcc9516022b48c7ae6420e360f4a78068a11c8050d791
MD5 347f4d06b869caa5c3d53d2496901544
BLAKE2b-256 817a9a9959be04caf649d3f34fa28e96b6a3280e1d88fe601c18e11421e9e088

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.6-cp313-cp313-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 275.1 kB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","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.6-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 eb3b2009c5082586f1f96f50dd5de8a877a23fceb24ab2b55f946b56d5a78c0b
MD5 81a36074f2eeaff61030c528815fcd9c
BLAKE2b-256 57bfb9e55d6012d772c8adf1269c2b4124a979849d6d5af480e91b79ef6e13fd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.6-cp312-cp312-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 284.5 kB
  • Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","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.6-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 5a666b59deddd9415a33e8b563dea21a946dde0920ac3185324d0c886a29ca37
MD5 ef9eebedd13496e0b692de1572e798bd
BLAKE2b-256 65f0c370f505ac30dfe5584f916252526d0c7a065cb21918330c33862a53efc9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.6-cp312-cp312-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 275.3 kB
  • Tags: CPython 3.12, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","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.6-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 860f381808d60c36912402eb860155dfce357e6dcd9d329ab3c096a7314c735c
MD5 4f90bba2febda889faca3dcd122fdadf
BLAKE2b-256 f6dd0dc8c7961ff46116e84f7cc3fddb054944bf1ba153b2d70dab8c94c92587

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.6-cp311-cp311-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 287.5 kB
  • Tags: CPython 3.11, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","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.6-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 49be98f19124e9786c7a2ab87dce2ab12098cb3b7729ea98a9676995858a0f4c
MD5 d2d11d7ba53b51adb4ecec6e5bf36d8f
BLAKE2b-256 9d839b39df9b169d8e4569bd1e75f916c80580b335e4f227c56af1088f610170

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.6-cp311-cp311-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 278.4 kB
  • Tags: CPython 3.11, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","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.6-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 c32db6f0a120b156600f68e39d6f9d28a2008d04dc53a65af64be5655ba0358f
MD5 b5c80cb89ad6c5a0d17840c3462cc6f9
BLAKE2b-256 604250ce3813c3f0c3206fb132d510750036408f7d6e789138ec36cc9b102712

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.6-cp310-cp310-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 287.5 kB
  • Tags: CPython 3.10, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","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.6-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 d9c986f8d99b810cda931d42e0c65ea5be29209a0b870f797021bfcb63bf5102
MD5 246793ead5c0674c5bd146bc33931f26
BLAKE2b-256 456b389d700263350c74435161673eead5fd21e00e884d65cf9ff44d3ae85e18

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.6-cp310-cp310-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 278.2 kB
  • Tags: CPython 3.10, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","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.6-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 9004a1363b48cb0637426fddc6291985a48a1077f943c88fe6fe2f25bf6f41d1
MD5 82a4df486ca48a899742b00bec2c6bab
BLAKE2b-256 af400f199f273a2268b7993db1f982cae9ca4105baea6f1420c2e08cb4cb2bba

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