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.dev2
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.

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

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/master/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.11.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.11-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pysparkformat-0.0.11.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.11.tar.gz
Algorithm Hash digest
SHA256 fc1d3b8436a8887da849e3fb10621bfcbea43752699e3bada48f9f839f235c9f
MD5 a3d0f90daaba7085844adff6c07cd260
BLAKE2b-256 ea78441b6517ed8a3e42a3b005ad044d59e92dc573692bc8076d452d87c22266

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pysparkformat-0.0.11-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.11-py3-none-any.whl
Algorithm Hash digest
SHA256 7f76351d66834c1e5007cbf0535bee349b747e20402daac60a3f651db299bb21
MD5 415820430bebdc95085689cde41c0594
BLAKE2b-256 d67dd3c59a86102d623c7b4a0b8c9fe31de8a59880af7952e86e9c9d314b1b67

See more details on using hashes here.

Provenance

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