sparkdantic
A pydantic -> spark schema library
What it is and what it does
SparkDantic bridges Pydantic and PySpark by letting you define data models once as Pydantic classes and automatically generate PySpark schemas from them. It extends Pydantic's BaseModel with a SparkModel class that adds schema generation methods, and also provides standalone functions to convert existing Pydantic models. The package handles type mapping from Python/Pydantic types to Spark native types, supports Enums (mixed with int or str), and allows field-level type coercion via a SparkField function. PySpark is optional—you can generate JSON-formatted Spark schemas without it, but StructType generation requires PySpark 3.3.0 or higher (up to but not including 4.2.0).
The package depends on jinja2, jmespath, packaging, pydantic, and pyparsing. It's designed for workflows where you need to validate data with Pydantic and then load or process it in Spark, eliminating the need to maintain separate schema definitions. Fields can be excluded from Spark schemas using Pydantic's built-in exclude mechanism, useful for Spark-incompatible types.
Use it for:
- Define a Pydantic model for data validation, then generate a PySpark StructType schema for DataFrame operations without manual schema definition.
- Convert existing Pydantic BaseModel classes to Spark schemas using the standalone create_spark_schema function for legacy codebases.
- Generate JSON-formatted Spark schemas from Pydantic models for serialization or schema registry integration without requiring PySpark installed.
- Enforce type safety across validation and Spark processing by coercing Pydantic fields to specific Spark types via SparkField.
- Exclude Spark-incompatible fields (e.g., arbitrary objects) from schema generation while keeping them in the Pydantic model for validation.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Converts Pydantic models to PySpark schemas (StructType or JSON format), allowing you to define data structures once and generate compatible Spark schemas automatically.
Yes, if you work with both Pydantic and PySpark. Low install friction, no security vulnerabilities, and active maintenance make it a safe choice. The optional PySpark dependency is a practical design—you can use JSON schema generation immediately. The main caveat is that license information is unavailable, so verify licensing for your use case before committing to production.
Install
sparkdantic on PyPI
pip
pip install sparkdanticuv
uv add sparkdanticpoetry
poetry add sparkdanticInstalling sparkdantic
Before you install
Low install friction with a pure-Python wheel. PySpark is optional; JSON schema generation works without it, but StructType conversion requires PySpark 3.3.0 or higher (up to but not including 4.2.0). Actively maintained as of 32 days ago.
Quickstart
pip install sparkdantic
from sparkdantic import SparkModel
from typing import List
class MyModel(SparkModel):
name: str
age: int
hobbies: List[str]
spark_schema = MyModel.model_spark_schema()
PySpark 3.3.0 or higher (up to but not including 4.2.0) required for StructType schema generation; JSON schema generation works without PySpark.
Verify before relying
- Whether the package is actively maintained beyond the 32-day release window (no repo stars, commit history, or archived status data available).
- Real-world performance and compatibility with edge cases in complex Pydantic type hierarchies.
Package facts
| License | not declared (unclear) |
| Python support | supports the current Python release (<4.0.0,>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 5 — jinja2, jmespath, packaging, pydantic, pyparsing |
| Maintenance | actively maintained — 32 days since the last release |
| First released | |
| Downloads | 1,408,664/month — #3,942 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: sparkdantic-2.8.4-py3-none-any.whl
Tags
More Application Frameworks packages
FastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
textualTextual is a Python framework for building…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
mcpBuild and connect to Model Context Protocol…
permissive · top 1,000 on PyPI
WerkzeugWerkzeug is a WSGI utility library providing…
permissive · top 1,000 on PyPI
sparkaidProvides utilities for working with Spark…
copyleft · top 15,000 on PyPI
tinselGenerates PySpark DataFrame schemas from Python…
permissive · top 15,000 on PyPI
pbsparkConverts protobuf messages to and from PySpark…
permissive · top 15,000 on PyPI
pydantic-to-typescriptConverts pydantic model definitions into…
permissive · top 5,000 on PyPI
pydantic-sparkConverts Pydantic class definitions to Apache…
permissive · top 15,000 on PyPI
graphene-pydanticConverts Pydantic models into GraphQL object…
permissive · top 15,000 on PyPI
pydantic-to-typescript2Converts Pydantic models to TypeScript…
permissive · top 15,000 on PyPI
dydanticDynamically generates Pydantic models from JSON…
permissive · top 5,000 on PyPI
pyspark-data-sourcesProvides custom Apache Spark data sources using…
permissive · top 15,000 on PyPI
quinnQuinn provides helper methods for PySpark…
permissive · top 15,000 on PyPI