Skip to main content

pyspark extra utilities

SparkMetrics

Track metrics (like number of rows/number of files written) when writing a DataFrame.

import pyspark.sql
from pysparkextra.metrics import SparkMetrics

spark_session: pyspark.sql.SparkSession
df: pyspark.sql.DataFrame = spark_session.createDataFrame(
    [
        [1, 2],
        [-3, 4],
    ],
    schema=("foo", "bar")
)

with SparkMetrics(spark_session) as metrics:
    df.write.parquet("/tmp/target", mode='overwrite')
print(metrics['numOutputRows'])  # 2

with SparkMetrics(spark_session) as metrics:
    df.union(df).write.parquet("/tmp/target", mode='overwrite')
print(metrics['numOutputRows'])  # 4

print(metrics)  # {'numFiles': 5, 'numOutputBytes': 3175, 'numOutputRows': 4, 'numParts': 0}

union arbitrary number of dataframes with arbitrary number of columns

from pyspark.sql import DataFrame, SparkSession
from pysparkextra.funcs import union

spark_session: SparkSession
df1: DataFrame = spark_session.createDataFrame(
    [
        [1, 2],
        [3, 4],
    ], schema=("foo", "bar"))
df2: DataFrame = spark_session.createDataFrame(
    [
        [10, 20, 30],
        [40, 50, 60],
    ], schema=("bar", "qux", "foo")
)
df3: DataFrame = spark_session.createDataFrame(
    [
        [100, 200],
        [300, 400],
    ], schema=("foo", "bar")
)

df: DataFrame = union(df1, df2, df3)

df.show()

# +---+---+----+
# |foo|bar| qux|
# +---+---+----+
# |  1|  2|null|
# |  3|  4|null|
# | 30| 10|  20|
# | 60| 40|  50|
# |100|200|null|
# |300|400|null|
# +---+---+----+

and more

Check out the tests, which also act as examples.

Metadata

Release files for pysparkextra 0.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pysparkextra 0.4.2
File Size Uploaded Provenance Actions
pysparkextra-0.4.2.tar.gz 8.5 kB Without provenance Details for pysparkextra-0.4.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pysparkextra 0.4.2
File Interpreter ABI Platform Actions
pysparkextra-0.4.2-py3-none-any.whl Python 3 none any Details for pysparkextra-0.4.2-py3-none-any.whl

Total release size: 18.8 kB

Release files / pysparkextra-0.4.2.tar.gz

Download URL pysparkextra-0.4.2.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
07166c9c9f5ede82c89e32c7b6fcf108ba71a494d8d6ffe828beb26466a0383d
BLAKE2b-256 checksum
How to use checksums
34f3079f7feedefbd6945aa27fc47b0ab493f8a59e3aedd3ead6dbf0a587fb7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

Release files / pysparkextra-0.4.2-py3-none-any.whl

Download URL pysparkextra-0.4.2-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ef08746bd3d0aea0849ba2dcba540cd887b9896019446477f659f98574b1612a
BLAKE2b-256 checksum
How to use checksums
59528daad79b6598d34bcfd170b8e00e23fa899b236c31a7a6f868b74e9e1ca8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

Security for pysparkextra 0.4.2

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page