import requests


def get_uniprot_from_ensembl(ensp_id):
    """Return Uniprot ID given Ensembl Protein ID

    Parameters
    ----------
    ensp_id : str
        Ensembl Protein ID

    Returns
    -------
    uniprot_id : str
       Uniprot_Id
    """
    url = "http://grch37.rest.ensembl.org/xrefs/id/"
    query = "%s?content-type=application/json;" % ensp_id
    db = "external_db=Uniprot/SWISSPROT"

    r = requests.get(url + query + db)
    dict = r.json()
    try:
        uniprot_id = dict[0]['primary_id']
    except IndexError:
        uniprot_id = None
    except KeyError:
        uniprot_id = None
    return uniprot_id