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.


Latest Python Release


Supported Formats

Currently, the following formats are 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.9.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.9-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pysparkformat-0.0.9.tar.gz
Algorithm Hash digest
SHA256 db8aa16cb2c8f2fefd260c58b9daf7898e9af5fa7879827563ffea559b0efbc9
MD5 891191db99cc5f09709f63df37e92ca1
BLAKE2b-256 3b33b4cd8ee30450bd66f40aaa77273651bd5f15fb344f6c852bef57f6ddf40f

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pysparkformat-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for pysparkformat-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 bbbd3f0476ee0257c4f6a2fc99969f46283a13fea3208d11736ad2fc6d11a94d
MD5 099070ebc40a8cc24e2f45ad7237f6bf
BLAKE2b-256 5b8c7ccd30f7f46a940dd5decccbc808f0aa1993f8f8cd94657abf10a8426520

See more details on using hashes here.

Provenance

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