import requests


def perform_query(query):
    """Performs a SPARQL query to the wikidata endpoint

    Args:
        query: A string containing a functional sparql query

    Returns:
        A json with the response content.
    """

    endpoint_url = "https://query.wikidata.org/sparql"

    try:
        response = requests.get(
            endpoint_url,
            params={"query": query},
            headers={"Accept": "application/sparql-results+json"},
        )
        response.raise_for_status()

    except requests.exceptions.HTTPError as err:
        raise requests.exceptions.HTTPError(err)

    else:
        raw_results = response.json()

        return raw_results