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 analyzelow_price_threshold(Decimal): Maximum price for valid periodsmin_selections(int): Number of periods to findmin_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.
Metadata
Release files for spot-planner 0.4.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| spot_planner-0.4.2.tar.gz | 1.9 MB | Details |
Built distributions (wheels)
Total release size: 4.6 MB
Release files / spot_planner-0.4.2.tar.gz
| Download URL | spot_planner-0.4.2.tar.gz |
|---|---|
| Size | 1.9 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
caef95bdd142fe07821853921a0c90b8b7017efe2feed1e8517ca53dbd7ebf08
|
|
BLAKE2b-256 checksum How to use checksums |
e3624487211b7d6e5b2c6fca00e6034b6a3e6175607df4d1be305bb3b8b3d2f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","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}
|
Release files / spot_planner-0.4.2-cp314-cp314-manylinux_2_34_x86_64.whl
| Download URL | spot_planner-0.4.2-cp314-cp314-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 275.7 kB |
| Tags | CPython 3.14 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
c2fe801d859c8bb8b6bfb7f41c2d15f4136487f819343c36a40836486adc6c31
|
|
BLAKE2b-256 checksum How to use checksums |
d82504529a367682ae23ee522fb987b2c1c6ae4978c658849309dca2bba9afda
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","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}
|
Release files / spot_planner-0.4.2-cp314-cp314-manylinux_2_34_aarch64.whl
| Download URL | spot_planner-0.4.2-cp314-cp314-manylinux_2_34_aarch64.whl |
|---|---|
| Size | 267.3 kB |
| Tags | CPython 3.14 Linux glibc 2.34+ ARM64 |
|
SHA-256 checksum How to use checksums |
ee1872420930f029232e30f865835d45fd215caa52de60f9c87800ace0e3c2aa
|
|
BLAKE2b-256 checksum How to use checksums |
8114a56bc90059e9e608cbbe2ebc57fb4028b3f84a8bbfce6aefd8644f745381
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","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}
|
Release files / spot_planner-0.4.2-cp313-cp313-manylinux_2_34_x86_64.whl
| Download URL | spot_planner-0.4.2-cp313-cp313-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 276.0 kB |
| Tags | CPython 3.13 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
311438b38d16c4c9548bcc9853e2ea06ab6c333caf91f22c1d5a1e692e33ffa9
|
|
BLAKE2b-256 checksum How to use checksums |
a04b6abbe1565c4f4f4a0c4f3b660773691a304861ba7835a8fca6bcbf3460ce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","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}
|
Release files / spot_planner-0.4.2-cp313-cp313-manylinux_2_34_aarch64.whl
| Download URL | spot_planner-0.4.2-cp313-cp313-manylinux_2_34_aarch64.whl |
|---|---|
| Size | 267.4 kB |
| Tags | CPython 3.13 Linux glibc 2.34+ ARM64 |
|
SHA-256 checksum How to use checksums |
d4972f8ec399ec1b47f9ed408824c9f6eeae68cd867294feadfee8714fe17880
|
|
BLAKE2b-256 checksum How to use checksums |
d04e081f88a48ccd8f11298e2e294fe92595ec1b2fce7f1c13b4567f2c663066
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","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}
|
Release files / spot_planner-0.4.2-cp312-cp312-manylinux_2_34_x86_64.whl
| Download URL | spot_planner-0.4.2-cp312-cp312-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 276.2 kB |
| Tags | CPython 3.12 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
8374b833c7be3be0feb42dc9311baa14558407e310b34fd0f15b408a012d09a8
|
|
BLAKE2b-256 checksum How to use checksums |
ab7fe6f368fb250b18b454c88921c7d901453185643577359f2a629bde8c7056
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","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}
|
Release files / spot_planner-0.4.2-cp312-cp312-manylinux_2_34_aarch64.whl
| Download URL | spot_planner-0.4.2-cp312-cp312-manylinux_2_34_aarch64.whl |
|---|---|
| Size | 267.5 kB |
| Tags | CPython 3.12 Linux glibc 2.34+ ARM64 |
|
SHA-256 checksum How to use checksums |
5b0bd85c94d7165357293934b4e67da918706d09e223b34800b1d828df714e4c
|
|
BLAKE2b-256 checksum How to use checksums |
48cc7c23054258a530b2f4a5e4358b56b45f682366e4f9dc737e23fcf8ce2371
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","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}
|
Release files / spot_planner-0.4.2-cp311-cp311-manylinux_2_34_x86_64.whl
| Download URL | spot_planner-0.4.2-cp311-cp311-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 277.9 kB |
| Tags | CPython 3.11 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
db4e564b6f78fb8b5af7fb8bdf387d43d44546f1f036051942cf2fbfa0c6cbaa
|
|
BLAKE2b-256 checksum How to use checksums |
264c2c183d5d012a5d6011831a39eb6c8f7a35779a4317d0d95e84431d132020
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","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}
|
Release files / spot_planner-0.4.2-cp311-cp311-manylinux_2_34_aarch64.whl
| Download URL | spot_planner-0.4.2-cp311-cp311-manylinux_2_34_aarch64.whl |
|---|---|
| Size | 269.3 kB |
| Tags | CPython 3.11 Linux glibc 2.34+ ARM64 |
|
SHA-256 checksum How to use checksums |
02172b9eb8f3ee09e7b52155144621e7413b512d9babae99fc8a996d2740b7f1
|
|
BLAKE2b-256 checksum How to use checksums |
51e927ecc8f57499f89a70d1ded81a87d902bec8bd56baca22c2e75d31ee51d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","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}
|
Release files / spot_planner-0.4.2-cp310-cp310-manylinux_2_34_x86_64.whl
| Download URL | spot_planner-0.4.2-cp310-cp310-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 278.0 kB |
| Tags | CPython 3.10 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
54beb34b89afece0d0d8b5065287a1a43c17cecda79343cd289d23daeaea6221
|
|
BLAKE2b-256 checksum How to use checksums |
7f206acf224bb23ee38d50e05a749b1b8083682fefff3ed507263c5d036aadd7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","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}
|
Release files / spot_planner-0.4.2-cp310-cp310-manylinux_2_34_aarch64.whl
| Download URL | spot_planner-0.4.2-cp310-cp310-manylinux_2_34_aarch64.whl |
|---|---|
| Size | 269.4 kB |
| Tags | CPython 3.10 Linux glibc 2.34+ ARM64 |
|
SHA-256 checksum How to use checksums |
9b4ac35584a1b1eec61ab939cf4456b564cada238659e1f0c7a5050bcf73318b
|
|
BLAKE2b-256 checksum How to use checksums |
cd01406ea964a9cf8164c9144d48448a0b8c8245fca974035f1d812de5d19544
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","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}
|