def _get_python_preamble(code: list, start_index: int = 0) -> int:
    """Returns the python preamble (the part before variables can be written)
    Arguments:
        code: the list of code lines
        start_index: the starting index to begin processing
    Returns:
        Returns the ending index of the preamble
    """
    # We disable this pylint check that would decrease readability
    # pylint: disable=too-many-nested-blocks, too-many-branches
    # We skip over blank lines, imports, comments, and docstrings
    num_lines = len(code)
    cur_line_idx = start_index
    in_docstring = False
    while cur_line_idx < num_lines:
        cur_line = code[cur_line_idx].strip()
        if in_docstring:
            cur_line_idx += 1
            if cur_line.count('"""') % 2 == 1:
                in_docstring = False
        elif len(cur_line) == 0:
            cur_line_idx += 1
        else:
            have_special = False
            for special_start in ['from', 'import']:
                if cur_line.startswith(special_start):
                    have_special = True
                    break
            if have_special is True:
                cur_line_idx += 1
            elif cur_line.startswith('def') or cur_line.startswith('class'):
                # We are done, check if we need to back up some rows
                if cur_line_idx > start_index:
                    while True:
                        cur_line_idx -= 1
                        cur_line = code[cur_line_idx].strip()
                        if len(cur_line) <= 0 or cur_line[0] != '#':
                            break
                    break
            else:
                in_docstring = cur_line.count('"""') % 2 == 1
                cur_line_idx += 1

    return cur_line_idx