Skip to main content

Python library for biproportional and other apportionment methods.

Project description

Biprop - A Python Library for Calculating Biproportional Apportionments

[!CAUTION] DO NOT use this repository to calculate the official results of actual elections! The code in this repository was not formally verified and might not always deliver correct results or terminate.

Welcome to the biprop library. This library is meant for election enthusiats and statistics nerds like me who want to ask questions like

How would the parliament of country X look like if they used biproportional apportionment in their last election?

or

How would the apportionment change if party Y and Z ran together as one and if we introduced a quorum that parties have to fulfill?

The biprop library contains all the tools you need to answer these questions and more.

Installation

You can install biprop with pip using

pip install biprop

Basic Usage

To demonstrate the basic usage of the biprop library, we will replicate the calculations from the example from this Wikipedia article. We start with importing the biprop library and defining the votes, region and party names from the example:

>>> import biprop as bp
>>> party_names = ['A', 'B', 'C']
>>> region_names = ['I', 'II', 'III']
>>> votes = [[123,  45, 815],
...          [912, 714, 414],
...          [312, 255, 215]]

Now we can use the votes to define an election and calculate the upper and lower apportionments:

>>> e = bp.Election(votes, party_names=party_names, region_names=region_names, total_seats=20)
>>> e.upper_apportionment(which='parties')
array([ 5, 11,  4])
>>> e.upper_apportionment(which='regions')
array([7, 5, 8])
>>> e.lower_apportionment()
Lower apportionment converged after 2 iterations.
array([[1, 0, 4],
       [4, 4, 3],
       [2, 1, 1]])

We indeed arrive at the same seat distribution as the example in the Wikipedia article. You can find more usage examples and more detailed explanations in the Examples directory of the project's GitHub page.

Examples and Tutorial

You can find practical examples and detailed explanations in the tutorial iPython notebooks in the Examples directory of the project's GitHub page. The tutorials are still being worked on and are not yet complete.

Version 0

[!WARNING] Version 0.1.0 is outdated and is not maintained anymore. Users still using this version are encouraged to migrate to version 1.x.x.

If you still need access to the version 0.1.0, you can find the code for it in the v0 directory. This directory includes the biprop.py module which implements the version 0.1.0. It also contains an example.py module that uses the 2019 and 2023 Swiss National Council Elections to demonstrate how to use biprop.py.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

biprop-1.0.4.tar.gz (33.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

biprop-1.0.4-py3-none-any.whl (35.1 kB view details)

Uploaded Python 3

File details

Details for the file biprop-1.0.4.tar.gz.

File metadata

  • Download URL: biprop-1.0.4.tar.gz
  • Upload date:
  • Size: 33.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for biprop-1.0.4.tar.gz
Algorithm Hash digest
SHA256 8ee7f6ab636c0917465df20ca0e67186325312ea4238cdd0e89488060d557514
MD5 2c9e09b2d1e9132065e71b61943b3912
BLAKE2b-256 40f246f6c2209b52db2dbbc14f505cb685a02185cbc0cb2c778035e84b904308

See more details on using hashes here.

File details

Details for the file biprop-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: biprop-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 35.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for biprop-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3e20b68546787202165e1fc4ffe8695c53facf2d2f843fe34cef24b223f031ae
MD5 731c1348c6159eb6a7420f6253b924d0
BLAKE2b-256 9bcb9968fc4bd52d9f43aa2d356a27176ad4147341c573e68e43a9a64d6d1a52

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page