This release is a pre-release and may not be stable for production use.
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()
Metadata
Release files for drasi-reaction-sdk 0.1.2a0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| drasi_reaction_sdk-0.1.2a0.tar.gz | 6.1 kB | Without provenance | Details for drasi_reaction_sdk-0.1.2a0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| drasi_reaction_sdk-0.1.2a0-py3-none-any.whl | Python 3 | none | any | Details for drasi_reaction_sdk-0.1.2a0-py3-none-any.whl |
Total release size: 18.3 kB
Release files / drasi_reaction_sdk-0.1.2a0.tar.gz
| Download URL | drasi_reaction_sdk-0.1.2a0.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b9b3df42d851822ef1afa34adb658c77b9fcb35ee081930ad8504a5a1a423dc2
|
|
BLAKE2b-256 checksum How to use checksums |
db9c793d132143c791339f727d9dabf682bd4ff28b11f09c699d160db226edbc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.0
|
Release files / drasi_reaction_sdk-0.1.2a0-py3-none-any.whl
| Download URL | drasi_reaction_sdk-0.1.2a0-py3-none-any.whl |
|---|---|
| Size | 12.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0da31ef23343a7b96cf890fe3ed7781147e73e73d697d0acf3c23eade8d0cb16
|
|
BLAKE2b-256 checksum How to use checksums |
872a33efce4917aee6a1f69ce5bed0624e9c77469220cb8430a64d693729f886
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.0
|
Security for drasi-reaction-sdk 0.1.2a0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.