Skip to main content

Library to perform STV Poll calculations. The package was created as part of the VoteIT project, specifically to handle larger elections that was hard to count with Markus Schulzes STV method.

Typical usage would be primary elections or elections with many winners from a pool of many candidates. The result will be proportional.

Fully supported:

  • Scottish STV

  • Instant-Runoff Voting (IRV)

Mostly working:

  • CPO STV (Do not use for polls with too many possible outcomes)

Python versions

Tested on python 3.10 through 3.13.

Example

Case from: https://en.wikipedia.org/wiki/Single_transferable_vote

from stvpoll.scottish_stv import calculate_scottish_stv

candidates = ('orange', 'chocolate', 'pear', 'strawberry', 'bonbon')
# votes can be collections.Counter, dict or list of tuples with candidates and vote count
ballots = {
    ('orange'): 4,
    ('pear', 'orange'): 2,
    ('chocolate', 'strawberry'): 8,
    ('chocolate', 'bonbon'): 4,
    ('strawberry',): 1,
    ('bonbon',): 1,
}

result = calculate_scottish_stv(
    candidates=candidates,
    ballots=ballots,
    winners=3,
)

This will return a ElectionResult object that contains the result and some useful metadata.

Each ballot is a list of candidates in order of preference, so: [‘pear’, ‘orange’] means ‘pear’ before ‘orange’ etc.

Count is the number of ballots with those exact preferences. In the above example, 4 people voted for only ‘orange’, two people voted for ‘pear’ and then ‘orange, and so on.

result.elected_as_tuple()
('chocolate', 'orange', 'strawberry')

Code & Contributions

You may fork the code at: https://github.com/VoteIT/STVPoll

Please report any bugs there, or email info@voteit.se

Metadata

Release files for STVPoll 0.5.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for STVPoll 0.5.6
File Interpreter ABI Platform
stvpoll-0.5.6-py3-none-any.whl Python 3 none any Details

Release files / stvpoll-0.5.6-py3-none-any.whl

Download URL stvpoll-0.5.6-py3-none-any.whl
Size 21.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ed2c05782381ef9fc3c90f832858eb4541a7c390144a74f76eaa9a3fb715a97f
BLAKE2b-256 checksum
How to use checksums
ec1ecbd2a23428f1b52bb392ecaca4fc7d2713ddad4eb44b98267572784cc052
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.5.6 This release

1 release file

0.5.5

1 release file

0.5.4

1 release file

0.5.3

1 release file

0.5.2

1 release file

0.5.1

1 release file

0.5.0

1 release file

0.4.7

1 release file

0.4.6

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.2.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page