Skip to main content

Cloud cost prediction engine — framework-agnostic, strategy-based

Project description

billing-cost-prediction

Tests Python Coverage

Framework-agnostic cloud cost prediction engine. Strategy-based, zero dependencies.

Quick Start

from billing_cost_prediction import PredictionEngine, BillingRecord, BillingMonth, CloudProvider

engine = PredictionEngine()
records = [
    BillingRecord(
        resource_id="res-001",
        cloud_provider=CloudProvider.AZURE,
        billing_month=BillingMonth.from_string("2026-04"),
        cost=1234.56,
    ),
]
results = engine.predict(records, months=12)
for batch in results:
    for r in batch.results:
        print(f"{r.predict_month}: {r.predicted_cost:.2f} ({r.method}, confidence={r.confidence})")

Strategies

Strategy Best For Min History
moving_average Stable workloads 1 month
exponential_smoothing Noisy data, recent-weighted 2 months
linear_trend Consistent growth/decline 3 months
seasonal Annual recurring patterns 12 months
auto (default) Picks best based on data

Strategy guide with flowcharts

Docs

Roadmap

✅ Phase 1: Core Engine (done)

  • Type system (BillingRecord, PredictionResult, BillingMonth, enums)
  • 4 strategies: moving_average, exponential_smoothing, linear_trend, seasonal
  • Back-test based confidence scoring
  • Per-resource auto strategy selection
  • Extensible strategy protocol (Protocol, structural subtyping)
  • Unit + integration tests (95%+ coverage)
  • Architecture refactoring (O(n) iteration, sort-once, build_result helper)
  • Python 3.10+ support
  • Architecture docs with flowcharts (Mermaid)
  • Pre-commit hooks (ruff + mypy)

🔜 Phase 2: Production Readiness (next)

  • PyPI publish (pip install cost-prediction)
  • CI pipeline (GitHub Actions: pytest/ruff/mypy matrix)
  • Coverage reporting (sticky PR comment)
  • Integration guide (Django, SQL, CSV, custom strategy)

🔗 Django Integration (cross-repo)

Repo: softwareone-finops-backend

  • Remove backend/prediction/prediction_model/ directory
  • Remove backend/prediction/azure_views.py (dead code)
  • Add cost-prediction to pyproject.toml dependencies
  • Create backend/prediction/data_adapter.py (DB ↔ engine bridge)
  • Rewrite task__multi_cloud_bill_predict using engine + adapter
  • Change task from "delete-all + rebuild" to update_or_create upsert
  • Add unique_together constraint on prediction model
  • Remove unused model fields (billing_model, region, availability_zone, provider_metadata)
  • Unify actual-cost queries across Alibaba/Azure in Views
  • Integration tests for data_adapter, tasks, views

🔮 Phase 3: Algorithm Enhancements (done)

  • ExponentialSmoothingStrategy
  • CostAnomalyDetector (pre-filter anomalous months)
  • StrategyEnsemble (multi-strategy voting)
  • Prediction accuracy tracking (MAPE)
  • Day-based billing normalization (to_daily_rates / to_monthly_rates)

Development

# install in dev mode
pip install -e ".[dev]"

# run tests
pytest -v

# lint
ruff check .
mypy .

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

billing_cost_prediction-0.1.1.tar.gz (28.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

billing_cost_prediction-0.1.1-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file billing_cost_prediction-0.1.1.tar.gz.

File metadata

  • Download URL: billing_cost_prediction-0.1.1.tar.gz
  • Upload date:
  • Size: 28.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for billing_cost_prediction-0.1.1.tar.gz
Algorithm Hash digest
SHA256 bdb9f518459f56530ac9a4b2d671f6634264ab6336c38452951fb5237f8bbfb6
MD5 dc2aff0fe5ac3982b1df11effa34a5d2
BLAKE2b-256 aff5077fdb2ea5df0ff75dc6143e4b791c311b387badfb15ed7f4b61ca63fe13

See more details on using hashes here.

Provenance

The following attestation bundles were made for billing_cost_prediction-0.1.1.tar.gz:

Publisher: publish.yml on Visionary-Future/billing-cost-prediction

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file billing_cost_prediction-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for billing_cost_prediction-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 534e3d5ee42f9283df12afc0741336028118fd7566d8115afba27624366b1a61
MD5 721320ace2bf930f5208d2df6487f986
BLAKE2b-256 23bab479813fc9ce484c37cba5a419402be49b1d61cda17187823d91e07500db

See more details on using hashes here.

Provenance

The following attestation bundles were made for billing_cost_prediction-0.1.1-py3-none-any.whl:

Publisher: publish.yml on Visionary-Future/billing-cost-prediction

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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