from typing import List
from typing import Dict
from typing import Any
from typing import Optional


def get_entity(entity_id: str, entities: List[Dict[str, Any]]) -> Dict:
    """
    Retrieves entity from list of entities given the entity id.

    Parameters
    ----------
    entity_id: String identifier of the relevant entity.
    entities: List of entities

    Returns
    -------
    Entity from entity list with matching entity id

    """
    entity: Optional[Dict] = next((x for x in entities if x['id'] == entity_id), None)
    if entity:
        return entity
    else:
        raise Exception(f'The entity_id {entity_id} was not found in:\n {entities}')