Filter Events

Keep only rows that match a column filter, a Python predicate, or a SQL query.

Exactly one of keep, drop, func, or sql must be provided. If all are None the eventstream is returned unchanged.

Usage

stream.filter_events(keep={"event": ["purchase", "add_to_cart"]})
stream.filter_events(drop={"event": ["system_event"], "platform": ["bot"]})
stream.filter_events(sql="SELECT * FROM eventstream WHERE event NOT LIKE 'system_%'")

Parameters

ParameterTypeDescription
keepdict, optional{column: values} mapping. Keeps rows where each listed column contains one of the listed values. Multiple columns combine with AND: a row is kept only if it matches every entry. Example: {"event": ["purchase", "add_to_cart"]}.
dropdict, optionalSame {column: values} format, but removes the matching rows instead. Multiple columns combine with OR: a row is removed if it matches any entry (the exact complement of keep).
funccallable, optionalA function that accepts the raw pandas DataFrame and returns a boolean Series. Rows where the Series is True are kept.
sqlstr, optionalDuckDB SQL SELECT statement that reads from the eventstream table alias and returns all original columns. Example: "SELECT * FROM eventstream WHERE event NOT LIKE 'system_%'".