Custom Spark data sources for reading and writing data in Apache Spark, using the Python Data Source API
Project description
PySpark Data Sources
This repository showcases custom Spark data sources built using the new Python Data Source API introduced in Apache Spark 4.0. For an in-depth understanding of the API, please refer to the API source code. Note this repo is demo only and please be aware that it is not intended for production use. Contributions and feedback are welcome to help improve the examples.
Installation
pip install pyspark-data-sources
Usage
Make sure you have pyspark >= 4.0.0 installed.
pip install pyspark
Or use Databricks Runtime 15.4 LTS or above versions, or Databricks Serverless.
from pyspark_datasources.fake import FakeDataSource
# Register the data source
spark.dataSource.register(FakeDataSource)
spark.read.format("fake").load().show()
# For streaming data generation
spark.readStream.format("fake").load().writeStream.format("console").start()
Example Data Sources
| Data Source | Short Name | Description | Dependencies |
|---|---|---|---|
| GithubDataSource | github |
Read pull requests from a Github repository | None |
| FakeDataSource | fake |
Generate fake data using the Faker library |
faker |
| StockDataSource | stock |
Read stock data from Alpha Vantage | None |
| GoogleSheetsDataSource | googlesheets |
Read table from public Google Sheets | None |
| KaggleDataSource | kaggle |
Read datasets from Kaggle | kagglehub, pandas |
| SimpleJsonDataSource | simplejson |
Write JSON data to Databricks DBFS | databricks-sdk |
| OpenSkyDataSource | opensky |
Read from OpenSky Network. | None |
| SalesforceDataSource | salesforce |
Streaming sink for writing data to Salesforce | simple-salesforce |
See more here: https://allisonwang-db.github.io/pyspark-data-sources/.
Official Data Sources
For production use, consider these official data source implementations built with the Python Data Source API:
| Data Source | Repository | Description | Features |
|---|---|---|---|
| HuggingFace Datasets | @huggingface/pyspark_huggingface | Production-ready Spark Data Source for 🤗 Hugging Face Datasets | • Stream datasets as Spark DataFrames • Select subsets/splits with filters • Authentication support • Save DataFrames to Hugging Face |
Contributing
We welcome and appreciate any contributions to enhance and expand the custom data sources.:
- Add New Data Sources: Want to add a new data source using the Python Data Source API? Submit a pull request or open an issue.
- Suggest Enhancements: If you have ideas to improve a data source or the API, we'd love to hear them!
- Report Bugs: Found something that doesn't work as expected? Let us know by opening an issue.
Development
Environment Setup
poetry install
poetry env activate
Build Docs
mkdocs serve
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 pyspark_data_sources-0.1.9.tar.gz.
File metadata
- Download URL: pyspark_data_sources-0.1.9.tar.gz
- Upload date:
- Size: 27.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.3 Darwin/24.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b2b0625d4132297eba74a093e5193ce8cea52666a6369bf3463aa9f1d996fc6
|
|
| MD5 |
a0aebc2f928b96be73a11bd80a555784
|
|
| BLAKE2b-256 |
abacb91aa834715150d8fe9be08f63fea2833fa8ac66b8bee610cd120e269f74
|
File details
Details for the file pyspark_data_sources-0.1.9-py3-none-any.whl.
File metadata
- Download URL: pyspark_data_sources-0.1.9-py3-none-any.whl
- Upload date:
- Size: 32.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.3 Darwin/24.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a4652fc4153becead7b77d46d7aa850d68208dbbe117fe937573158a7d3668b
|
|
| MD5 |
fc51f92ce1e280a4499a41a2cee3a1bb
|
|
| BLAKE2b-256 |
da34866bc4ba8eba9c25b289ea9b9f37614e1d2461f5fa216042200c312d9943
|