Filter Matcher Module

Overview

The filter_matcher module provides filter matching for the newsletter editor UI.

It wraps sendMail’s filtering logic to:

  • Apply filters to subscriber rows in the editor

  • Show live preview of filtered results

  • Validate filters against actual data

Filter matching wrapper for editor filter preview.

Wraps sendMail.filter() to apply filters in the newsletter editor UI. Provides live preview of how filters will affect subscriber lists.

Classes:

FilterMatcher: Applies filters to rows for preview in editor UI

class filter_matcher.FilterMatcher[source]

Bases: object

Wrapper around sendMail.filter() for filter matching.

__init__() None[source]
is_available() bool[source]

Check if sendMail.filter is available.

match_row(row_data: list[Any], filter_dict: dict[str, str], headers: list[str]) bool[source]

Apply filter to a row of data.

Parameters:
  • row_data – List of values (one per column)

  • filter_dict – Filter conditions {“field”: “operator value”}

  • headers – List of field/column names

Returns:

True if row matches filter (should be included), False if filtered out

filter_rows(rows_data: list[list[Any]], filter_dict: dict[str, str], headers: list[str]) list[list[Any]][source]

Apply filter to multiple rows.

Parameters:
  • rows_data – List of rows, each a list of values

  • filter_dict – Filter conditions

  • headers – Column/field names

Returns:

Filtered list of rows (matching filter)

filter_rows_with_count(rows_data: list[list[Any]], filter_dict: dict[str, str], headers: list[str]) tuple[list[list[Any]], int][source]

Apply filter and return both results and original count.

Parameters:
  • rows_data – List of rows

  • filter_dict – Filter conditions

  • headers – Column/field names

Returns:

Tuple of (filtered_rows, original_count)

Classes

FilterMatcher

class filter_matcher.FilterMatcher[source]

Bases: object

Wrapper around sendMail.filter() for filter matching.

__init__() None[source]
is_available() bool[source]

Check if sendMail.filter is available.

match_row(row_data: list[Any], filter_dict: dict[str, str], headers: list[str]) bool[source]

Apply filter to a row of data.

Parameters:
  • row_data – List of values (one per column)

  • filter_dict – Filter conditions {“field”: “operator value”}

  • headers – List of field/column names

Returns:

True if row matches filter (should be included), False if filtered out

filter_rows(rows_data: list[list[Any]], filter_dict: dict[str, str], headers: list[str]) list[list[Any]][source]

Apply filter to multiple rows.

Parameters:
  • rows_data – List of rows, each a list of values

  • filter_dict – Filter conditions

  • headers – Column/field names

Returns:

Filtered list of rows (matching filter)

filter_rows_with_count(rows_data: list[list[Any]], filter_dict: dict[str, str], headers: list[str]) tuple[list[list[Any]], int][source]

Apply filter and return both results and original count.

Parameters:
  • rows_data – List of rows

  • filter_dict – Filter conditions

  • headers – Column/field names

Returns:

Tuple of (filtered_rows, original_count)

Usage Examples

Single row filtering

Check if a single row matches filter criteria:

from filter_matcher import FilterMatcher

matcher = FilterMatcher()

# Headers and row data
headers = ['id', 'name', 'email', 'status']
row = [1, 'John', 'john@example.com', 'active']

# Filter (field -> "operator value")
filter_dict = {'status': 'is active', 'email': 'is not empty'}

# Returns True if row matches (should be INCLUDED)
if matcher.match_row(row, filter_dict, headers):
    print("Row matches filter")
else:
    print("Row filtered out")

Multiple rows filtering

Filter a dataset to show preview:

rows = [
    [1, 'John', 'john@example.com', 'active'],
    [2, 'Jane', 'jane@example.com', 'inactive'],
    [3, 'Bob', 'bob@example.com', 'active'],
]

filtered = matcher.filter_rows(rows, filter_dict, headers)
print(f"Matched {len(filtered)} of {len(rows)} rows")

Get filter results with count

Get both filtered results and original count for statistics:

filtered, total = matcher.filter_rows_with_count(
    rows, filter_dict, headers
)
print(f"Selected {len(filtered)} of {total} subscribers")