Skip to main content

elex-clarity

https://img.shields.io/pypi/v/elex-clarity.svg https://img.shields.io/pypi/pyversions/elex-clarity.svg https://circleci.com/gh/washingtonpost/elex-clarity.svg?style=shield https://img.shields.io/pypi/l/elex-clarity.svg

A CLI tool for pulling in election results from sites using Clarity (the “election night reporting” product described here). This package is hosted on pypi.

Please use the Github issue tracker to submit bugs or request features.

Overview

This library

  • Provides a simple CLI tool for pulling in and formatting election results from a Clarity-backed website or local file

  • Separates data retrieval from data formatting

  • By default, returns results formatted like so

    {
        "2020-11-03_GA_G_P": {
            "id": "2020-11-03_GA_G_P",
            "source": "clarity",
            "precinctsReportingPct": 100.0,
            "counts": {
                "donald_j_trump_i_rep": 2461837,
                "joseph_r_biden_dem": 2474507,
                "jo_jorgensen_lib": 62138
            },
            "office": "P",
            "lastUpdated": "2020-11-20T20:37:06Z",
            "subunits": {
                "appling": {
                    "id": "appling",
                    "counts": {
                        "donald_j_trump_i_rep": 6526,
                        "joseph_r_biden_dem": 1779,
                        "jo_jorgensen_lib": 36
                    }
                },
                ...
            }
        }
    }

Installation

  • Make sure you have python 3.7+ installed

  • Optional: we recommend that you set up a virtualenv and activate it

  • pip install elex-clarity

Usage

All CLI commands require a Clarity election ID and state postal code. For example

elexclarity 105369 GA

The election ID can be found by navigating to the election in question in whichever results site you’re viewing. For example, for Georgia, the Secretary of State’s website links to election results. Following the Current Election Results link you get to a clarity page with many election results pages. Looking at the 2020-current results will lead to https://results.enr.clarityelections.com/GA/105369/web.264614/#/summary, which contains the election ID right after the state postal code.

Other parameters

Title

Name

Description

Type

Required?

Default

style

what broad type of formatting should be done?

one of [default, raw]

N

default

outputType

what specific type of formatting should be done?

one of [results, settings, summary]

N

results

level

what level of data should be fetched/returned?

one of [precinct, county, state]

N

county

countyName

Name of county to get results from if counties have their own pages

string

N

–

officeID

what office ID(s) should be returned?

a comma separated list of office IDs

N

–

countyMapping

an object with race names (as provided via Clarity) mapped to some other identifier that should be used in results formatting. Sample formats can be found in the tests/fixtures folder

object

N

–

voteCompletionMode

the method that should be used to determine whether a precinct is fully reporting

string

N

percentReporting

precinctsReportingPct

a county-level override for the precincts reprting percent that applies to all subunits, given as a mapping between county IDs and percents (does not change the value of the reportingStatus field)

object

N

–

filename

the path to read results from (if you don’t want to ping a Clarity site)

string

N

–

Example invocations

Retrieving raw data:

  • elexclarity 105369 GA --outputType=summary --style=raw

  • elexclarity 105369 GA --outputType=settings --style=raw

  • elexclarity 105369 GA --level=precinct --style=raw

  • elexclarity 106043 CA --countyName Santa_Clara --level=precinct

Retrieving + formatting settings (for presidential races):

  • elexclarity 105369 GA --outputType=settings --officeID=P

Retrieving + formatting results:

  • elexclarity 105369 GA --level=precinct --countyMapping='{"Worth": "13321"}'

  • elexclarity 105369 GA --level=precinct

  • elexclarity 105369 GA --level=precinct --voteCompletionMode=voteTypes

  • elexclarity 105369 GA --level=county

  • elexclarity 106210 WV --level=county --countyMapping='<mapping json>'

  • elexclarity 105369 WV --level=state

Formatting data from a local file:

  • elexclarity 105369 GA --level=precinct --filename="tests/fixtures/results/ga_atkinson_precincts_11-3.xml" --countyMapping='<mapping json>'

  • elexclarity 105369 GA --level=county --filename="tests/fixtures/ga_counties_11-3.xml" --countyMapping='<mapping json>'

Development

  • Clone this repository

  • pip install -r requirements.txt

  • tox

  • You should see some code coverage info and test results

  • If the above was successful, you are ready for development

Releasing a New Version

In preparation for a new release:

  • Decide what the next version will be per semantic versioning

  • Make a new branch named release/<version number>

  • Update the changelog with all changes that will be included in the release

  • Commit your changes and make a PR against main

  • Once the changes are merged, tag main (or develop for a beta release) with the release’s version number and push that tag (git push --tags)

  • Merge main into develop

Metadata

Release files for elex-clarity 0.0.9

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

Source distribution (sdist)

Source distribution for elex-clarity 0.0.9
File Size Uploaded Provenance Actions
elex-clarity-0.0.9.tar.gz 13.8 kB Without provenance Details for elex-clarity-0.0.9.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for elex-clarity 0.0.9
File Interpreter ABI Platform Actions
elex_clarity-0.0.9-py3.7.egg Legacy Egg format - - Details for elex_clarity-0.0.9-py3.7.egg
elex_clarity-0.0.9-py2.py3-none-any.whl Python 3, Python 2 none any Details for elex_clarity-0.0.9-py2.py3-none-any.whl

Total release size: 61.7 kB

Release files / elex-clarity-0.0.9.tar.gz

Download URL elex-clarity-0.0.9.tar.gz
Size 13.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8e6fd4efda3c1b6977600de1696e7219444735108bb7880152a6a982e4c7b390
BLAKE2b-256 checksum
How to use checksums
15831efb6e67d079e0c147f8b5893ea9f9cdbd11fdeffe8972c28066415a4918
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.12

Release files / elex_clarity-0.0.9-py3.7.egg

Download URL elex_clarity-0.0.9-py3.7.egg
Size 31.4 kB
Tags Egg
SHA-256 checksum
How to use checksums
8aa4ef57892874df38729d21011d4cbc18038ead12f6ba014831a5bed84922ad
BLAKE2b-256 checksum
How to use checksums
79e43f100dac478061e1c213ec91a77be324afeac86ba136449d299efbeebf71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.12

Release files / elex_clarity-0.0.9-py2.py3-none-any.whl

Download URL elex_clarity-0.0.9-py2.py3-none-any.whl
Size 16.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
501760e8014cfe19d77135c241aebcfe41ffea0505fb40d40f3279551765b392
BLAKE2b-256 checksum
How to use checksums
66264e599072788b1a5cf45b66da46011fd651db40e8229f09cc05b03a763625
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.12

Security for elex-clarity 0.0.9

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.

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