Skip to main content

A declarative PySpark framework for row- and aggregate-level data quality validation.

Project description

CI Pipeline codecov Docs PyPI version Python Versions License: Apache-2.0 PyPI Downloads

SparkDQ — Data Quality Validation for Apache Spark

SparkDQ is a lightweight data quality framework built specifically for PySpark. Define checks declaratively or in Python, run them directly inside your Spark pipelines, and catch data issues before they reach production.

No wrappers. No heavy dependencies. Just Python and Spark.

Quickstart Examples

Define checks as dictionaries that can be loaded from YAML/JSON files, stored in databases, or generated by APIs — perfect for CI/CD pipelines and data contracts.

from pyspark.sql import SparkSession

from sparkdq.engine import BatchDQEngine
from sparkdq.management import CheckSet

spark = SparkSession.builder.getOrCreate()

df = spark.createDataFrame(
    [
        {"id": 1, "name": "Alice"},
        {"id": 2, "name": None},
        {"id": 3, "name": "Bob"},
    ]
)

# Declarative configuration via dictionary
# Could be loaded from YAML, JSON, or any external system
check_definitions = [
    {"check-id": "my-null-check", "check": "null-check", "columns": ["name"]},
]
check_set = CheckSet()
check_set.add_checks_from_dicts(check_definitions)

result = BatchDQEngine(check_set).run_batch(df)
print(result.summary())
# Validation Summary (2024-01-01 00:00:00)
# Total records:   3
# Passed records:  2
# Failed records:  1
# Warnings:        0
# Pass rate:       67.00%

Prefer Python-native development? Define checks directly in Python for full type safety, IDE autocompletion, and compile-time validation:

from pyspark.sql import SparkSession

from sparkdq.checks import NullCheckConfig, RowCountMinCheckConfig
from sparkdq.core import Severity
from sparkdq.engine import BatchDQEngine
from sparkdq.management import CheckSet

spark = SparkSession.builder.getOrCreate()

df = spark.createDataFrame(
    [
        {"id": 1, "name": "Alice"},
        {"id": 2, "name": None},
        {"id": 3, "name": "Bob"},
    ]
)

check_set = (
    CheckSet()
    .add_check(
        NullCheckConfig(
            check_id="null-check",
            columns=["name"],
            severity=Severity.CRITICAL,
        )
    )
    .add_check(
        RowCountMinCheckConfig(
            check_id="min-row-count",
            min_count=1,
            severity=Severity.WARNING,
        )
    )
)

result = BatchDQEngine(check_set).run_batch(df)
print(result.summary())
# Validation Summary (2024-01-01 00:00:00)
# Total records:   3
# Passed records:  2
# Failed records:  1
# Warnings:        0
# Pass rate:       67.00%

SparkDQ ships with 30+ built-in checks across null validation, numeric ranges, string patterns, date boundaries, schema enforcement, uniqueness, and referential integrity.

🚀 See the official documentation to learn more.

Installation

For Local Development / Standalone Clusters

Install with PySpark included:

pip install sparkdq[spark]

For Databricks / Managed Platforms

Install without PySpark (runtime provided by platform):

pip install sparkdq

The framework supports Python 3.11+ and is fully tested with PySpark 3.5.x. SparkDQ will automatically check for PySpark availability on import and provide clear error messages if PySpark is missing in your environment.

Why SparkDQ?

  • Extensible by design: Add custom checks via a simple plugin system — no changes to the core required

  • Declarative or Pythonic: Load checks from YAML/JSON, or define them in Python with full type safety and IDE autocompletion

  • Severity-aware: Distinguish between hard failures (CRITICAL) and soft constraints (WARNING) — react differently to each

  • Row-level and aggregate: Validate individual records and entire datasets in a single pass

  • Minimal footprint: Only Pydantic required — PySpark is provided by your platform

Typical Use Cases

  • Data Ingestion: Validate schema, check for nulls, enforce value ranges, and detect format violations before bad data enters your platform

  • Lakehouse Quality: Assert completeness, uniqueness, and referential integrity before writing to Delta, Iceberg, or Hudi tables

  • ML & Analytics: Validate feature completeness, numeric boundaries, and row counts before model training or reporting

  • Pipeline Assertions: Enforce data contracts between pipeline stages — fail fast on critical violations, log warnings for soft constraints

Let’s Build Better Data Together

⭐️ Found this useful? Give it a star and help spread the word!

📣 Questions, feedback, or ideas? Open an issue or discussion — we’d love to hear from you.

🤝 Want to contribute? Check out CONTRIBUTING.md to get started.

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

sparkdq-0.11.2.tar.gz (3.1 MB view details)

Uploaded Source

Built Distribution

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

sparkdq-0.11.2-py3-none-any.whl (93.5 kB view details)

Uploaded Python 3

File details

Details for the file sparkdq-0.11.2.tar.gz.

File metadata

  • Download URL: sparkdq-0.11.2.tar.gz
  • Upload date:
  • Size: 3.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.17

File hashes

Hashes for sparkdq-0.11.2.tar.gz
Algorithm Hash digest
SHA256 5839939eb085a7f95fa9ea27a56dacc371a70b3adc133b97941c90f3828b9910
MD5 dd2cc89b5593cecd4acaa7de4bacc89a
BLAKE2b-256 a0b0483a08d14355c2fae963608ddc8ebe5c34571b47438e219002940c27defd

See more details on using hashes here.

File details

Details for the file sparkdq-0.11.2-py3-none-any.whl.

File metadata

  • Download URL: sparkdq-0.11.2-py3-none-any.whl
  • Upload date:
  • Size: 93.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.17

File hashes

Hashes for sparkdq-0.11.2-py3-none-any.whl
Algorithm Hash digest
SHA256 08d736ba3756db84ff14b2372081dc1def7765eed6864ed34018dcb1aedb4aaa
MD5 e1eef281f10e6322b3f489c3fb7fdf0e
BLAKE2b-256 207e98e13c5087f66c6afce38e104ed819ac9fbd8ee4a52780eac2a530f35a01

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