Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Relies on Elex, a command-line tool to get results from the AP Election API 2.0. Demonstrates a method putting those results into a Postgres database using the COPY method and the loader's CSV output.


The following things are assumed to be true in this documentation.

  • You are running OSX.
  • You are using Python 2.7. (Probably the version that came OSX.)
  • You have pip, virtualenv and virtualenvwrapper installed and working.

See "Chapter 2: Install Virtualenv" of NPR's development environment blog post for details.

Having trouble on OS X El Capitan? See: Can't install virtualenvwrapper on OSX 10.11 El Capitan.

Getting started

mkvirtualenv elex-loader
git clone && cd elex-loader
pip install -r requirements.txt

The script will create databases and the user necessary for local development. Note: This does not exist for non-development environments. Please use commands in elex-dotfiles instead.


The New York Times defines a handful of different environments; principally, dev, stg and prd.

  • dev: Hits test URLs by default. Assumes a local Postgres database where the local user is a superuser.
  • stg: Hits test URLs by default. Requires a Postgres user / host / password to be defined in the environment. We use a .pgpass file and export the rest in /etc/environment. Check out elex-dotfiles for more.
  • prd: Hits live URLs by default. Requires a Postgres user / host / password to be defined in the environment.

Use cases

Load initial data


The AP will make "live zeros" available in the morning of an election day. You can run to get an entire new set of data, including races, reporting units, candidates and zeroed-out results.

Load results on election night


The daemon will run 100,000 times (seriously) unless it is stopped. We control ours with a custom Supervisord instance and a modified /etc/supervisord.conf. This configuration file is available in elex-dotfiles along with other secrets.

Set a wait interval

You might want to control how long the daemon waits between cycles. This is hardcoded to a default -- 15s in production, 30s elsewhere. You can create the file /tmp/ and export an ELEX_LOADER_TIMEOUT variable like this:


The daemon checks for this file and sources it if it exists in every loop, which means you can dynamically control the wait time. For example, we do this in our admin.

Load results once


Sometimes you just need to load a single update, e.g., to grab final results after we've turned off the loader. This command will get new results without baking or reloading any other parts of the database.

Load delegate data


Often, the AP will update delegate information after our daemon has stopped running. To update just delegates for a given racedate, run this command.


The NYT AP election loader scripts




You can’t perform that action at this time.