A Python implementation of common apportionment methods
This is a collection of common apportionment methods. Apportionment has two main applications: to assign a fixed number of parliamentary seats to parties (proportionally to their vote count), and to assign representatives in a senate to states (proportionally to their population count). A recommendable overview of apportionment methods can be found in the book "Fair Representation" by Balinski and Young [2].
The following apportionment methods are implemented:
- the largest remainder method (or Hamilton method)
- the class of divisor methods including
- D'Hondt (or Jefferson)
- Sainte-Laguë (or Webster)
- Modified Sainte-Laguë (as used e.g. in Norway)
- Huntington-Hill
- Adams
- the quota method [1]
This module supports Python 3.7+.
Installation
Using pip:
pip install apportionment
Latest development version from source:
git clone https://github.com/martinlackner/abcvoting/
python setup.py install
Requirements:
- Python 3.7+
- numpy
A simple example
The following example calculates the seat distribution of Austrian representatives in the European Parliament based on the D'Hondt method and the 2019 election results. Parties that received less than 4% are excluded from obtaining seats and are thus excluded in the calculation.
import apportionment.methods as app
parties = ['OEVP', 'SPOE', 'FPOE', 'GRUENE', 'NEOS']
votes = [1305956, 903151, 650114, 532193, 319024]
seats = 18
app.compute("dhondt", votes, seats, parties, verbose=True)
The output is
D'Hondt (Jefferson) method
OEVP: 7
SPOE: 5
FPOE: 3
GRUENE: 2
NEOS: 1
which is indeed the official result.
Another example can be found in apportionment/examples/simple.py. We verify results from recent Austrian National Council elections in apportionment/examples/austria.py and from recent elections of the Israeli Knesset in apportionment/examples/israel.py.
References
[1] Balinski, M. L., & Young, H. P. (1975). The quota method of apportionment. The American Mathematical Monthly, 82(7), 701-730.
[2] Balinski, M. L., & Young, H. P. (1982). Fair Representation: Meeting the Ideal of One Man, One Vote. Yale University Press, 1982. (There is a second edition from 2001 by Brookings Institution Press.)
Metadata
Release files for apportionment 1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| apportionment-1.0-py3-none-any.whl | Python 3 | none | any | Details for apportionment-1.0-py3-none-any.whl |
Release files / apportionment-1.0-py3-none-any.whl
| Download URL | apportionment-1.0-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9a8bb1e8a3b4d94002f4a36552810ec2bc1e8e5f32a4582874743ef017575f1e
|
|
BLAKE2b-256 checksum How to use checksums |
ac184781cea71cb197f62dc8c0d8d34853c7fe3a9689b81d566cfdc0593bccb4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
|
Security for apportionment 1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.