import requests


def get_target_chemblid(target_upid):
    """Get ChEMBL ID from UniProt upid

    Parameters
    ----------
    target_upid : str

    Returns
    -------
    target_chembl_id : str
    """
    url = 'https://www.ebi.ac.uk/chembl/api/data/target.json'
    params = {'target_components__accession': target_upid}
    r = requests.get(url, params=params)
    r.raise_for_status()
    js = r.json()
    target_chemblid = js['targets'][0]['target_chembl_id']
    return target_chemblid