Parliamentary Commissions

Swiss Parliament: Commissions

The Federal Chancellery maintains data on the Swiss political system. The curia dataset is publicly available 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
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import warnings

from plotly.subplots import make_subplots
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.

Political Parties

In [4]:
query = """
SELECT ?council ?faction (COUNT(?mep) AS ?members)

  	VALUES ?_council { <> <> <>}
	?mep a schema:Person;
         schema:memberOf/schema:memberOf ?_council;
                        schema:memberOf ?role.
   FILTER NOT EXISTS { ?role schema:endDate ?end }
   ?role schema:memberOf ?_faction.
   ?_faction a <>;
             schema:name ?faction.
   ?_council schema:name ?council.
   FILTER (lang(?council) = 'de')
   FILTER (lang(?faction) = 'de')
GROUP BY ?council ?faction
ORDER BY DESC(?council) DESC (?members)

df = sparql.send_query(query)
In [5]:
cmap = plt.get_cmap('YlOrRd')
colors = [mcolors.rgb2hex(cmap((i+1)/N_FACTIONS)) for i in range(N_FACTIONS)]
factions = [
     "Grünliberale Fraktion",
     "Grüne Fraktion",
     "Die Mitte-Fraktion. Die Mitte. EVP.",
     "Sozialdemokratische Fraktion",
     "FDP-Liberale Fraktion",
     "Fraktion der Schweizerischen Volkspartei"
colormap = dict(zip(factions,colors))

fig = make_subplots(rows=1, cols=3, subplot_titles=df["council"].unique(), specs=[[{"type": "pie"}, {"type": "pie"}, {"type": "pie"}]])
for i, council in enumerate(df["council"].unique()):

     members = dict(zip(df[df.council == council]["faction"],df[df.council == council]["members"]))

          values=[members[f] if f in members else 0 for f in factions],
          labels=factions, sort=False
          ), row=1, col=i+1)
     fig.update_traces(textinfo='none', marker={"colors": [colormap[f] for f in factions]})

fig.update_layout(height=400, title={"text": "Members of Parliament (as of today)", "x": 0.5})