from typing import Optional
import ast


def str_to_dict(string: str) -> Optional[dict]:
    """Convert dictionary-friendly string to python dict.

    Args:
        string: string which may contain dictionary.

    Returns:
        Python dict if conversion is possible, None otherwise.
    """
    try:
        return ast.literal_eval(string)
    except (ValueError, SyntaxError):
        return None