Skip to main content

Production-grade PySpark auditing, optimization, and governance framework — static + dynamic analysis with local AI assistance

Project description

SparkGuardian logo

SparkGuardian

Production-grade PySpark auditing, optimization, and governance framework

PyPI version Downloads Rules MIT License

Tech stack

Python 3.11+ Apache Spark / PySpark libcst Typer CLI Rich terminal UI Ollama local AI SARIF v2.1.0 GitHub Actions GitHub Code Scanning GitLab CI Jenkins Rust (planned)


SparkGuardian detects PySpark anti-patterns, analyzes execution plans, generates prioritized remediation plans, and integrates into CI/CD pipelines. All 100% offline, no cloud APIs, no source code exfiltration

Table of Contents


Features

Feature Description
Static AST analysis libcst, never executes your code — 21 rules
Execution-plan analysis shuffles, CartesianProduct, AQE from df.explain()
Safe auto-refactor backup + dry-run preview
Local AI (Ollama) explanations, remediation, offline RAG
Cloud cost estimator $ waste on EMR / Databricks / GCP / Azure
Score + history 0–100 score, regression detection
Reports terminal, JSON, Markdown, HTML, SARIF v2.1.0
CI/CD exit codes 0/1/2 — GitHub Actions, GitLab, Jenkins
Licensing trial tokens, offline activation, Stripe billing

Installation

pip install sparkguardian
pip install "sparkguardian[ai]"    # + local Ollama

Python 3.11+.

Quick Start

sparkguardian activate             # paste SG-… token (7-day free trial)
sparkguardian analyze app.py       # --json --html --md --sarif
sparkguardian fix app.py --dry-run
sparkguardian cost app.py --cloud databricks
sparkguardian explain-plan plan.txt
sparkguardian remediation app.py   # AI (needs Ollama)
sparkguardian license              # status

Rules

21 rules — static AST (16) + execution-plan (5). List them:

sparkguardian list-rules

Ignore System

Suppress inline or by block, with audit trail:

df.collect()                       # cy:ignore CY001
# cy:ignore-start CY008
...
# cy:ignore-end CY008

Configuration

.sparkguardian.toml — enable/disable rules, override severity, ignore paths, CI thresholds.

Local AI Setup

Optional, 100% local via Ollama:

pip install "sparkguardian[ai]"
ollama pull llama3.1
sparkguardian ai-status

Cloud Cost Estimator

Turns anti-patterns into $ waste per cloud:

sparkguardian cost app.py --cloud databricks
# 💸 Estimated waste: $2,407/month

Audit History

Track score over time, flag regressions:

sparkguardian analyze app.py --history
sparkguardian history app.py

SARIF Output

GitHub Code Scanning ready:

sparkguardian analyze src/ --sarif results.sarif

CI/CD Integration

- run: pip install sparkguardian
- run: sparkguardian analyze src/ --sarif results.sarif

Exit 0 clean · 1 critical · 2 warnings. GitLab / Jenkins samples in ci/.

Licensing & Web Portal

application/ — FastAPI landing page + license portal + Stripe billing. Live: https://sparkguardian-portal.fly.dev

  • 7-day free-trial tokens (name + email → signed SG-…)
  • CLI activates online once, caches locally, checks expiry offline
  • Types: trial / monthly / lifetime / enterprise
  • Stripe Checkout ($10/mo Pro) + webhook auto-issues Pro
  • Admin dashboard: list / revoke / stats
cd application && ./run.sh          # http://localhost:8000  (/admin, /docs)

Deployment

Full app on any container host:

  • Fly.iocd application && fly deploy (fly.toml included)
  • Render — Blueprint via render.yaml

See application/README.md.

Architecture

sparkguardian/   parser · rules · rewriter · ai · cost · scoring · history · reporting · licensing · cli
application/     backend (FastAPI)  ·  frontend (static portal)

Development

pip install -e ".[dev]"
pytest                 # 375 tests
ruff check . && mypy sparkguardian

License

MIT — see LICENSE.

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

sparkguardian-0.1.2.tar.gz (53.4 kB view details)

Uploaded Source

Built Distribution

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

sparkguardian-0.1.2-py3-none-any.whl (68.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sparkguardian-0.1.2.tar.gz
  • Upload date:
  • Size: 53.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for sparkguardian-0.1.2.tar.gz
Algorithm Hash digest
SHA256 3551b7548ae985d93783f5edef63e1233aedd35d4509b63eec125f1a1c1a19da
MD5 5031cb1e99244bca2a549427a47f37b9
BLAKE2b-256 9e8931ebad8fc1c05306f3ed234594435ac76a0aa194f53dd2047f9a5f16d4a4

See more details on using hashes here.

File details

Details for the file sparkguardian-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: sparkguardian-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 68.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for sparkguardian-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 93caa1d7d6df8908743625ff59ca63965a8df7212d33e0ab501be206c8692098
MD5 5203889bf73e9989dad7d8589736a633
BLAKE2b-256 c790cc9c36e2844fc1a039344abfb740f25b674f28570a357b7e1272d23725ce

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