# Introduction
This Spark package is designed to process data from various sources, perform transformations, and write the results to different sinks. It follows the pipeline design pattern to provide a flexible and modular approach to data processing.
## Setup
Install this package using:
```bash
pip install pysparkify
```
Create spark_config.conf file of this format to enter all configurations related to spark in `config/spark_config.conf`
```bash
[SPARK]
spark.master=local[*]
spark.app.name=PysparkifyApp
spark.executor.memory=4g
spark.driver.memory=2g
```
This library abstracts Spark data processing workflows. For example you would like to;
- take first two rows of the data, save it as a separate output
- take an average and save it as a separate output
with below sample data
```
name,age,city
Hayaan,10,Islamanad
Jibraan,8,ShahAlam
Allyan,3,Paris
John,35,San Francisco
Doe,22,Houston
Dane,30,Seattle
```
Your recipe reads the csv data as source, transforms the data and optionally save the output of each transformation to sink. Below would be the recipe.yml for this operation.
```
source:
- type: CsvSource
config:
name: csv
path: "resources/data/input_data.csv"
transformer:
- type: SQLTransformer
config:
name: transformer1
source:
- name: csv
as_name: t1
statement:
- sql: "SELECT * from t1 limit 2"
as_name: trx1
to_sink: sink1
- sql: "select AVG(age) from trx1"
as_name: trx2
to_sink: sink2
sink:
- type: CsvSink
config:
name: sink1
path: "output/output_data.csv"
- type: CsvSink
config:
name: sink2
path: "output/avgage_data.csv"
```
### Usage
This library can be run as a command line tool:
```bash
pysparkify 'path/to/recipe.yml'
```
Or use it in your Python scripts:
```python
from pysparkify.lib.app import run
run('path/to/recipe.yml') #this expects spark_config.conf file on path `config/spark_config.conf` path
# or with optional spark configuration file
run('path/to/recipe.yml', 'path/to/custom_spark_config.conf')
```
## Design
The package is structured as follows:
### Source, Sink and Transformer Abstraction
The package defines abstract classes `Source`, `Sink` and `Transformer` to represent data sources, sinks and transformers. It also provides concrete classes, including `CsvSource`, `CsvSink` and `SQLTransformer`, which inherit from the abstract classes. This design allows you to add new source and sink types with ease.
### Configuration via `recipe.yml`
The package reads its configuration from a `recipe.yml` file. This YAML file specifies the source, sink, and transformation configurations. It allows you to define different data sources, sinks, and transformation queries.
### Transformation Queries
Transformations are performed by `SQLTransformer` using Spark SQL queries defined in the configuration. These queries are executed on the data from the source before writing it to the sink. New transformers can be implemented by extending `Transformer` abstract class that can take spark dataframes from sources to process and send dataframes to sinks to save.
### Pipeline Execution
The package reads data from the specified source, performs transformations based on the configured SQL queries, and then writes the results to the specified sink. You can configure multiple sources and sinks within the same package.
## How to Contribute
1. There are plenty of ways, in which implementation of new Sources and Sinks top the list
2. Open a PR
3. PR is reviewed and approved, included `github actions` will deploy the version directly to pypi repository
Raw data
{
"_id": null,
"home_page": "https://github.com/raohammad/pysparkify",
"name": "pysparkify",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "python, pysparkify, etl, bigdata",
"author": "Hammad Aslam KHAN",
"author_email": "raohammad@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/1e/0a/4c2b8b9c86e00b456053ed3b9fa2b4ca4d745ad289226e899e0c5124db49/pysparkify-0.26.3.tar.gz",
"platform": null,
"description": "# Introduction\nThis Spark package is designed to process data from various sources, perform transformations, and write the results to different sinks. It follows the pipeline design pattern to provide a flexible and modular approach to data processing.\n\n## Setup\n\nInstall this package using:\n\n```bash\npip install pysparkify\n```\n\nCreate spark_config.conf file of this format to enter all configurations related to spark in `config/spark_config.conf`\n\n```bash\n[SPARK]\nspark.master=local[*]\nspark.app.name=PysparkifyApp\nspark.executor.memory=4g\nspark.driver.memory=2g\n```\n\nThis library abstracts Spark data processing workflows. For example you would like to;\n\n- take first two rows of the data, save it as a separate output\n- take an average and save it as a separate output\n\nwith below sample data\n\n```\nname,age,city\nHayaan,10,Islamanad\nJibraan,8,ShahAlam\nAllyan,3,Paris\nJohn,35,San Francisco\nDoe,22,Houston\nDane,30,Seattle\n```\n\nYour recipe reads the csv data as source, transforms the data and optionally save the output of each transformation to sink. Below would be the recipe.yml for this operation.\n\n```\nsource:\n - type: CsvSource\n config:\n name: csv\n path: \"resources/data/input_data.csv\"\n\ntransformer:\n - type: SQLTransformer\n config:\n name: transformer1\n source: \n - name: csv\n as_name: t1\n statement: \n - sql: \"SELECT * from t1 limit 2\"\n as_name: trx1\n to_sink: sink1\n - sql: \"select AVG(age) from trx1\"\n as_name: trx2\n to_sink: sink2\n\nsink:\n - type: CsvSink\n config:\n name: sink1\n path: \"output/output_data.csv\"\n - type: CsvSink\n config:\n name: sink2\n path: \"output/avgage_data.csv\"\n \n```\n\n\n### Usage\n\nThis library can be run as a command line tool:\n\n```bash\npysparkify 'path/to/recipe.yml'\n```\n\nOr use it in your Python scripts:\n\n```python\n\nfrom pysparkify.lib.app import run\nrun('path/to/recipe.yml') #this expects spark_config.conf file on path `config/spark_config.conf` path\n\n# or with optional spark configuration file\nrun('path/to/recipe.yml', 'path/to/custom_spark_config.conf')\n\n```\n\n\n## Design\n\nThe package is structured as follows:\n\n### Source, Sink and Transformer Abstraction\n\nThe package defines abstract classes `Source`, `Sink` and `Transformer` to represent data sources, sinks and transformers. It also provides concrete classes, including `CsvSource`, `CsvSink` and `SQLTransformer`, which inherit from the abstract classes. This design allows you to add new source and sink types with ease.\n\n### Configuration via `recipe.yml`\n\nThe package reads its configuration from a `recipe.yml` file. This YAML file specifies the source, sink, and transformation configurations. It allows you to define different data sources, sinks, and transformation queries.\n\n### Transformation Queries\n\nTransformations are performed by `SQLTransformer` using Spark SQL queries defined in the configuration. These queries are executed on the data from the source before writing it to the sink. New transformers can be implemented by extending `Transformer` abstract class that can take spark dataframes from sources to process and send dataframes to sinks to save.\n\n### Pipeline Execution\n\nThe package reads data from the specified source, performs transformations based on the configured SQL queries, and then writes the results to the specified sink. You can configure multiple sources and sinks within the same package.\n\n\n## How to Contribute\n\n1. There are plenty of ways, in which implementation of new Sources and Sinks top the list\n2. Open a PR\n3. PR is reviewed and approved, included `github actions` will deploy the version directly to pypi repository\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Spark based ETL",
"version": "0.26.3",
"project_urls": {
"Homepage": "https://github.com/raohammad/pysparkify"
},
"split_keywords": [
"python",
" pysparkify",
" etl",
" bigdata"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "97818cd5ef895ec68eb8e9a08f045e01f2311ed63e8e2869c9cd6a66a75b6124",
"md5": "007515f4aac19a93b00399284393eeaf",
"sha256": "da71d2d877eeda5c23793003c681b75b4f4d4e8dc0ecd65b88e14f4c6988c987"
},
"downloads": -1,
"filename": "pysparkify-0.26.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "007515f4aac19a93b00399284393eeaf",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 12621,
"upload_time": "2024-05-01T15:48:55",
"upload_time_iso_8601": "2024-05-01T15:48:55.981929Z",
"url": "https://files.pythonhosted.org/packages/97/81/8cd5ef895ec68eb8e9a08f045e01f2311ed63e8e2869c9cd6a66a75b6124/pysparkify-0.26.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1e0a4c2b8b9c86e00b456053ed3b9fa2b4ca4d745ad289226e899e0c5124db49",
"md5": "6b77593dff2f6fb4d5ebe42008b441d0",
"sha256": "a75c73ce7f3bb98ffa231f830ed2646ff0184462bb51b45ae327f4189a621bc1"
},
"downloads": -1,
"filename": "pysparkify-0.26.3.tar.gz",
"has_sig": false,
"md5_digest": "6b77593dff2f6fb4d5ebe42008b441d0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 9733,
"upload_time": "2024-05-01T15:48:57",
"upload_time_iso_8601": "2024-05-01T15:48:57.757028Z",
"url": "https://files.pythonhosted.org/packages/1e/0a/4c2b8b9c86e00b456053ed3b9fa2b4ca4d745ad289226e899e0c5124db49/pysparkify-0.26.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-01 15:48:57",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "raohammad",
"github_project": "pysparkify",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pysparkify"
}