Reaction SDK for Project Drasi
Project description
Reaction SDK for Python
This library provides the building blocks and infrastructure to implement a Drasi Reaction in python.
Getting started
Install the package
pip install drasi_reaction_sdk
Simple example
The following example logs the various parts of the incoming change event from a Continuous Query.
from drasi.reaction.models.ChangeEvent import ChangeEvent
from drasi.reaction.sdk import DrasiReaction
async def change_event(event: ChangeEvent, query_configs: dict[str, Any] | None = None):
print(f"Received change sequence {event.sequence} for query {event.queryId}")
if event.addedResults:
print(f"Added result: {event.addedResults}")
if event.deletedResults:
print(f"Removed result: {event.deletedResults}")
if event.updatedResults:
print(
f"Updated result - before: {event.updatedResults[0].before}, after {event.updatedResults[0].after}"
)
reaction = DrasiReaction(on_change_event=change_event)
reaction.start()
Advanced example
The following example illustrates
- Retrieving a configuration value from the Reaction manifest
- Parsing the per query configuration object from Yaml
- Process change events from the query
- Process control events (start, stop, etc.) from the query
from drasi.reaction.models.ChangeEvent import ChangeEvent
from drasi.reaction.models.ControlEvent import ControlEvent
from drasi.reaction.sdk import DrasiReaction
from drasi.reaction.utils import get_config_value, parse_yaml
# Retrieve the connection string from the Reaction configuration
my_connection_string = get_config_value("MyConnectionString")
# Define the function that will be called when a change event is received
async def on_change_event(event: ChangeEvent, query_config: dict[str, Any] | None) -> None:
print(f"Received change signal for query {event.query_id}")
print(f"Passed in the query config: {query_config}")
# do something else with the `event` and `query_config`
# Define the function that will be called when a control event is received
async def on_control_event(event: ControlEvent, query_config: dict[str, Any] | None) -> None:
print(f"Received control signal: {event.control_signal} for query {event.query_id}")
print(f"Passed in the query config: {query_config}")
print(f"Starting Drasi reaction with connection string: {my_connection_string}")
# Configure the Reaction with the on_change_event and on_control_event functions
custom_reaction = DrasiReaction(
on_change_event=on_change_event,
on_control_event=on_control_event,
parse_query_configs=parse_yaml,
)
# Start the Reaction
custom_reaction.start()
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 drasi_reaction_sdk-0.1.2a0.tar.gz.
File metadata
- Download URL: drasi_reaction_sdk-0.1.2a0.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b9b3df42d851822ef1afa34adb658c77b9fcb35ee081930ad8504a5a1a423dc2
|
|
| MD5 |
0dcb6397eedf5005f95037e1fefa6429
|
|
| BLAKE2b-256 |
db9c793d132143c791339f727d9dabf682bd4ff28b11f09c699d160db226edbc
|
File details
Details for the file drasi_reaction_sdk-0.1.2a0-py3-none-any.whl.
File metadata
- Download URL: drasi_reaction_sdk-0.1.2a0-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0da31ef23343a7b96cf890fe3ed7781147e73e73d697d0acf3c23eade8d0cb16
|
|
| MD5 |
bfcb05ad79929a84e90714ad48f5e21b
|
|
| BLAKE2b-256 |
872a33efce4917aee6a1f69ce5bed0624e9c77469220cb8430a64d693729f886
|