Parse bank PDF statements for bank operations.

SberParser

Designed to parse lines from Sberbank PDF statements and convert them into Operation objects.

is_operation classmethod

is_operation(str_: str) -> bool

Use to filter strings that conform to the expected format of a bank transaction.

Parameters:
  • str_ (str) –

    The string to check.

Returns:
  • bool –

    True if the string starts with a date in the format DD.MM.YYYY,

  • bool –

    otherwise False.

Example
    print(cls.is_operation("12.03.2024 14:22 456789 КАФЕ +100.00 12345.67"))
    #> True
    print(cls.is_operation("Some random text without a date"))
    #> False

parse_main_line classmethod

parse_main_line(str_: str) -> Operation | None

Parse a line into an Operation object if it matches the pattern.

Parameters:
  • str_ (str) –

    A line from a PDF statement that may contain information.

Returns:
  • Operation | None –

    An Operation object if the line matches the pattern, otherwise None.

Example
    line = "12.03.2024 14:22 456789 КАФЕ +100.00 12345.67"
    parser = SberParser()
    operation = parser.parse_main_line(line)
    print(operation.date)
    #> datetime.date(2024, 3, 12)

parse_lines classmethod

parse_lines(str_: str | list[str]) -> list

Parse a list of strings or a single string into a list of Operation objects.

Skip lines that do not match the expected format of a bank operation.

Parameters:
  • str_ (str | list[str]) –

    A single string or a list of strings from a PDF statement.

Returns:
  • list –

    A list of Operation objects created from matching lines.

Example
    lines = "
    12.03.2024 14:22 456789 КАФЕ +100.00 12345.67\n
    Некорректная строка\n
    13.03.2024 15:30 123456 МАГАЗИН -200.00 12145.67
    "
    parser = SberParser()
    operations = parser.parse_lines(lines)
    print(len(operations))
    #> 2