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.0.tar.gz (743.9 kB 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.0-cp313-cp313-manylinux_2_34_x86_64.whl (278.2 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

spot_planner-0.3.0-cp313-cp313-manylinux_2_34_aarch64.whl (267.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

spot_planner-0.3.0-cp312-cp312-manylinux_2_34_x86_64.whl (278.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

spot_planner-0.3.0-cp312-cp312-manylinux_2_34_aarch64.whl (268.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

spot_planner-0.3.0-cp311-cp311-manylinux_2_34_x86_64.whl (278.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

spot_planner-0.3.0-cp311-cp311-manylinux_2_34_aarch64.whl (269.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

spot_planner-0.3.0-cp310-cp310-manylinux_2_34_x86_64.whl (278.6 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

spot_planner-0.3.0-cp310-cp310-manylinux_2_34_aarch64.whl (269.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

File details

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

File metadata

  • Download URL: spot_planner-0.3.0.tar.gz
  • Upload date:
  • Size: 743.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.14 {"installer":{"name":"uv","version":"0.9.14","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.0.tar.gz
Algorithm Hash digest
SHA256 5af9f6871fc93beb2bfeec98be47bb3a0cb4e3e32fc0ce65e467e91685294385
MD5 15752b5496d9fc5499e05aeb5902c1c4
BLAKE2b-256 bef78b19f9001915d0c2f85e2fdf6bba7cfd45d8755a6706339997c572be3814

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.0-cp313-cp313-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 278.2 kB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.14 {"installer":{"name":"uv","version":"0.9.14","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.0-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 b03c119f4c9096c447b43f7b724b14b395781cb246224d70b6fd0ed9fe3894ae
MD5 69ce9e98a7788344da1f3145c70ee0a7
BLAKE2b-256 81ac642a60175c0c3a910a5d95522433ba2a0005f974f7836703a324eaa594ed

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.0-cp313-cp313-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 267.9 kB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.14 {"installer":{"name":"uv","version":"0.9.14","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.0-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 f62db0b2eb09d0a31d15decd5f8d9e10088a8283f7c8efa592aae10483d8a6a3
MD5 0247c29f721b7a90cfc729bdd6a7ed63
BLAKE2b-256 b7d0140696f5b1efd6d809146387ecf3b6a9fdf3cbea649177d38005b7c1861c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.0-cp312-cp312-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 278.5 kB
  • Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.14 {"installer":{"name":"uv","version":"0.9.14","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.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 2ae48dd27b498091fee7c9864408b7ea89bea05df38c8e5ee4e04ca9ba16b54e
MD5 8ce1c8d9faa32b0048614205b3996b32
BLAKE2b-256 35a4d4721b1980f4a1088019a428f657102cfbece6f5218e67ac154b9a53a8fa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.0-cp312-cp312-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 268.4 kB
  • Tags: CPython 3.12, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.14 {"installer":{"name":"uv","version":"0.9.14","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.0-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 5e0bb5c46fba19cb1fbcf2b3250332947150f1a188a2d7965b79f4f552589b5d
MD5 76ec9d8a3034d65994b281f0406bf832
BLAKE2b-256 d5b734a0c29b2faa862c2a4933f9536bd4e5e1fa9382f3c049f9deab33816143

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.0-cp311-cp311-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 278.6 kB
  • Tags: CPython 3.11, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.14 {"installer":{"name":"uv","version":"0.9.14","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.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a6a87e8453fe7b329f11ad9a5b1f311d9ed73ab4b9c432d2b5296e3b47c731a8
MD5 8b380146d33b1bfee813e173dd139b70
BLAKE2b-256 9d45d1cd0b210307b932a400243994c57b59d57b211084c8f42df693c71db54a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.0-cp311-cp311-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 269.2 kB
  • Tags: CPython 3.11, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.14 {"installer":{"name":"uv","version":"0.9.14","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.0-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 2fa99766707c0de06b654290f5586b785a2355a6823d5806da4c79835cff9cb1
MD5 d08e2ebb8f6bc3acb3c10f2a450be8d4
BLAKE2b-256 9b2d1de4fda358a4a904652e6e6b13f78fa7374ee9be944c56d11db0624baa81

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.0-cp310-cp310-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 278.6 kB
  • Tags: CPython 3.10, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.14 {"installer":{"name":"uv","version":"0.9.14","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.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 3ef52985c3e65296472bdd765877bc09522e1040679f43953a4c097fec552ead
MD5 73502b3c644ec5a831a36fd901a7ddc4
BLAKE2b-256 3312052c1eb1b377757a7af3da1f9c7ab91cb542fe2775c515b6281a70ce559e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.0-cp310-cp310-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 269.2 kB
  • Tags: CPython 3.10, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.14 {"installer":{"name":"uv","version":"0.9.14","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.0-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 db5feb6af589e3054b996f944eadd98813fe60869c6bdee07dad413f56249e11
MD5 dee17509ac5956415441a03a0dee1fd9
BLAKE2b-256 01fccc895ae81825f3a6063b010d42ddf9e54b2fed0c3f6d43ec3f9924410837

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