Skip to content

filter

This module contains the classes that represent Obsidian filters. Filters are used to search through Obsidian notes. See searchby to understand how filters are used.

A filter is composed of one or more fields, each field having an associated mode. Each field has a key, value, and occurrence.

  • key: The key of the field. Defines which search method will be used. See get_search_strategies for more information.
  • value: The value of the field. Values that will be searched based on the chosen search method
  • occurrence: The occurrence of the field value. Can be 'inline', 'yaml', or 'file'.
    • inline: occurs inline
    • yaml: occurs in yaml
    • file: both inline and yaml

Field(key: FieldKey, value: FieldValue, occurrence: FieldOcurrence)

Represents a filter field.

Parameters:

  • key (FieldKey) –

    The key of the field

  • value (FieldValue) –

    The value of the field

  • occurrence (FieldOcurrence) –

    The occurrence of the field

Source code in pyobsidian/filter.py
39
40
41
42
43
44
45
46
47
def __init__(
    self: Self, 
    key: FieldKey, 
    value: FieldValue, 
    occurrence: FieldOcurrence
) -> None:
    self.__key = key
    self.__value = value
    self.__occurrence = occurrence

key: FieldKey property

The key of the field

occurrence: FieldOcurrence property

The occurrence of the field

value: FieldValue property

The value of the field

Filter(fields: list[FilterField] = [])

Represents a filter for notes.

Parameters:

  • fields (list[FilterField], default: [] ) –

    The list of filter fields

Source code in pyobsidian/filter.py
96
97
def __init__(self: Self, fields: list[FilterField] = []):
    self.__fields = fields

fields: list[FilterField] property

The list of filter fields for the current object.

Returns:

  • list[FilterField]

    The list of filter fields for the current object.

add_field(field: FilterField) -> Filter

Adds a new filter field to the filter and returns a new Filter object.

Parameters:

  • field (FilterField) –

    The filter field to be added.

Returns:

  • Filter

    A new Filter object with the added filter field.

Source code in pyobsidian/filter.py
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
def add_field(self: Self, field: FilterField) -> Filter:
    """Adds a new filter field to the filter and returns a new Filter object.

    Parameters
    ----------
    field : FilterField
        The filter field to be added.

    Returns
    -------
    Filter
        A new Filter object with the added filter field.
    """
    cur_fields = self.fields
    new_fields = cur_fields + [field]
    new_filter = Filter(new_fields)
    return new_filter

FilterField(field: Field, mode: FilterMode) dataclass

Represents a filter field.

Parameters:

  • field (Field) –

    The filter field

  • mode (FilterMode) –

    The mode of the filter