Skip to main content

U.S. election and government metadata

Project description

POLITICO

us-elections 🇺🇸

A package for working with US elections metadata. Like python-us, but for elections!

PyPI version

Quickstart

$ pip install us-elections

Exploring election data

from elections import ElectionYear


# GET A SPECIFIC YEAR'S ELECTIONS AND DATA:
election_year = ElectionYear(2020)
election_year
# <ElectionYear: 2020 (Presidential cycle)>


# GET ELECTIONS IN THIS YEAR:
election_year.elections
# [
#   <DemocraticPrimaryElection: Iowa (Feb. 03, 2020)>,
#   <RepublicanPrimaryElection: Iowa (Feb. 03, 2020)>,
#   ...
#   <GeneralElection: Alabama Nov. 03, 2020>,
#   <GeneralElection: Alaska Nov. 03, 2020>,
#   ...
# ]

election_year.elections.primaries
# [
#   <DemocraticPrimaryElection: Iowa (Feb. 03, 2020)>,
#   <RepublicanPrimaryElection: Iowa (Feb. 03, 2020)>,
#   <DemocraticPrimaryElection: New Hampshire (Feb. 11, 2020)>,
#   <RepublicanPrimaryElection: New Hampshire (Feb. 11, 2020)>,
#   ...
# ]

election_year.elections.primaries.republican
# [
#   <RepublicanPrimaryElection: Iowa (Feb. 03, 2020)>,
#   <RepublicanPrimaryElection: New Hampshire (Feb. 11, 2020)>,
#   <RepublicanPrimaryElection: Alabama (Mar. 03, 2020)>,
#   <RepublicanPrimaryElection: Arkansas (Mar. 03, 2020)>,
#   ...
# ]

election_year.elections.general_elections
# [
#   <GeneralElection: Alabama (Nov. 03, 2020)>,
#   <GeneralElection: Alaska (Nov. 03, 2020)>,
#   <GeneralElection: Arizona (Nov. 03, 2020)>,
#   <GeneralElection: Arkansas (Nov. 03, 2020)>,
#   ...
# ]


# You can also filter by type of primary:

# election_year.elections.presidential_primaries
# election_year.elections.presidential_primaries.democratic
# election_year.elections.downticket_primaries
# election_year.elections.downticket_primaries.republican


# GET GOVERNMENTS BY LEVEL:
election_year.federal
# <FederalGovernment: United States of America>

election_year.states
# [
#   <StateGovernment: Alabama>,
#   <StateGovernment: Alaska>,
#   <StateGovernment: Arizona>,
#   <StateGovernment: Arkansas>,
#   ...
# ]

election_year.states.alabama
# <StateGovernment: Alabama>

election_year.states.new_jersey
# <StateGovernment: New Jersey>


# GET A BRANCH WITHIN A GOVERNMENT:
election_year.federal.legislative
# <LegislativeBranch: U.S. Congress>

election_year.states.delaware.executive
# <ExecutiveBranch: Delaware>


# GET SEATS UP FOR ELECTION:
election_year.federal.legislative.seats
# [
#   <HouseSeat: Alaska U.S. House seat, at-large district>,
#   ...
#   <SenateSeat: Alaska U.S. Senate seat, class II>,
#   ...
# ]

election_year.states.delaware.executive.seats
# [
#   <ExecutiveSeat: Delaware Governor>,
#   <ExecutiveSeat: Delaware Lieutenant Governor>,
#   ...
# ]


# GET SEATS FROM A SPECIFIC LEGISLATIVE CHAMBER:
election_year.federal.legislative.seats.senate
# [
#   <SenateSeat: Alabama U.S. Senate seat, class II>,
#   <SenateSeat: Alaska U.S. Senate seat, class II>,
#   <SenateSeat: Arizona U.S. Senate seat, class III>,
#   <SenateSeat: Arkansas U.S. Senate seat, class II>,
#   ...
# ]

election_year.federal.legislative.seats.house
# [
#   <HouseSeat: Alaska U.S. House seat, at-large district>,
#   <HouseSeat: Alabama U.S. House seat, 1st district>,
#   <HouseSeat: Alabama U.S. House seat, 2nd district>,
#   <HouseSeat: Alabama U.S. House seat, 3rd district>,
#   ...
# ]


# FILTER BY STATE:
election_year.elections_for_state('TX')
# [
#   <DemocraticPrimaryElection: Texas (Mar. 03, 2020)>,
#   <RepublicanPrimaryElection: Texas (Mar. 03, 2020)>,
#   <GeneralElection: Texas (Nov. 03, 2020)>
# ]

election_year.federal.legislative.seats_for_state('TX')
# [
#   <SenateSeat: Texas U.S. Senate seat, class II>,
#   <HouseSeat: Texas U.S. House seat, 1st district>,
#   <HouseSeat: Texas U.S. House seat, 2nd district>,
#   <HouseSeat: Texas U.S. House seat, 3rd district>,
#   ...
# ]

election_year.federal.legislative.seats_for_state('GA').senate
# [
#   <SenateSeat: Georgia U.S. Senate seat, class II>,
#   <SenateSeat: Georgia U.S. Senate seat, class III>
# ]

Class-by-class reference

ElectionYear

Model docs TK.

GovernmentLevel

Variants: FederalGovernment and StateGovernment (for now).

Model docs TK.

GovernmentBranch

Variants: LegislativeBranch and ExecutiveBranch (for now).

Model docs TK.

PrimaryElection

Party-specific variants: DemocraticPrimaryElection and RepublicanPrimaryElection.

Model docs TK.

PrimaryRunoffElection

Party-specific variants: DemocraticPrimaryRunoffElection and RepublicanPrimaryRunoffElection.

Model docs TK.

GeneralElection

Model docs TK.

ElectoralZone

Variants: DistrictElectoralZone and StateElectoralZone.

Model docs TK.

SenateSeat

Model docs TK.

HouseSeat

Model docs TK.

ExecutiveSeat

Variants: HeadOfGovernmentSeat.

Model docs TK.

Party

Model docs TK.

Contributing data

  1. Add data to one of the CSVs in the db/ directory.
  2. Build the package data files: $ python build.py
  3. Submit a pull request!

Influences

This project borrows most of its software design from python-us.

Its data models are also heavily inspired by the DNC election data project.

Testing

$ pipenv install -d
$ pipenv run pytest

Project details


Download files

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

Source Distribution

us-elections-0.6.0.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

us_elections-0.6.0-py3-none-any.whl (160.4 kB view details)

Uploaded Python 3

File details

Details for the file us-elections-0.6.0.tar.gz.

File metadata

  • Download URL: us-elections-0.6.0.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/2.7.16

File hashes

Hashes for us-elections-0.6.0.tar.gz
Algorithm Hash digest
SHA256 7400bc4340546220ce323dc129f9f947177d353dd9d1136a1ad948340e2cf235
MD5 64c7436612db74c66850aff396f5ffd8
BLAKE2b-256 90623a58ddeb27537f95a56822dfda3df5f87fa2deb3f42f74e49f8cdc8495d8

See more details on using hashes here.

File details

Details for the file us_elections-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: us_elections-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 160.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/2.7.16

File hashes

Hashes for us_elections-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 854fb981d56e56a2bd46b5008b11cea831479b3367145b02f720e542e771149e
MD5 73e1df05f41d323ba84f8f4a0add6b5c
BLAKE2b-256 9a5e6888b6b58bf469cb9591178a9b77ef7742b3c4d6457bf58ec11a8f9b8e6d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page