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.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pysparkformat-0.0.10.tar.gz.
File metadata
- Download URL: pysparkformat-0.0.10.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
00332b93d16f890a615531bc2ab8da6ba9318cecf6429f30aea1ff75171477d1
|
|
| MD5 |
70cfcf3b34d4e2aee89dfb217dca72bb
|
|
| BLAKE2b-256 |
9ff18fd72aaa113e5063f4adbc51629f7f7dea7cd228b3336c7e4e8963c3fb29
|
Provenance
The following attestation bundles were made for pysparkformat-0.0.10.tar.gz:
Publisher:
release.yaml on aig/pysparkformat
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pysparkformat-0.0.10.tar.gz -
Subject digest:
00332b93d16f890a615531bc2ab8da6ba9318cecf6429f30aea1ff75171477d1 - Sigstore transparency entry: 156728534
- Sigstore integration time:
-
Permalink:
aig/pysparkformat@ed7609654ea38fcfe8db0ffdffbfe9c3502164fe -
Branch / Tag:
refs/tags/release/v0.0.10 - Owner: https://github.com/aig
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@ed7609654ea38fcfe8db0ffdffbfe9c3502164fe -
Trigger Event:
push
-
Statement type:
File details
Details for the file pysparkformat-0.0.10-py3-none-any.whl.
File metadata
- Download URL: pysparkformat-0.0.10-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df1e5e8c0112f1685d18b95ad0303229c4b20dbba7bb3ba6bed3a5d744a2c948
|
|
| MD5 |
13d1ab1baddac29a914d7dd37d3c30d8
|
|
| BLAKE2b-256 |
6578bc891f982f8658e22cabd5c59ee02c9582a645c097010e9bed3a1fc24d3f
|
Provenance
The following attestation bundles were made for pysparkformat-0.0.10-py3-none-any.whl:
Publisher:
release.yaml on aig/pysparkformat
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pysparkformat-0.0.10-py3-none-any.whl -
Subject digest:
df1e5e8c0112f1685d18b95ad0303229c4b20dbba7bb3ba6bed3a5d744a2c948 - Sigstore transparency entry: 156728535
- Sigstore integration time:
-
Permalink:
aig/pysparkformat@ed7609654ea38fcfe8db0ffdffbfe9c3502164fe -
Branch / Tag:
refs/tags/release/v0.0.10 - Owner: https://github.com/aig
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@ed7609654ea38fcfe8db0ffdffbfe9c3502164fe -
Trigger Event:
push
-
Statement type: