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 and the OpenParlData.ch REST API.

swissparlpy


Quick Start

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', limit=10)
for c in councillors:
    print(c['LastName'], c['FirstName'])

Features

  • Multiple backends – Use the official parlament.ch OData API or the OpenParlData.ch REST API
  • 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