swissparlpy

PyPI Version Build Status Code style: black

swissparlpy is a Python module that provides easy access to the data of the OData webservice of the Swiss Parliament, the OpenParlData.ch REST API and the Gever (Geschäftsverwaltungssystem) APIs of the canton and the city of Zurich.

swissparlpy


Quick Start

Current release: 2.1.0 – requires Python 3.10 or higher. See the changelog for all changes.

pip install swissparlpy
import swissparlpy as spp

# List available tables
tables = spp.get_tables()
print(tables[:5])
# ['MemberParty', 'Party', 'Person', 'PersonAddress', 'PersonCommunication']

# Get data from a table
councillors = spp.get_data('MemberCouncil', Language='DE', CantonAbbreviation='ZH')
for c in councillors[:10]:
    print(f"{c['FirstName']} {c['LastName']}")

Features

  • Multiple backends – Use the official parlament.ch OData API, the OpenParlData.ch REST API or the Gever APIs of the canton and the city of Zurich
  • Simple API – Intuitive functions to list tables, inspect variables, and query data
  • Filtering – Filter data by any field, substring, date range, or advanced OData filter expressions
  • Pagination – Automatically handles large result sets with server-side pagination
  • pandas integration – Convert results directly to a DataFrame with .to_dataframe()
  • Visualization – Plot voting results directly with the optional visualization support

Vizualization of voting results as scoreboard:

Voting visualization example with scoreboard


Credits

This library is inspired by the R package swissparl by David Zumbach. The idea for a Python version was triggered by Ralph Straumann asking on Twitter.

Similar Libraries

Language Library
R zumbov2/swissparl
JavaScript michaelschoenbaechler/swissparl