# RisingWave Python SDK
Simple Python SDK for event-driven applications with RisingWave.
## Quick start
### 1. Install risingwave-py ([PyPI](https://pypi.org/project/risingwave-py/))
```bash
pip install risingwave-py
```
### 2. Run RisingWave
You can install RisingWave standlone on your laptop via:
```bash
# Download and install RisingWave standalone
curl https://risingwave.com/sh | sh
# start RisingWave on macOS
risingwave
# start RisingWave on linux
./risingwave
```
You can also provision a free-tier cluster in [RisingWave Cloud](https://cloud.risingwave.com/auth/signin/)
### 3. Interact with RisingWave in Python
#### Initialization
```python
from risingwave import RisingWave, RisingWaveConnOptions, OutputFormat
import pandas as pd
import threading
# Init to connect to RisingWave instance on localhost
# You can also init with a connection string: RisingWave(RisingWaveConnOptions("postgresql://root:root@localhost:4566/dev"))
rw = RisingWave(
RisingWaveConnOptions.from_connection_info(
host="localhost", port=4566, user="root", password="root", database="dev"
)
)
```
#### Insert and query data in DataFrame via SQL
```python
# Insert a dataframe into a test_product table
test_df1 = pd.DataFrame(
{
"product": ["foo", "bar"],
"price": [123.4, 456.7],
}
)
rw.insert(table_name="test_product", data=test_df1)
# Fetch data from the test_product table via SQL
rw.fetch("SELECT * FROM test_product", format=OutputFormat.DATAFRAME)
```
#### Subscribe changes from a table
```python
# Subscribe to changes in the test_product table in a separate thread.
# Print out the changes to console when they occur.
def subscribe_product_change():
rw.on_change(
subscribe_from="test_product",
handler=lambda x: print(x),
output_format=OutputFormat.DATAFRAME,
)
threading.Thread(target=subscribe_product_change).start()
# Insert a new dataframe into the table test_product
test_df2 = pd.DataFrame(
{
"product": ["foo", "bar"],
"price": [78.9, 10.11],
}
)
rw.insert(table_name="test_product", data=test_df2)
### You should be able to see the changes for produce in console now!
```
#### Define your streaming job via materialized view in SQL
```python
# Create a materialized view to calculate the average price of each product
mv = rw.mv(
name="test_product_avg_price_mv",
stmt="SELECT product, avg(price) as avg_price from test_product GROUP BY product",
)
# Fetch data from the materialized view via SQL
rw.fetch("SELECT * FROM test_product_avg_price_mv", format=OutputFormat.DATAFRAME)
```
#### Subscribe changes from your stremaing job
```python
# Subscribe to changes in avg price for each produce.
# Print out the changes to console when they occur.
def subscribe_product_avg_price_change():
mv.on_change(
handler=lambda x: print(x),
output_format=OutputFormat.DATAFRAME,
)
threading.Thread(target=subscribe_product_avg_price_change).start()
# Insert a new dataframe into the test_product
test_df3 = pd.DataFrame(
{
"product": ["foo", "bar"],
"price": [200, 0.11],
}
)
rw.insert(table_name="test_product", data=test_df3)
### You should be able to see the changes in for product and product avg price console now!
```
## Demo
You can also check the demo in our [repo](https://github.com/risingwavelabs/risingwave-py).
```shell
python3 -m venv
source ./venv/bin/activate
python3 demo.py simple
```
Raw data
{
"_id": null,
"home_page": null,
"name": "risingwave-py",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "risingwave, risingwave-py, risingwave-python, risingwave_py, risingwave_python",
"author": null,
"author_email": "Mike Wang <mikecwangcn@gmail.com>, Patrick Huang <hzxa21@hotmail.com>",
"download_url": "https://files.pythonhosted.org/packages/34/1d/f504f5801ce9377966d85ed83211b513eb06ce534de08b56cbdedfcc619f/risingwave_py-0.0.1.tar.gz",
"platform": null,
"description": "# RisingWave Python SDK\n\nSimple Python SDK for event-driven applications with RisingWave.\n\n## Quick start\n\n### 1. Install risingwave-py ([PyPI](https://pypi.org/project/risingwave-py/))\n```bash\npip install risingwave-py\n```\n\n### 2. Run RisingWave\nYou can install RisingWave standlone on your laptop via:\n```bash\n# Download and install RisingWave standalone\ncurl https://risingwave.com/sh | sh\n\n# start RisingWave on macOS\nrisingwave\n\n# start RisingWave on linux\n./risingwave\n```\n\nYou can also provision a free-tier cluster in [RisingWave Cloud](https://cloud.risingwave.com/auth/signin/)\n\n### 3. Interact with RisingWave in Python\n#### Initialization\n```python\nfrom risingwave import RisingWave, RisingWaveConnOptions, OutputFormat\nimport pandas as pd\nimport threading\n\n# Init to connect to RisingWave instance on localhost\n# You can also init with a connection string: RisingWave(RisingWaveConnOptions(\"postgresql://root:root@localhost:4566/dev\"))\nrw = RisingWave(\n RisingWaveConnOptions.from_connection_info(\n host=\"localhost\", port=4566, user=\"root\", password=\"root\", database=\"dev\"\n )\n)\n```\n\n#### Insert and query data in DataFrame via SQL\n```python\n# Insert a dataframe into a test_product table\ntest_df1 = pd.DataFrame(\n {\n \"product\": [\"foo\", \"bar\"],\n \"price\": [123.4, 456.7],\n }\n)\nrw.insert(table_name=\"test_product\", data=test_df1)\n\n# Fetch data from the test_product table via SQL\nrw.fetch(\"SELECT * FROM test_product\", format=OutputFormat.DATAFRAME)\n```\n\n#### Subscribe changes from a table\n```python\n# Subscribe to changes in the test_product table in a separate thread.\n# Print out the changes to console when they occur.\ndef subscribe_product_change():\n rw.on_change(\n subscribe_from=\"test_product\",\n handler=lambda x: print(x),\n output_format=OutputFormat.DATAFRAME,\n )\n\n\nthreading.Thread(target=subscribe_product_change).start()\n\n\n# Insert a new dataframe into the table test_product\ntest_df2 = pd.DataFrame(\n {\n \"product\": [\"foo\", \"bar\"],\n \"price\": [78.9, 10.11],\n }\n)\nrw.insert(table_name=\"test_product\", data=test_df2)\n\n\n### You should be able to see the changes for produce in console now!\n```\n\n#### Define your streaming job via materialized view in SQL\n```python\n# Create a materialized view to calculate the average price of each product\nmv = rw.mv(\n name=\"test_product_avg_price_mv\",\n stmt=\"SELECT product, avg(price) as avg_price from test_product GROUP BY product\",\n)\n\n# Fetch data from the materialized view via SQL\nrw.fetch(\"SELECT * FROM test_product_avg_price_mv\", format=OutputFormat.DATAFRAME)\n```\n\n#### Subscribe changes from your stremaing job\n```python\n# Subscribe to changes in avg price for each produce.\n# Print out the changes to console when they occur.\ndef subscribe_product_avg_price_change():\n mv.on_change(\n handler=lambda x: print(x),\n output_format=OutputFormat.DATAFRAME,\n )\n\n\nthreading.Thread(target=subscribe_product_avg_price_change).start()\n\n\n# Insert a new dataframe into the test_product\ntest_df3 = pd.DataFrame(\n {\n \"product\": [\"foo\", \"bar\"],\n \"price\": [200, 0.11],\n }\n)\nrw.insert(table_name=\"test_product\", data=test_df3)\n\n\n### You should be able to see the changes in for product and product avg price console now!\n```\n\n## Demo\nYou can also check the demo in our [repo](https://github.com/risingwavelabs/risingwave-py). \n```shell\npython3 -m venv\nsource ./venv/bin/activate\npython3 demo.py simple\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "Python SDK for real-time processing",
"version": "0.0.1",
"project_urls": null,
"split_keywords": [
"risingwave",
" risingwave-py",
" risingwave-python",
" risingwave_py",
" risingwave_python"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "22467ae4894cddab522da4ba549ddd3897512386831e89983b923ae3b3f0553b",
"md5": "e5f212374f46b34160018de880295062",
"sha256": "776852c8fc4a554fb581c1cc49fd5cd5fd7a89f4999c8072334b65caa18116d3"
},
"downloads": -1,
"filename": "risingwave_py-0.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e5f212374f46b34160018de880295062",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 12265,
"upload_time": "2024-09-12T06:06:13",
"upload_time_iso_8601": "2024-09-12T06:06:13.998539Z",
"url": "https://files.pythonhosted.org/packages/22/46/7ae4894cddab522da4ba549ddd3897512386831e89983b923ae3b3f0553b/risingwave_py-0.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "341df504f5801ce9377966d85ed83211b513eb06ce534de08b56cbdedfcc619f",
"md5": "1037e161191574bd8bf36a333fec3bb5",
"sha256": "6c01cf78bf7f0283c1b73176f1afe624e1131a23e90940dd5371378b137d0f96"
},
"downloads": -1,
"filename": "risingwave_py-0.0.1.tar.gz",
"has_sig": false,
"md5_digest": "1037e161191574bd8bf36a333fec3bb5",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 13525,
"upload_time": "2024-09-12T06:06:15",
"upload_time_iso_8601": "2024-09-12T06:06:15.845390Z",
"url": "https://files.pythonhosted.org/packages/34/1d/f504f5801ce9377966d85ed83211b513eb06ce534de08b56cbdedfcc619f/risingwave_py-0.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-12 06:06:15",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "risingwave-py"
}