Members of Parliament

Swiss Parliament: Members

The Federal Chancellery maintains data on the Swiss political system. The curia dataset is publicly available and it provides data on political parties, parliamentary comissions, members of parliament and their affiliations.

Parliament data is also available as Linked Data.


SPARQL endpoint

Swiss political data can be accessed with SPARQL queries.
You can send queries using HTTP requests. The API endpoint is

SPARQL client

We will use the SparqlClient from graphly to communicate with the database. Graphly will allow us to:

  • send SPARQL queries
  • automatically add prefixes to all queries
  • format response to pandas or geopandas
In [1]:
import pandas as pd
import as px
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import datetime
import warnings

from graphly.api_client import SparqlClient

%matplotlib inline
pd.set_option('display.max_rows', 100)
In [2]:
# Uncomment to install dependencies in Colab environment
#!pip install git+
In [3]:
sparql = SparqlClient("")

    "schema": "<>"

SPARQL queries can become very long. To improve the readibility, we will work wih prefixes.

Using the add_prefixes method, we can define persistent prefixes. Every time you send a query, graphly will now automatically add the prefixes for you.

MEP by gender, age and chamber

In [4]:
query = """
SELECT ?council ?name ?gender ?age ?start
  VALUES ?_council {<> <>}
  ?member a schema:Person ;
         schema:name ?name;
         schema:gender ?gender;
         schema:birthDate ?birthday;
         schema:memberOf ?role.
  ?role a schema:Role;
        schema:member ?member;
        schema:startDate ?start;
        schema:memberOf ?_council.
  ?_council schema:name ?council.
  FILTER (lang(?council) = "de")
  FILTER NOT EXISTS { ?role schema:endDate ?end }
  BIND( "2022-06-16"^^<> as ?today )
  BIND(YEAR(?today)-YEAR(?birthday) as ?age)

df = sparql.send_query(query)
df = df.replace({"": "Male", "": "Female"})
In [5]:
df["bucket"] = df.age.apply(lambda x: "{}-{}".format((x//bucket)*bucket, (x//bucket+1)*bucket))
counts = df.groupby(["bucket", "gender"]).size().reset_index(name='count')

fig =, x="bucket", y="count", color="gender",
             barmode="stack", color_discrete_sequence=[px.colors.qualitative.Plotly[1],px.colors.qualitative.Plotly[0]])

    title='Members of Parliament (as of today)', 
    yaxis_title="Share in %",