A package containing algorithms for sortition - democratic lotteries.
Project description
sortition-algorithms
A package containing algorithms for sortition - democratic lotteries.
- Github repository: https://github.com/sortitionfoundation/sortition-algorithms/
- Documentation https://sortitionfoundation.github.io/sortition-algorithms/
About
This library implements algorithms for sortition - the random selection of representative citizen panels (also known as citizens' assemblies, juries, or deliberative panels). Unlike simple random sampling, these algorithms use stratified selection to ensure the chosen panel reflects the demographic composition of the broader population.
What is Sortition?
Sortition creates representative groups by randomly selecting people while respecting demographic quotas. For example, if your population is 52% women and 48% men, sortition ensures your panel maintains similar proportions rather than risking an all-male or all-female selection through pure chance.
Key Features
- Stratified Random Selection: Respects demographic quotas while maintaining randomness
- Household Diversity: Optional address checking to ensure geographic and household spread
- Multiple Algorithms: Choose from maximin, leximin, nash, or legacy selection methods
- Flexible Data Sources: Works with CSV files, Google Sheets, or direct Python data structures
- Transparency: Detailed reporting of selection process and quota fulfillment
Quick Example
from sortition_algorithms import run_stratification, read_in_features, read_in_people, Settings
# Load your data
features = read_in_features("demographics.csv") # Age, Gender, Location quotas
people = read_in_people("candidates.csv", Settings(), features)
# Select a representative panel of 100 people
success, selected_panels, messages = run_stratification(
features, people, number_people_wanted=100, settings=Settings()
)
if success:
panel = selected_panels[0] # Set of selected person IDs
print(f"Selected {len(panel)} people for the panel")
Research Background
The algorithms are described in this paper (open access). Other relevant papers are linked to from the docs
Installing the library
pip install sortition-algorithms
(Or uv add ... or ...)
Optional dependencies
There are two sets of optional dependencies:
# Install the library to use the leximin algorithm
# This requires a commercial/academic license to use
pip install 'sortition-algorithms[gurobi]'
# Install the basic Command Line Interface
pip install 'sortition-algorithms[cli]'
The Command Line Interface
The library includes a CLI for common operations:
# CSV workflow
python -m sortition_algorithms csv \
--settings config.toml \
--features-csv demographics.csv \
--people-csv candidates.csv \
--selected-csv selected.csv \
--remaining-csv remaining.csv \
--number-wanted 100
Documentation
For detailed usage instructions, API reference, and advanced examples:
- Quick Start Guide - Get up and running quickly
- Core Concepts - Understand sortition and stratified selection
- API Reference - Complete function documentation
- CLI Usage - Command line interface examples
- Data Adapters - Working with CSV, Google Sheets, and custom data sources
Starting Development
Prerequisites
The recommended prerequisites are:
Set Up
To install a virtualenv with the required dependencies and set up pre-commit hooks:
just install
Get going
# run all the tests
just test
# run all the tests that aren't slow
just test
# run all the code quality checks
just check
The CI/CD pipeline will be triggered when you open a pull request, merge to main, or when you create a new release.
To enable the code coverage reports, see here.
Releasing a new version
- Create an API Token on PyPI.
- Add the API Token to your projects secrets with the name
PYPI_TOKENby visiting this page. - Create a new release on Github.
- Create a new tag in the form
*.*.*.
For more details, see here.
Repository initiated with fpgmaas/cookiecutter-uv.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sortition_algorithms-0.10.3.tar.gz.
File metadata
- Download URL: sortition_algorithms-0.10.3.tar.gz
- Upload date:
- Size: 157.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3cff4d3ab3f18c8420ee83fca2713dad1641e08145338ace629d69dcc15fd12b
|
|
| MD5 |
99e25d0dc64d45cd64cd89124516b676
|
|
| BLAKE2b-256 |
d2259a1d9c88d97e52669051c5fda54478e6627e416616ee7bcf70383b9397a6
|
File details
Details for the file sortition_algorithms-0.10.3-py3-none-any.whl.
File metadata
- Download URL: sortition_algorithms-0.10.3-py3-none-any.whl
- Upload date:
- Size: 63.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5cd06a6d38381bbdab793ce48a4b3aa17279f776b4ac85d3b1d62b7fb042c26
|
|
| MD5 |
470f09da4d0eacbfb9f5aee6bf84a919
|
|
| BLAKE2b-256 |
98aacef44e60b516ea7e90cefd58f962786036542364aa05f49aa262818c5d1b
|