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.11.tar.gz (1.7 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.11-cp314-cp314-manylinux_2_34_x86_64.whl (286.6 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

spot_planner-0.3.11-cp314-cp314-manylinux_2_34_aarch64.whl (277.5 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ ARM64

spot_planner-0.3.11-cp313-cp313-manylinux_2_34_x86_64.whl (287.1 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

spot_planner-0.3.11-cp313-cp313-manylinux_2_34_aarch64.whl (278.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

spot_planner-0.3.11-cp312-cp312-manylinux_2_34_x86_64.whl (287.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

spot_planner-0.3.11-cp312-cp312-manylinux_2_34_aarch64.whl (278.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

spot_planner-0.3.11-cp311-cp311-manylinux_2_34_x86_64.whl (289.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

spot_planner-0.3.11-cp311-cp311-manylinux_2_34_aarch64.whl (280.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

spot_planner-0.3.11-cp310-cp310-manylinux_2_34_x86_64.whl (289.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

spot_planner-0.3.11-cp310-cp310-manylinux_2_34_aarch64.whl (280.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

File details

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

File metadata

  • Download URL: spot_planner-0.3.11.tar.gz
  • Upload date:
  • Size: 1.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.5 {"installer":{"name":"uv","version":"0.10.5","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.11.tar.gz
Algorithm Hash digest
SHA256 95935b1f7e068d218d6c89f7ae42aba864bfc10753f6b9836c9e98d988f9c12f
MD5 68db3947a2d204581a5aad31aac785c5
BLAKE2b-256 97902bc5386b31dc1ea0a733aa3df2a4783e7b57af82fdfcbbbcb6aac49745a3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.11-cp314-cp314-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 286.6 kB
  • Tags: CPython 3.14, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.5 {"installer":{"name":"uv","version":"0.10.5","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.11-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 3358db4515a98ddfd8585d1699a89181510b046ce59e6de5acf8f8bd28f558c6
MD5 d72393442f06bc02cfbe2f019e4ef0e6
BLAKE2b-256 b0eaaa056a5fb89fba3cde22d3164271577da09b7280ec662e3b0445f830b36b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.11-cp314-cp314-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 277.5 kB
  • Tags: CPython 3.14, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.5 {"installer":{"name":"uv","version":"0.10.5","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.11-cp314-cp314-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 c9c199328d83df0ea12ddbfdeecca4b259756e40da6737bce4e9b611232a036c
MD5 892648117ca3e02c63f55aca4acc0902
BLAKE2b-256 4a506fad7c5427acf253812e0f8b8ad0c712e72c5e5ada35210a0d089db55419

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.11-cp313-cp313-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 287.1 kB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.5 {"installer":{"name":"uv","version":"0.10.5","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.11-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 7f7159d2d0e3c87912dfbce34eb6a0adf756ec97358a591bdc569c72edc3c354
MD5 01dfa44a75fde51f890353485db9d36a
BLAKE2b-256 e8acd5ed85e73ea3651b169777f91a0f019f4378011c7f12012e207dc6742f70

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.11-cp313-cp313-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 278.0 kB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.5 {"installer":{"name":"uv","version":"0.10.5","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.11-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 455ccd6e0cb9905fc46120c5ddc1b398490862f2a329535a9214dc116ae6063a
MD5 9f0e65cc709e8cb5e98845fbfefd17b2
BLAKE2b-256 5b39908503227c40b28de5d5bd4b89678e3a250fb4c4a031c06907ed1e8343f6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.11-cp312-cp312-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 287.5 kB
  • Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.5 {"installer":{"name":"uv","version":"0.10.5","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.11-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 826f9a9e0a32c7dd2875988539ffc2ecc0e3081e0c7c616817bb410d5e207fa6
MD5 b6ed85e8a6b72527dba4d26bcbda4321
BLAKE2b-256 5e73d9c58b30c30e300806f200191622ea2b5eb43bbc856c6b98337651613633

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.11-cp312-cp312-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 278.3 kB
  • Tags: CPython 3.12, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.5 {"installer":{"name":"uv","version":"0.10.5","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.11-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 84213ed7aaa21c3dbeb90712b808e94cc30bb56b426f207a1d8afe9d6a77b916
MD5 10242811487357a49a8d6d42b1b9f7bf
BLAKE2b-256 e6e50fe56fb220f792accbd7609ed2ba66ca59e18175173918113e0e45e20232

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.11-cp311-cp311-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 289.8 kB
  • Tags: CPython 3.11, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.5 {"installer":{"name":"uv","version":"0.10.5","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.11-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 9c7527f56d370e212d7c9aced544ba9859c19635e22d599682fe364e19c85f74
MD5 6c8fd7d52fc18d5e326f94526bd0b9d8
BLAKE2b-256 127aa4834f14c8b960357ed5cf219de90fa1a28c39fe62137cadfff2aa0c699e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.11-cp311-cp311-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 280.2 kB
  • Tags: CPython 3.11, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.5 {"installer":{"name":"uv","version":"0.10.5","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.11-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 3a2f4a27c9f1a8381d8846652e6a0231efbc5f041c7fc6711b5e53e13b72645f
MD5 e351c425342b77a077958f535bb56b68
BLAKE2b-256 6d821aac514436842db2150b091038037559ad45157cb900b800f0e096591ec4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.11-cp310-cp310-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 289.8 kB
  • Tags: CPython 3.10, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.5 {"installer":{"name":"uv","version":"0.10.5","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.11-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 6cfa7466480cd04c6b5c8950938406ea4040dee2a8bde904a1ace09837ae0c33
MD5 511ef334fbd89d998b30658aa9c00198
BLAKE2b-256 801efc4da68964527967688ce9b49819567b90168cc97ae028bdc519d0b41bea

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spot_planner-0.3.11-cp310-cp310-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 280.0 kB
  • Tags: CPython 3.10, manylinux: glibc 2.34+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.5 {"installer":{"name":"uv","version":"0.10.5","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.11-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 2f60e4ab70b40768a9269c5343878f7d70fcb2252be23df871b1624136bbc902
MD5 b2902369714bb3d22eaed15c9fd3396f
BLAKE2b-256 264a8bc2dd19c0655ed552e7742fbdbcccffdfad2a80f332e9f5609a4eaa2fe6

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