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

Classes

ElectionYear

from elections import ElectionYear


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


# GET ELECTIONS IN THIS YEAR:
election_year.elections
# [<GeneralElection: Alabama Nov. 06, 2018>, ... ]

election_year.elections.general
election_year.elections.primary


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

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

eyr.states.alabama
eyr.states.new_jersey


# GET A BRANCH WITHIN A GOVERNMENT:
election_year.federal.legislative
# <Branch: United States Federal Government legislative Branch>

election_year.states.alaska.executive
# <Executive Branch: Alaska State Government>


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

election_year.states.alaska.executive.seats
# [<ExecutiveSeat: Alaska Governor>, ... ]

election_year.seats.federal.senate
election_year.seats.federal.house


# FILTER BY STATE:
election_year.elections_for_state('TX')
# [<GeneralElection: Texas Nov. 06, 2018>, ... ]

election_year.federal.legislative.seats_for_state('TX')
# [<HouseSeat: Texas U.S. House seat, 1st district>, ... ]

election_year.federal.legislative.seats_for_state('TX').senate
# [<SenateSeat: Texas U.S. Senate seat, class I>]

SenateSeat

from elections import ElectionYear

election_year = ElectionYear(2018)
seat = election_year.federal.legislative.seats.senate[0]

seat.state
# <State:Arizona>

seat.incumbent
# 'Flake, Jeff'

seat.incumbent_party
# <Party: Republican Party>

seat.senate_class
# 'I'

# etc.

HouseSeat

from elections import ElectionYear

election_year = ElectionYear(2018)
seat = election_year.federal.legislative.seats.house[0]

seat.state
# <State:Alaska>

seat.district
#

seat.district_name
# 'at-large district'

seat.incumbent
# 'Young, Don'

seat.incumbent_party
# <Party: Republican Party>

# etc.

GeneralElection

from elections import ElectionYear

election_year = ElectionYear(2018)
election = election_year.elections.general[0]

election.state
# <State:Alabama>

election.election_date
# datetime.datetime(2018, 11, 6, 0, 0)

election.registration_deadline
# datetime.datetime(2018, 10, 22, 0, 0)

# etc.

PrimaryElection

from elections import ElectionYear

election_year = ElectionYear(2018)
election = election_year.elections.primary[0]

election.state
# <State:Alabama>

election.election_date
# datetime.datetime(2018, 6, 5, 0, 0)

election.gop_election_type
# 'open'

election.runoff_election_date
# datetime.datetime(2018, 7, 17, 0, 0)

# etc.

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.1.1.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

us_elections-0.1.1-py3-none-any.whl (140.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: us-elections-0.1.1.tar.gz
  • Upload date:
  • Size: 8.8 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.1.1.tar.gz
Algorithm Hash digest
SHA256 6f077f11568c756dcffd453028abb81119c41a0d8f0ac4331c56afe0202c1004
MD5 c140ff6cfb012c92d5779eefe4b65295
BLAKE2b-256 c34a6223c950039a8b0c5faa9354bdf2bd395a76306cd596c2d9b033e4230cce

See more details on using hashes here.

File details

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

File metadata

  • Download URL: us_elections-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 140.5 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.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7c0f9154ffee44d7d895c3ae90af41c1e3baad43349e5c7e9173220184f012a6
MD5 130b9652b1bf1d86bca4d31fd1e8f266
BLAKE2b-256 42a5698a1a2a60ce879f4e75a3d79558e76ddad4ed1836685eebf9b7a3eb936f

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