Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

STV polling methods

Project description


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

Work in progress:



Case from:

from stvpoll.scottish_stv import ScottishSTV

example_ballots = (
    (('orange',), 4),
    (('pear', 'orange',), 2),
    (('chocolate', 'strawberry',), 8),
    (('chocolate', 'bonbon',), 4),
    (('strawberry',), 1),
    (('bonbon',), 1),

poll = ScottishSTV(seats=3, candidates=('orange', 'chocolate', 'pear', 'strawberry', 'bonbon'))
for (candidates, bcount) in example_ballots:
    poll.add_ballot(candidates, bcount)

result = poll.calculate()

This will return a ElectionResult object that contains the result and some useful metadata. The elected attribute contains the elected candidates.

Candidates to the left have higher preference, so: [‘pear’, ‘orange’] means ‘pear’ before ‘orange’ etc. The number is how many of that kind of ballot there is.

[<Candidate: chocolate>, <Candidate: orange>, <Candidate: strawberry>]

Code & Contributions

You may fork the code at:

Please report any bugs there, or email


0.2.0 (dev)

  • Fixed bug in deciding which vote to transfer first when multiple elected in Scottish STV. [schyffel] [robinharms]
  • Scottish STV: Resolve ties so that winners are always in correct ranking order (extreme case). [schyffel]
  • Now works on Python 3. [schyffel]
  • Test coverage 100 %. [schyffel]

0.1.4 (2018-05-12)

  • Fixed a situation where primary_candidate in rounds didn’t exist. [schyffel] [robinharms]

0.1.3 (2018-03-22)

  • Excluded empty ballots, so that they do not affect the quota. [schyffel]

0.1.2 (2017-11-24)

  • Fixed exception on empty ballots. [schyffel]

0.1.1 (2017-11-24)

  • Fixed case where randomization caused an exception. [schyffel]

0.1.0 (2017-11-03)

  • Initial version

Project details

Download files

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

Files for STVPoll, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size STVPoll-0.2.0.tar.gz (9.0 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page