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
price_data = [
    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(
    price_data=price_data,
    price_threshold=Decimal("35"),
    desired_count=2,
    min_period=1,
    max_gap=1,
    max_start_gap=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(
    price_data=hourly_prices,
    price_threshold=Decimal("0.05"),  # 5 cents per kWh
    desired_count=3,
    min_period=3,  # 3-hour minimum
    max_gap=2      # Allow 2-hour gaps between periods
)

Cloud Computing Cost Optimization

# Find most cost-effective periods for batch processing
optimal_windows = get_cheapest_periods(
    price_data=aws_spot_prices,
    price_threshold=Decimal("0.10"),  # $0.10 per hour
    desired_count=5,
    min_period=4,  # 4-hour processing windows
    max_gap=1      # Minimal gaps between windows
)

Resource Planning

# Plan maintenance windows during low-cost periods
maintenance_slots = get_cheapest_periods(
    price_data=resource_costs,
    price_threshold=budget_threshold,
    desired_count=2,
    min_period=8,  # 8-hour maintenance windows
    max_gap=0      # No gaps allowed
)

API Reference

get_cheapest_periods(price_data, price_threshold, desired_count, min_period=1, max_gap=0, max_start_gap=0)

Find the cheapest periods in a price sequence.

Parameters:

  • price_data (List[Decimal]): Sequence of prices to analyze
  • price_threshold (Decimal): Maximum price for valid periods
  • desired_count (int): Number of periods to find
  • min_period (int, optional): Minimum period length. Defaults to 1.
  • max_gap (int, optional): Maximum gap between periods. Defaults to 0.
  • max_start_gap (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.1.2.tar.gz (21.5 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.1.2-cp313-cp313-manylinux_2_34_x86_64.whl (256.5 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

spot_planner-0.1.2-cp313-cp313-manylinux_2_34_aarch64.whl (247.6 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

spot_planner-0.1.2-cp312-cp312-manylinux_2_34_x86_64.whl (256.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

spot_planner-0.1.2-cp312-cp312-manylinux_2_34_aarch64.whl (247.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

spot_planner-0.1.2-cp311-cp311-manylinux_2_34_x86_64.whl (256.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

spot_planner-0.1.2-cp311-cp311-manylinux_2_34_aarch64.whl (247.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

spot_planner-0.1.2-cp310-cp310-manylinux_2_34_x86_64.whl (256.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

spot_planner-0.1.2-cp310-cp310-manylinux_2_34_aarch64.whl (247.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

File details

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

File metadata

  • Download URL: spot_planner-0.1.2.tar.gz
  • Upload date:
  • Size: 21.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.22

File hashes

Hashes for spot_planner-0.1.2.tar.gz
Algorithm Hash digest
SHA256 b45033e327462397239e2798914948262aa8f092121edb474af594b2b38b7f1c
MD5 ac6d20c87aeaa7a37e1aa8baec2f71af
BLAKE2b-256 cb4a84bae8793652e99c6039c9a0f932d17cb0ce0f2be8caa7329584965b9284

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.1.2-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 7452ebba854fe762554b5fc06ef5c1156a45e5cb9f1d344369515e17588d119d
MD5 46f92ee949bce0c13bf7236aa34e08d7
BLAKE2b-256 8e4b7504bb9364f04d4e756a0d550398c22451cd43e91e7c18e58f2dc1272a06

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.1.2-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 3ea3c87ed8a7940af3dc7a20e8c56992be72153c118c75c76cbf9602ecb0074c
MD5 03420d280483aafccabf3e8e5748e661
BLAKE2b-256 041216a03969debb1634456de1f50d13ed0360b7c258019ecd22870872469be6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.1.2-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 3546674f6de0e1c62a2f3948098e22cb09cf81d6e0774b3f51efac4281af2991
MD5 fc4eefa1a485f8f93558c343180d53f1
BLAKE2b-256 f821a00aa3cb02b6834ad12fe59584f42d13071de410a92149841535e782ce11

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.1.2-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 ce03750307c68949a116d8079b84b2a1343fab88108b6ac30e56926225d3a3b8
MD5 7b66355abb8e37baa83d88a3ee6d64fb
BLAKE2b-256 c0866108ffa4757318650486a4cfeb4e284d0a4c40ec59ae75b7a1ae8fd93e5c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.1.2-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 fb8b43d78338604284ab94559cbff46f0ede1f97623683e2de55884e7aefc808
MD5 034d65006e2914ab219aa5e510f1ce28
BLAKE2b-256 2a66ac7bcd01faee877f75c5ae3218d2debf709761cc2e8a2b54a27c77294955

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.1.2-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 6797d0b01f825d9d832293f6dcd6f86ec264b881981c7e981ca55dc7443cf876
MD5 3b9ec7e3a6fe74d5d467447688edb501
BLAKE2b-256 b4af384dde90e103285647ab4534083d4db3a7583acc103a0a21de7e6be6afe6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.1.2-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f7af152462414fb23f3437bc5be070719f70220a3ec380b6ad0893aa10c0521f
MD5 1d341b323f57433037e1404882a361fb
BLAKE2b-256 5fe5f1b3bdd3fe53b4e4baae73331b47564810e7d4376aaf6dfde84e2a1f6271

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spot_planner-0.1.2-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 936116347489f4931c7c436d8249a774b17342d1a37442c74bb117eaecea6c53
MD5 8ee2afcaecf65bf2b3d10d5a67f0d8a5
BLAKE2b-256 d44d728995f412773ab933f9a19f96e0fae7bdc816e763d19edb738b344e1e0c

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