from typing import Iterable
from typing import Dict
from typing import Any


def pb_obj2dict(obj, keys: Iterable[str]) -> Dict[str, Any]:
    """Convert a protobuf object to a Dict by selected keys

    :param obj: a protobuf object
    :param keys: an iterable of keys for extraction
    """
    return {k: getattr(obj, k) for k in keys if hasattr(obj, k)}