Skip to main content

Collection of Apache Spark Custom Data Formats

Project description

pysparkformat: 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.

Supported Formats

Currently, the following format is supported:

http-csv

This format reads in parallel CSV directly from a URL.

Options

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

http-json

This format reads in parallel JSON Lines directly from a URL. You must specify the schema when using this format.

Options

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

Installation

This requires PySpark 4.0 or later to be installed:

pip install pyspark==4.0.0.dev2

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.

Usage Example: http-csv

This example demonstrates reading a CSV file from a URL using the http-csv format.

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/master/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()

Usage Example: http-json

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/master/tests/data/valid-nested.jsonl"

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

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

Contributing

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.7.tar.gz (7.4 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.7-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pysparkformat-0.0.7.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pysparkformat-0.0.7.tar.gz
Algorithm Hash digest
SHA256 088dfcfc6e3370511f549c2a85a70218e34326afa7043aedd6db65a815f401de
MD5 3b0c2c2992d31e07f30133b295879569
BLAKE2b-256 5bebc23e155e0a8ce8839a9f1e989b6fe96e114dd7f01beac65f3ab6573b8055

See more details on using hashes here.

Provenance

The following attestation bundles were made for pysparkformat-0.0.7.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.7-py3-none-any.whl.

File metadata

  • Download URL: pysparkformat-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pysparkformat-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 8a2e5709922670c06f113027280a038ed36c6642be439dc7127f777ec4d4b217
MD5 a165b0f11ed24e4b40af6aac13bfcbb3
BLAKE2b-256 00897968f57e15648137bb010ed2397462cffaf5e9b4ba223d43d6089151fb7d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pysparkformat-0.0.7-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