sortition-algorithms 0.9.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sortition_algorithms/__init__.py +22 -0
- sortition_algorithms/__main__.py +229 -0
- sortition_algorithms/adapters.py +308 -0
- sortition_algorithms/committee_generation.py +1377 -0
- sortition_algorithms/core.py +591 -0
- sortition_algorithms/errors.py +26 -0
- sortition_algorithms/features.py +351 -0
- sortition_algorithms/find_sample.py +93 -0
- sortition_algorithms/people.py +175 -0
- sortition_algorithms/people_features.py +288 -0
- sortition_algorithms/settings.py +110 -0
- sortition_algorithms/utils.py +107 -0
- sortition_algorithms-0.9.0.dist-info/METADATA +191 -0
- sortition_algorithms-0.9.0.dist-info/RECORD +17 -0
- sortition_algorithms-0.9.0.dist-info/WHEEL +4 -0
- sortition_algorithms-0.9.0.dist-info/entry_points.txt +2 -0
- sortition_algorithms-0.9.0.dist-info/licenses/LICENSE +674 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sortition-algorithms
|
|
3
|
+
Version: 0.9.0
|
|
4
|
+
Summary: A package containing algorithms for sortition - democratic lotteries.
|
|
5
|
+
Project-URL: Homepage, https://sortitionfoundation.github.io/sortition-algorithms/
|
|
6
|
+
Project-URL: Repository, https://github.com/sortitionfoundation/sortition-algorithms
|
|
7
|
+
Project-URL: Documentation, https://sortitionfoundation.github.io/sortition-algorithms/
|
|
8
|
+
Author-email: Sortition Foundation <hamish@sortitionfoundation.org>
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: python
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
|
+
Requires-Python: <3.13,>=3.11
|
|
18
|
+
Requires-Dist: attrs>=25.3.0
|
|
19
|
+
Requires-Dist: cattrs>=25.1.0
|
|
20
|
+
Requires-Dist: cvxpy>=1.6.5
|
|
21
|
+
Requires-Dist: gspread>=6.2.1
|
|
22
|
+
Requires-Dist: mip==1.15.0
|
|
23
|
+
Requires-Dist: numpy>=2.2.6
|
|
24
|
+
Requires-Dist: oauth2client>=4.1.3
|
|
25
|
+
Provides-Extra: cli
|
|
26
|
+
Requires-Dist: click>=8.2.1; extra == 'cli'
|
|
27
|
+
Provides-Extra: gurobi
|
|
28
|
+
Requires-Dist: gurobipy>=12.0.2; extra == 'gurobi'
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# sortition-algorithms
|
|
32
|
+
|
|
33
|
+
[](https://img.shields.io/github/v/release/sortitionfoundation/sortition-algorithms)
|
|
34
|
+
[](https://github.com/sortitionfoundation/sortition-algorithms/actions/workflows/main.yml?query=branch%3Amain)
|
|
35
|
+
[](https://codecov.io/gh/sortitionfoundation/sortition-algorithms)
|
|
36
|
+
[](https://img.shields.io/github/commit-activity/m/sortitionfoundation/sortition-algorithms)
|
|
37
|
+
[](https://img.shields.io/github/license/sortitionfoundation/sortition-algorithms)
|
|
38
|
+
|
|
39
|
+
A package containing algorithms for sortition - democratic lotteries.
|
|
40
|
+
|
|
41
|
+
- **Github repository**: <https://github.com/sortitionfoundation/sortition-algorithms/>
|
|
42
|
+
- **Documentation** <https://sortitionfoundation.github.io/sortition-algorithms/>
|
|
43
|
+
|
|
44
|
+
## About
|
|
45
|
+
|
|
46
|
+
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.
|
|
47
|
+
|
|
48
|
+
### What is Sortition?
|
|
49
|
+
|
|
50
|
+
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.
|
|
51
|
+
|
|
52
|
+
### Key Features
|
|
53
|
+
|
|
54
|
+
- **Stratified Random Selection**: Respects demographic quotas while maintaining randomness
|
|
55
|
+
- **Household Diversity**: Optional address checking to ensure geographic and household spread
|
|
56
|
+
- **Multiple Algorithms**: Choose from maximin, leximin, nash, or legacy selection methods
|
|
57
|
+
- **Flexible Data Sources**: Works with CSV files, Google Sheets, or direct Python data structures
|
|
58
|
+
- **Transparency**: Detailed reporting of selection process and quota fulfillment
|
|
59
|
+
|
|
60
|
+
### Quick Example
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from sortition_algorithms import run_stratification, read_in_features, read_in_people, Settings
|
|
64
|
+
|
|
65
|
+
# Load your data
|
|
66
|
+
features = read_in_features("demographics.csv") # Age, Gender, Location quotas
|
|
67
|
+
people = read_in_people("candidates.csv", Settings(), features)
|
|
68
|
+
|
|
69
|
+
# Select a representative panel of 100 people
|
|
70
|
+
success, selected_panels, messages = run_stratification(
|
|
71
|
+
features, people, number_people_wanted=100, settings=Settings()
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
if success:
|
|
75
|
+
panel = selected_panels[0] # Set of selected person IDs
|
|
76
|
+
print(f"Selected {len(panel)} people for the panel")
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Research Background
|
|
80
|
+
|
|
81
|
+
The algorithms are described in [this paper (open access)](https://www.nature.com/articles/s41586-021-03788-6).
|
|
82
|
+
|
|
83
|
+
Other relevant papers:
|
|
84
|
+
|
|
85
|
+
- Procaccia et al. [Is Sortition Both Representative and Fair?](https://procaccia.info/wp-content/uploads/2022/06/repfair.pdf)
|
|
86
|
+
- Tiago c Peixoto
|
|
87
|
+
- [Reflections on the representativeness of citizens’ assemblies and similar innovations](https://democracyspot.net/2023/02/22/reflections-on-the-representativeness-of-citizens-assemblies-and-similar-innovations/) and
|
|
88
|
+
- [How representative is it really? A correspondence on sortition](https://www.publicdeliberation.net/how-representative-is-it-really-a-correspondence-on-sortition/)
|
|
89
|
+
|
|
90
|
+
## Installing the library
|
|
91
|
+
|
|
92
|
+
```sh
|
|
93
|
+
pip install sortition-algorithms
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
(Or `uv add ...` or ...)
|
|
97
|
+
|
|
98
|
+
### Optional dependencies
|
|
99
|
+
|
|
100
|
+
There are two sets of optional dependencies:
|
|
101
|
+
|
|
102
|
+
```sh
|
|
103
|
+
# Install the library to use the leximin algorithm
|
|
104
|
+
# This requires a commercial/academic license to use
|
|
105
|
+
pip install 'sortition-algorithms[gurobi]'
|
|
106
|
+
|
|
107
|
+
# Install the basic Command Line Interface
|
|
108
|
+
pip install 'sortition-algorithms[cli]'
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## The Command Line Interface
|
|
112
|
+
|
|
113
|
+
The library includes a CLI for common operations:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
# CSV workflow
|
|
117
|
+
python -m sortition_algorithms csv \
|
|
118
|
+
--settings config.toml \
|
|
119
|
+
--features-csv demographics.csv \
|
|
120
|
+
--people-csv candidates.csv \
|
|
121
|
+
--selected-csv selected.csv \
|
|
122
|
+
--remaining-csv remaining.csv \
|
|
123
|
+
--number-wanted 100
|
|
124
|
+
|
|
125
|
+
# Google Sheets workflow
|
|
126
|
+
python -m sortition_algorithms gsheet \
|
|
127
|
+
--settings config.toml \
|
|
128
|
+
--auth-json-file credentials.json \
|
|
129
|
+
--gsheet-name "Citizen Panel Selection" \
|
|
130
|
+
--number-wanted 100
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Documentation
|
|
134
|
+
|
|
135
|
+
For detailed usage instructions, API reference, and advanced examples:
|
|
136
|
+
|
|
137
|
+
- **[Quick Start Guide](https://sortitionfoundation.github.io/sortition-algorithms/quickstart/)** - Get up and running quickly
|
|
138
|
+
- **[Core Concepts](https://sortitionfoundation.github.io/sortition-algorithms/concepts/)** - Understand sortition and stratified selection
|
|
139
|
+
- **[API Reference](https://sortitionfoundation.github.io/sortition-algorithms/api-reference/)** - Complete function documentation
|
|
140
|
+
- **[CLI Usage](https://sortitionfoundation.github.io/sortition-algorithms/cli/)** - Command line interface examples
|
|
141
|
+
- **[Data Adapters](https://sortitionfoundation.github.io/sortition-algorithms/adapters/)** - Working with CSV, Google Sheets, and custom data sources
|
|
142
|
+
|
|
143
|
+
## Starting Development
|
|
144
|
+
|
|
145
|
+
### Prerequisites
|
|
146
|
+
|
|
147
|
+
The recommended prerequisites are:
|
|
148
|
+
|
|
149
|
+
- [uv](https://docs.astral.sh/uv/getting-started/installation/)
|
|
150
|
+
- [justfile](https://github.com/casey/just?tab=readme-ov-file#installation)
|
|
151
|
+
- [pre-commit](https://pre-commit.com/)
|
|
152
|
+
|
|
153
|
+
### Set Up
|
|
154
|
+
|
|
155
|
+
To install a virtualenv with the required dependencies and set up pre-commit hooks:
|
|
156
|
+
|
|
157
|
+
```sh
|
|
158
|
+
just install
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Get going
|
|
162
|
+
|
|
163
|
+
```sh
|
|
164
|
+
# run all the tests
|
|
165
|
+
just test
|
|
166
|
+
|
|
167
|
+
# run all the tests that aren't slow
|
|
168
|
+
just test
|
|
169
|
+
|
|
170
|
+
# run all the code quality checks
|
|
171
|
+
just check
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
The CI/CD pipeline will be triggered when you open a pull request, merge to main, or when you create a new release.
|
|
175
|
+
|
|
176
|
+
To finalize the set-up for publishing to PyPI, see [here](https://fpgmaas.github.io/cookiecutter-uv/features/publishing/#set-up-for-pypi).
|
|
177
|
+
For activating the automatic documentation with MkDocs, see [here](https://fpgmaas.github.io/cookiecutter-uv/features/mkdocs/#enabling-the-documentation-on-github).
|
|
178
|
+
To enable the code coverage reports, see [here](https://fpgmaas.github.io/cookiecutter-uv/features/codecov/).
|
|
179
|
+
|
|
180
|
+
## Releasing a new version
|
|
181
|
+
|
|
182
|
+
- Create an API Token on [PyPI](https://pypi.org/).
|
|
183
|
+
- Add the API Token to your projects secrets with the name `PYPI_TOKEN` by visiting [this page](https://github.com/sortitionfoundation/sortition-algorithms/settings/secrets/actions/new).
|
|
184
|
+
- Create a [new release](https://github.com/sortitionfoundation/sortition-algorithms/releases/new) on Github.
|
|
185
|
+
- Create a new tag in the form `*.*.*`.
|
|
186
|
+
|
|
187
|
+
For more details, see [here](https://fpgmaas.github.io/cookiecutter-uv/features/cicd/#how-to-trigger-a-release).
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
Repository initiated with [fpgmaas/cookiecutter-uv](https://github.com/fpgmaas/cookiecutter-uv).
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
sortition_algorithms/__init__.py,sha256=2uOa5Hz8fE50x1-oWkF-quK6gKncnCV1kMVzCk3I03o,609
|
|
2
|
+
sortition_algorithms/__main__.py,sha256=KKdGi97C4ozUAb4JrgRo0ZWLL4euG4JXQrC2KTlIjD4,6738
|
|
3
|
+
sortition_algorithms/adapters.py,sha256=pYqXnibZDzahKt5SQQoEc5CNqPlo2KRr4AxCRO7JJR4,12426
|
|
4
|
+
sortition_algorithms/committee_generation.py,sha256=DB2-2aPO9pxkBaqHUJ351jqrikq1s8gophewZf_Ke-s,56969
|
|
5
|
+
sortition_algorithms/core.py,sha256=OrT97X4pOK6Rlx82R0Peaj4oA41gjdBEY1IxPPiqOCc,22038
|
|
6
|
+
sortition_algorithms/errors.py,sha256=Gq5ENu5jmIR2psELfJ1vv3PL9SOemFstwalLeDX9EDc,618
|
|
7
|
+
sortition_algorithms/features.py,sha256=sV6KAOpM8LkPANsyQe1C91i9zbkxHTft3d5KxyOhfZA,13651
|
|
8
|
+
sortition_algorithms/find_sample.py,sha256=J88IRPjnAxZcXOeQLYgAuR5amb4wTPifcBJCmQYZeV8,4183
|
|
9
|
+
sortition_algorithms/people.py,sha256=lyYlhex_UbemqQiRbffaIDNx_v4nrs04Puj48kULur0,7577
|
|
10
|
+
sortition_algorithms/people_features.py,sha256=cqfC9Icy6wxO5ypOWIDfFvnLuUCdWCtIOXVF2lemz3g,12386
|
|
11
|
+
sortition_algorithms/settings.py,sha256=ji86f4t16s5H9UnrQtLt-2uhGgHOERitZxkuX_rjwhA,4191
|
|
12
|
+
sortition_algorithms/utils.py,sha256=nvoKZCD25aZgwymlDDVvCqZQNRRa4fqlxIdUaasm6mo,2968
|
|
13
|
+
sortition_algorithms-0.9.0.dist-info/METADATA,sha256=IzFlWJs9FBHB6peeOmjBZJA4doj1kqFOvM9cxpZjU4s,8312
|
|
14
|
+
sortition_algorithms-0.9.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
15
|
+
sortition_algorithms-0.9.0.dist-info/entry_points.txt,sha256=4KborwJYZ75Od1efKkTlHKZ4XBXEAO_2S7QwnVd-dQs,64
|
|
16
|
+
sortition_algorithms-0.9.0.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
17
|
+
sortition_algorithms-0.9.0.dist-info/RECORD,,
|