Registry / type-stubs / pyspark-stubs

pyspark-stubs

JSON →
library3.0.0.post3pypypiunverified

PySpark Stubs (pyspark-stubs) provides automatically generated type stubs for the Apache PySpark library. These stubs enable IDEs and static type checkers like MyPy to provide intelligent code completion, detect common programming errors, and improve code quality by enforcing type safety in PySpark applications. The current version is 3.0.0.post3, typically updated to align with major PySpark releases, often with `post` versions for stub refinements.

pip install pyspark-stubs
INSTALL
IMPORT
SIG · PYSPARK-STUBS
P
pyspark-stubs
type-stubspythonv3.0.0.post3
Install
15.4s avg
Import
252ms
Disk
242MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.0.0.post3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.940 runs
installs and imports cleanly · install 0.0s · import 0.108s · 244MB
glibc
py 3.103.940 runs
installs and imports cleanly · install 15.4s · import 0.093s · 245MB
242MB installed
● package 242MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SparkSession
from pyspark.sql import SparkSession
from pyspark.sql import SparkSession

This quickstart demonstrates how to use PySpark with type hints, leveraging `pyspark-stubs`. You install `pyspark-stubs` alongside your `pyspark` installation. When a type checker like MyPy processes this code, it uses the installed stubs to validate types for PySpark objects like `SparkSession` and DataFrame methods. The stubs themselves have no runtime effect; they only assist static analysis.

import os from pyspark.sql import SparkSession from typing import List # Instantiate SparkSession (requires PySpark to be installed and configured) spark: SparkSession = (SparkSession.builder .appName("PySparkStubsExample") .getOrCreate() ) # Example of using PySpark with type hints def process_data(data: List[int]) -> List[int]: # In a real scenario, this would involve Spark RDDs/DataFrames # This is a simplified example to show type hints in action. # For a type checker, 'pyspark-stubs' helps validate Spark-specific types. print(f"Processing data: {data}") return [x * 2 for x in data] if __name__ == '__main__': sample_data: List[int] = [1, 2, 3] processed_result = process_data(sample_data) print(f"Processed result: {processed_result}") # Example with a Spark DataFrame (for demonstration of type support) # This part requires a running SparkSession and actual PySpark code. # For type checking, `pyspark-stubs` ensures `spark` is typed correctly. data_df = spark.createDataFrame([("Alice", 1), ("Bob", 2)], ["name", "age"]) data_df.printSchema() data_df.show() spark.stop()
Debug
Known issues
gotchaThe version of `pyspark-stubs` should generally match the major version of your `pyspark` installation. Mismatched versions can lead to incorrect type checking results, including missing attributes or incompatible type signatures.
fix
Ensure `pip install pyspark-stubs==X.Y.*` where `X.Y` matches your `pyspark` major.minor version. E.g., for PySpark 3.0.x, use `pyspark-stubs==3.0.*`.
affects: All versions
gotcha`pyspark-stubs` only provides type hint files (`.pyi`); it does not include or install the actual `pyspark` library. Your code will not run if `pyspark` is not installed separately.
fix
Install `pyspark` (e.g., `pip install pyspark`) in addition to `pyspark-stubs` if you intend to run PySpark code.
affects: All versions
gotchaInstalling `pyspark-stubs` has no runtime effect on your PySpark application. Its sole purpose is to provide static type information for tools like MyPy, Pylance, or other IDEs.
fix
Understand that `pyspark-stubs` is a development-time dependency for type checking, not a runtime dependency. If you encounter runtime errors, they are related to your PySpark setup, not the stubs.
affects: All versions
Upgrade
Version history
3.0.0.post3latest on PyPI · released Jan 5, 2022
Audit
Dependencies
pysparkrequiredThese are type stubs *for* PySpark; PySpark itself must be installed separately to run code, though it's not a direct install dependency of this stub package.
Agent activity
18 hits · last 30 days
node
16
Amazon
1
OpenAI (training)
1
Resources
pyspark-stubs — pip install pyspark-stubs · libregistry