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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: us-elections-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 bd13c8290d80636fa3395269071e2aeec17e8066fe8ea0b7a57d10a9f7e53304
MD5 8ae553cb4d4da83cc49407c1178f3afe
BLAKE2b-256 f821e3499b4edde93ce102418e749e7ea309312910e94e53b6fd56acc03a337a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: us_elections-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d47a3e1ef46eb06dc8919bdfd85330425f637551610f4c32911476967f66d0de
MD5 db812ebdbbbfa0559a6ae07f50eb0bb6
BLAKE2b-256 1f110e66b727ddc8ba5151b459e94ae030c1c19199da029fb73f111c6c9446bb

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