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.13.tar.gz (1.9 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.13-cp314-cp314-manylinux_2_34_x86_64.whl (288.2 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

spot_planner-0.3.13-cp314-cp314-manylinux_2_34_aarch64.whl (279.1 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ ARM64

spot_planner-0.3.13-cp313-cp313-manylinux_2_34_x86_64.whl (288.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

spot_planner-0.3.13-cp313-cp313-manylinux_2_34_aarch64.whl (279.6 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

spot_planner-0.3.13-cp312-cp312-manylinux_2_34_x86_64.whl (289.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

spot_planner-0.3.13-cp312-cp312-manylinux_2_34_aarch64.whl (279.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

spot_planner-0.3.13-cp311-cp311-manylinux_2_34_x86_64.whl (291.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

spot_planner-0.3.13-cp311-cp311-manylinux_2_34_aarch64.whl (282.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

spot_planner-0.3.13-cp310-cp310-manylinux_2_34_x86_64.whl (291.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

spot_planner-0.3.13-cp310-cp310-manylinux_2_34_aarch64.whl (282.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

File details

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

File metadata

  • Download URL: spot_planner-0.3.13.tar.gz
  • Upload date:
  • Size: 1.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","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.13.tar.gz
Algorithm Hash digest
SHA256 3f343d04d4a29d9ad6605b079f22d83c5a9bbc7ee44a9d1dcdcb4e24a97b270e
MD5 8ea0bd85592f8b614492582160c2cb01
BLAKE2b-256 cdf1a0b42c4016f4a0ec2ae630aa056ac581e875f1583c49b33fa00482f9a176

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.13-cp314-cp314-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 288.2 kB
  • Tags: CPython 3.14, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","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.13-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 7f5b86dd03c67311fee49c7ef21ad997c4289c0fa3e91c0b31d30955ad78cfc8
MD5 f39e9eea6d52f06fb3dd5300eac6048d
BLAKE2b-256 4a26ddac073ec10e144d963de1eb74ec7cb4d9b022208c224a9b838090a7c566

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.13-cp314-cp314-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 279.1 kB
  • Tags: CPython 3.14, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","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.13-cp314-cp314-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 ba8e14de93e283609292aa475e3e29dca29e11eb86c2673837c95972ad49003b
MD5 77a8e53895cc097bc691f0ee409f9c71
BLAKE2b-256 1b597e6b3d693789fbc6dc3711c1b5e20f19b1bcb9fa9a0483f1b1783c28d411

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.13-cp313-cp313-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 288.7 kB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","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.13-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 24fca6b57a754178aeb7849bfe6baa757bf2221968a99dab78401ecaad35ac33
MD5 c5a3c6ad60831fe86afd4682657f7ba7
BLAKE2b-256 e9b2b8f63091a99b59b7904c2fdb6f688f86d4172ca51d054618a9e46d67084f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.13-cp313-cp313-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 279.6 kB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","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.13-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 2df137b96a767fae3352b062c0ac6e532146be488425876d658f08bedc28951d
MD5 e837cca401f0a85922189d859003914f
BLAKE2b-256 e8ee35157439b56eff83c738174c1765769e8e7db849d3112a669a07e3896589

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.13-cp312-cp312-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 289.0 kB
  • Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","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.13-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 d600ecc79c387fb12150e4ebc6b6686961197a52a17adce90e8196e5271bedfe
MD5 b3b36dcaddb6b64732b5f2bc967c2538
BLAKE2b-256 ad9105fe4ce454a41375bcf66ab93348f6f636bb639f0691962f7bd9d8879868

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.13-cp312-cp312-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 279.9 kB
  • Tags: CPython 3.12, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","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.13-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 92b2e1e9e28bd975d0bd5f6d45bf13f0e8534c039d4d9236f497018b5883b2ba
MD5 b73298f9f09c95026f3d78525d40741f
BLAKE2b-256 2eaf2d81963dd38c510dabf6b1e4ed7c3bfebd7c7ca890f32abc14460c50ddf7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.13-cp311-cp311-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 291.0 kB
  • Tags: CPython 3.11, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","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.13-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 af4ad653418d7e4afa2d6bd66bca62f9caea44d98e477bb55121494c3c915ae4
MD5 cbd4fc7a1e0426e4d87cb65a64f1704d
BLAKE2b-256 ce73b6f6b8871718262cb6a0eb1d163c79f3f7865853e8b3413c5c1e568a488f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.13-cp311-cp311-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 282.1 kB
  • Tags: CPython 3.11, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","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.13-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 7dbd4d327b05a631e24f0803ee26f81e2d0e5fa4521b86ace0eb151634d648c6
MD5 25f700ac9b81e9341a4e13a07045b8cc
BLAKE2b-256 edac8d50c7354dea285b2e1a9fb91d66f11e8d7449114c20e6d501fd00d50a65

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.13-cp310-cp310-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 291.1 kB
  • Tags: CPython 3.10, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","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.13-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 39a35ca8cf0fc9dbd41758ee6c0b61e0256d9ada178c381a7828867e65ee4ac4
MD5 96bc6e07ec6d5575b460ab3490a7bbd2
BLAKE2b-256 8ade5ab9bf45dd6fbdb26d43b69634a13accd1aef74684ea3cca258d9ef0c8b2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.13-cp310-cp310-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 282.0 kB
  • Tags: CPython 3.10, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","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.13-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 ac30f1e1f801dec51c03904e8367ee15301672d67c58022d6128422b73ca1552
MD5 9198bdafe0cb04c813dcc4eb23ea92a8
BLAKE2b-256 b0da64299d33fce3c3e322331b3b3a1908850b9b366ef27b0af9a021c21f009f

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