Skip to main content

Collection of Apache Spark Custom Data Formats

Project description

PySpark Data Source Formats

This project provides a collection of custom data source formats for Apache Spark 4.0+ and Databricks, leveraging the new V2 data source PySpark API.


Documentation Status Latest Python Release


Formats

Currently, the following formats are supported:

Format Read Write Description
http-csv Yes No Reads CSV files in parallel directly from a URL.
http-json Yes No Reads JSON Lines in parallel directly from a URL.

Installation

# Install PySpark 4.0.0
pip install pyspark==4.0.0

# Install the package using pip
pip install pysparkformat

For Databricks, install within a Databricks notebook using:

%pip install pysparkformat

This has been tested with Databricks Runtime 15.4 LTS and later.

http-csv

The following options can be specified when using the http-csv format:

Name Description Type Default
header Indicates whether the CSV file contains a header row. boolean false
sep The field delimiter character. string ,
encoding The character encoding of the file. string utf-8
quote The quote character. string "
escape The escape character. string \
maxLineSize The maximum length of a line (in bytes). integer 10000
partitionSize The size of each data partition (in bytes). integer 1048576

Example

from pyspark.sql import SparkSession
from pysparkformat.http.csv import HTTPCSVDataSource

# Initialize SparkSession (only needed if not running in Databricks)
spark = SparkSession.builder.appName("http-csv-example").getOrCreate()

# You may need to disable format checking depending on your cluster configuration
spark.conf.set("spark.databricks.delta.formatCheck.enabled", False)

# Register the custom data source
spark.dataSource.register(HTTPCSVDataSource)

# URL of the CSV file
url = "https://raw.githubusercontent.com/aig/pysparkformat/refs/heads/main/tests/data/valid-with-header.csv"

# Read the data
df = spark.read.format("http-csv").option("header", True).load(url)

# Display the DataFrame (use `display(df)` in Databricks)
df.show()

http-json

Name Description Type Default
maxLineSize The maximum length of a line (in bytes). integer 10000
partitionSize The size of each data partition (in bytes). integer 1048576

Example

from pyspark.sql import SparkSession
from pysparkformat.http.json import HTTPJSONDataSource

# Initialize SparkSession (only needed if not running in Databricks)
spark = SparkSession.builder.appName("http-json-example").getOrCreate()

# You may need to disable format checking depending on your cluster configuration
spark.conf.set("spark.databricks.delta.formatCheck.enabled", False)

# Register the custom data source
spark.dataSource.register(HTTPJSONDataSource)

# URL of the JSON file
url = "https://raw.githubusercontent.com/aig/pysparkformat/refs/heads/main/tests/data/valid-nested.jsonl"

# Read the data (you must specify the schema at the moment)
json_schema = "name string, wins array<array<string>>"
df = spark.read.format("http-json").schema(json_schema).load(url)

# Display the DataFrame (use `display(df)` in Databricks)
df.show()

Contribute

Contributions are welcome! We encourage the addition of new custom data source formats and improvements to existing ones.

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

pysparkformat-0.0.12.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

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

pysparkformat-0.0.12-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file pysparkformat-0.0.12.tar.gz.

File metadata

  • Download URL: pysparkformat-0.0.12.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pysparkformat-0.0.12.tar.gz
Algorithm Hash digest
SHA256 61a02f037c368b4b6e9abccfe8612d5b5462bdd64d9a370fe3c286661f49962d
MD5 466912fd16cc65299a3ce46381eb59b8
BLAKE2b-256 01acc41573801516f6c847d81adfd4e1f5dff505be6ad0baaa0f3e652aeb0079

See more details on using hashes here.

Provenance

The following attestation bundles were made for pysparkformat-0.0.12.tar.gz:

Publisher: release.yaml on aig/pysparkformat

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pysparkformat-0.0.12-py3-none-any.whl.

File metadata

  • Download URL: pysparkformat-0.0.12-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pysparkformat-0.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 4572a60a656e2505a073642fa21fdb2a8b32f78fbef1005a518fea8f804c2cf7
MD5 5aa17b6d1156d23451e839659565cb63
BLAKE2b-256 6dffd5b996dfac92dd1f12b40a61d6bb4e93b17227b50dbff073d869ffe3c627

See more details on using hashes here.

Provenance

The following attestation bundles were made for pysparkformat-0.0.12-py3-none-any.whl:

Publisher: release.yaml on aig/pysparkformat

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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