risingwave-py SDK.
This SDK provides a simple way to perform ad-hoc queries, subscribe to changes, and define event handlers for tables and materialized views, making it easier to integrate real-time data into applications. For details, see Python SDK.
As RisingWave is wire-compatible with PostgreSQL, you can also use third-party PostgreSQL drivers like psycopg2 and sqlalchemy to interact with RisingWave from your Python applications.
Use psycopg2 to connect to RisingWave
In this section, we use the psycopg2 driver to connect to RisingWave.
Run RisingWave
To learn about how to run RisingWave, see Run RisingWave.Install the psgcopg2 driver
For information about how to install psycopg and the difference between psycopg and psycopg-binary, see the official psycopg documentation.
Connect to RisingWave
To connect to RisingWave viapsycopg2:
Create a source
The code below creates a sourcewalk with the datagen connector. The datagen connector is used to generate mock data. The walk source consists of two columns, distance and duration, which respectively represent the distance and the duration of a walk. The source is a simplified version of the data that is tracked by smart watches.
All the code examples in this guide include a section for connecting to RisingWave. If you perform multiple actions within one connection session, you do not need to repeat this section.
Create a materialized view
The code in this section creates a materialized viewcounter to capture the latest total distance and duration.
Query a materialized view
The code in this section queries the materialized viewcounter to get real-time data.
Use sqlalchemy to connect to RisingWave
In this section, we use the SQLAlchemy driver to connect to RisingWave.
Run RisingWave
To learn about how to run RisingWave, see Run RisingWave.Install necessary Python packages
Ensure you have Python3 installed. For more information aboutsqlalchemy, see the SQLAlchemy. Refer to the documentation version that corresponds to the version of SQLAlchemy that you run.
For information about how to install psycopg-binary, see the official psycopg documentation.
Connect to RisingWave
To connect to RisingWave viasqlalchemy:
sqlaclehmy-postgres so risingwave+psycopg2 is used as the URI scheme. The rest of the URL follows the same format as the PostgreSQL driver.
Create a source
The code below creates a tableusers using the engine created in the previous section.