pyspark-antipattern
A static analysis linter for PySpark — catch performance antipatterns before they reach your cluster.
Written in Rust, installable as a Python package, and designed to run in CI/CD pipelines. +60 rules across 8 categories covering driver actions, shuffle explosions, UDFs, loops, and more.
What it catches
Real antipatterns, caught at commit time:
| Code | Rule | Why it matters |
|---|---|---|
df.collect() |
D001 | Pulls all data to driver — OOM risk on large datasets |
for c in cols: df.withColumn(...) |
L003 | Each call adds a projection — plan explodes exponentially |
array_distinct(collect_list(x)) |
ARR001 | Use collect_set(x) — one step instead of two |
df.rdd.collect() |
PERF001 | Use .toPandas() — 10x faster with Arrow enabled |
df.join(other) |
S011 | No condition = Cartesian product |
@udf returning StringType |
U001 | Built-in string functions are orders of magnitude faster |
Why this exists
PySpark is easy to misuse. .collect() on a 10 GB DataFrame, .withColumn() called in a loop, UDFs where built-in functions exist — these patterns work fine locally and silently destroy performance at scale. This tool catches them early, at commit time, before they reach your cluster.
Installation
pip install pyspark-antipattern
Usage
Check a single file:
pyspark-antipattern check pipeline.py
Check an entire directory recursively:
pyspark-antipattern check src/
Use a custom config location:
pyspark-antipattern check src/ --config path/to/pyproject.toml
Exit codes
0— no errors (warnings are allowed)1— one or more error-level violations found
CLI output
Default output — violations only:
Each violation line includes a colored severity badge — [HIGH] in red, [MEDIUM] in yellow, [LOW] in green — immediately after the rule ID:
error[D001][HIGH]: Avoid using collect()
--> pipeline.py:42:10
Filter by your cluster's PySpark version to suppress rules for newer APIs:
pyspark-antipattern check src/ --pyspark-version=3.3 # suppress rules requiring 3.4+
Filter by severity directly from the CLI:
pyspark-antipattern check src/ --severity=high # only HIGH violations
pyspark-antipattern check src/ --severity=medium # MEDIUM and HIGH
With show_information = true — inline explanation for each rule:
With show_best_practice = true — best-practice guidance for each rule:
Rules
Full documentation is available at https://skanderboudawara.github.io/pyspark-antipattern/.
Rules are organized by category in the docs/rules/ folder. Each rule has its own markdown file with a full explanation, best-practice guidance, and a severity badge indicating its performance impact.
| Category | Folder | Focus |
|---|---|---|
| ARR — Array | docs/rules/arr/ |
Array function antipatterns |
| D — Driver | docs/rules/driver/ |
Actions that pull data to the driver node |
| F — Format | docs/rules/format/ |
Code style and DataFrame API misuse |
| L — Looping | docs/rules/looping/ |
DataFrame operations inside loops |
| P — Pandas | docs/rules/pandas/ |
Pandas interop pitfalls |
| PERF — Performance | docs/rules/performance/ |
Runtime performance antipatterns |
| S — Shuffle | docs/rules/shuffle/ |
Joins, partitioning, and data movement |
| U — UDF | docs/rules/udf/ |
User-defined functions and their alternatives |
Each rule carries a severity reflecting its performance impact:
| Severity | Meaning |
|---|---|
| 🔴 HIGH | Major performance impact — OOM risk, full scans, shuffle explosion |
| 🟡 MEDIUM | Moderate performance impact — avoidable overhead at scale |
| 🟢 LOW | Minor impact — style, API correctness, small inefficiencies |
Configuration
Add a [tool.pyspark-antipattern] section to your project's pyproject.toml:
[tool.pyspark-antipattern]
# Show only these rules — everything else is silenced (default: all active)
# select = ["D001", "S"]
# Cluster PySpark version — silences rules requiring a newer version (default: all)
# pyspark_version = "3.3" # suppress rules that require PySpark 3.4+
# Downgrade these rules from error to warning (exit code stays 0)
warn = ["F008", "F011"]
# Completely silence these rules — no output, no exit code impact
# Accepts exact rule IDs or single-letter group prefixes
ignore = ["S004"] # silence one rule
# ignore = ["F"] # silence all F rules
# ignore = ["S", "L", "D001"] # silence all S and L rules
# Only report violations at or above this performance-impact level (default: all)
# severity = "medium" # show only MEDIUM and HIGH violations
# severity = "high" # show only HIGH violations
# Show inline explanation for each rule that fired (default: false)
show_information = false
# Show best-practice guidance for each rule that fired (default: false)
show_best_practice = false
# PERF003: fire when more than N shuffle ops occur without a checkpoint (default: 9)
max_shuffle_operations = 9
# S004: flag when the weighted count of .distinct() calls exceeds this (default: 5)
distinct_threshold = 5
# S008: flag when the weighted count of explode() calls exceeds this (default: 3)
explode_threshold = 3
# L001/L002/L003: flag for-loops where range(N) > threshold;
# while-loops always assume 99 iterations (default: 10)
loop_threshold = 10
# Directories to skip during recursive scanning (default: common build/venv dirs)
# exclude_dirs = ["my_generated_code", "vendor"]
Suppressing a specific line
Add a # noqa: pap: RULE_ID comment to suppress one or more rules on that line:
result = df.collect() # noqa: pap: D001
bad_join = df.crossJoin(other) # noqa: pap: S010, S002
CI/CD integration
GitHub Actions
- name: Lint PySpark code
run: |
pip install pyspark-antipattern
pyspark-antipattern check src/
The job fails automatically if any error-level rule fires. Warnings are reported but do not block the pipeline.
Pre-commit hook
# .pre-commit-config.yaml
repos:
- repo: local
hooks:
- id: pyspark-antipattern
name: PySpark antipattern linter
entry: pyspark-antipattern check
language: system
types: [python]
pass_filenames: false
args: ["src/"]
A word on strictness
This linter will challenge code that your team may have written deliberately and knowingly. That is by design.
Each violation is not a verdict — it is a question: "Did you mean to do this, and do you understand the trade-off?" If the answer is yes, suppress the rule on that line or downgrade it to a warning in your config. If the answer is no, you just avoided a production issue.
The strictest setup is the default: every rule is a hard error. Relax only what you have a documented reason to relax.
Author
Skander Boudawara — skander.education@proton.me
Metadata
Release files for pyspark-antipattern 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| pyspark_antipattern-0.4.1-py3-none-win_amd64.whl | Python 3 | none | Windows x86-64 | Details for pyspark_antipattern-0.4.1-py3-none-win_amd64.whl |
| pyspark_antipattern-0.4.1-py3-none-manylinux_2_28_aarch64.whl | Python 3 | none | Linux glibc 2.28+ ARM64 | Details for pyspark_antipattern-0.4.1-py3-none-manylinux_2_28_aarch64.whl |
| pyspark_antipattern-0.4.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | Python 3 | none | Linux glibc 2.17+ x86-64 | Details for pyspark_antipattern-0.4.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
| pyspark_antipattern-0.4.1-py3-none-macosx_11_0_arm64.whl | Python 3 | none | macOS 11.0+ ARM64 | Details for pyspark_antipattern-0.4.1-py3-none-macosx_11_0_arm64.whl |
| pyspark_antipattern-0.4.1-py3-none-macosx_10_12_x86_64.whl | Python 3 | none | macOS 10.12+ x86-64 | Details for pyspark_antipattern-0.4.1-py3-none-macosx_10_12_x86_64.whl |
Total release size: 7.7 MB
Release files / pyspark_antipattern-0.4.1-py3-none-win_amd64.whl
| Download URL | pyspark_antipattern-0.4.1-py3-none-win_amd64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
52df2fb0b06af2550bb228ec2df251c6a0220be06dcbe5d6c83b8a82125255fb
|
|
BLAKE2b-256 checksum How to use checksums |
49226c2899abbfc7ec9ca9ec1d23eed3fc7867489dae6abf98b98d5a9105ec8a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","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 / pyspark_antipattern-0.4.1-py3-none-manylinux_2_28_aarch64.whl
| Download URL | pyspark_antipattern-0.4.1-py3-none-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | Linux glibc 2.28+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
6532d143755c61c19138fdf030618b10835d7d5c0f9b976ba2e579cf2f0c3ad7
|
|
BLAKE2b-256 checksum How to use checksums |
45f6ace42348d3dafb79abbf320fa163329ebbaaae2634f61b7035c57bf5c491
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","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 / pyspark_antipattern-0.4.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | pyspark_antipattern-0.4.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.6 MB |
| Tags | Linux glibc 2.17+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
f83d4f9d55d47450fd2ec2e1bc4b750a259a3db88afa212bb1041d56c26cc8fb
|
|
BLAKE2b-256 checksum How to use checksums |
6716bb49c46f76cc7bd1d4d8b1d6ef96d8c31c11b90137ab4b6219f4e1a61d14
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","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 / pyspark_antipattern-0.4.1-py3-none-macosx_11_0_arm64.whl
| Download URL | pyspark_antipattern-0.4.1-py3-none-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | Python 3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
2e278cdd89b0416df34adeda46dab93dd8b06e1f4d597afd1daa2acf8e9f7b92
|
|
BLAKE2b-256 checksum How to use checksums |
ead5bd1fa13ac5b71f834c5a53f89d6f0f1be6e9437ea3063e3be1753c4d782c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","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 / pyspark_antipattern-0.4.1-py3-none-macosx_10_12_x86_64.whl
| Download URL | pyspark_antipattern-0.4.1-py3-none-macosx_10_12_x86_64.whl |
|---|---|
| Size | 1.6 MB |
| Tags | Python 3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
846d08ce6bad0a5992b2be95eecfa28927a168c316e5aaac47726a9996b2f52c
|
|
BLAKE2b-256 checksum How to use checksums |
c179b72ae35eeb6018c0196290381a527277c93e9e916c222c25187187a9d5e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","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}
|
Security for pyspark-antipattern 0.4.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.