Ruby wrappers for open government APIs around the web
Latest commit 6e1864e Apr 5, 2014 @jpmckinney jpmckinney Correct govkit-ca URL
Failed to load latest commit information.
lib -require 'iconv' May 8, 2013
rails move init.rb to rails directory Nov 20, 2012
.document Initial commit to govkit. Apr 28, 2010
.rspec Update three deprecated RSpec items Apr 8, 2011
.travis.yml Add travis-ci Apr 26, 2012
Gemfile update nokogiri Nov 16, 2012
LICENSE Correct govkit-ca URL Apr 5, 2014
Rakefile update openstates fixtures Nov 16, 2012
USAGE Add ability to fetch VoteSmart committtees; version bump to 0.0.3 May 20, 2010
VERSION bump version Nov 20, 2012

Govkit Build Status

Govkit is a Ruby gem that provides simple access to US open government APIs around the web, including:


From gemcutter:

gem install govkit


Add govkit to your environment.rb or Gemfile

Run rails generate govkit (Rails 3.x) or script/generate govkit (Rails 2.x) to copy a config file into config/initializers/govkit.rb. You will need to add your API keys to this config file.

Outside of Rails you can configure your API keys like so:

>> GovKit.configure do |config|
>>   config.sunlight_apikey   = 'YOUR_SUNLIGHT_API_KEY'
>>   config.votesmart_apikey  = 'YOUR_VOTESMART_API_KEY'
>>   config.ftm_apikey        = 'YOUR_FTM_API_KEY'
>> end

Usage Examples

>> GovKit::OpenStates::State.find_by_abbreviation('CA')
>> GovKit::VoteSmart::Address.find(votesmart_candidate_id)
>> GovKit::OpenCongress::Bill.find(:number => 5479, :type => 'h', :congress => '111')

Objects returned from GovKit will have attributes for each field coming back from the API:

>> x = GovKit::OpenStates::State.find_by_abbreviation('CA')
=> #<GovKit::OpenStates::State:0x00000100f6a5a8 @attributes={"lower_chamber_title"=>"Assemblymember", "lower_chamber_name"=>"Assembly", "upper_chamber_title"=>"Senator", "terms"=>[#<GovKit::OpenStates::State::Term:0x00000100f2a8e0 @attributes={"....
=> "California"

GovKit will raise GovKit::ResourceNotFound if a requested item isn't available.

Testing & Debugging

For debugging purposes, there's a raw_response reader provided for each object, which typically returns an HTTParty::Response object. To see the body of the HTTP response, you might look here:

(continuing the example from above)
>> x.raw_response.response.body
=> "{\n    \"lower_chamber_title\": \"Assemblymember\", \n    \"lower_chamber_name\": \"Assembly\", \n  ....

Bugs? Questions?

Please join the Govkit Google Group, especially if you'd like to talk about a new feature and get announcements.

Report a bug on our Lighthouse page.

Govkit's main repo is on Github:, where your contributions, forks, and feedback are greatly welcomed.

Dear Canadians

For Canadian open government data, our friends up north have created a govkit-ca gem that lives in the GovKit::CA namespace and should interoperate just fine with this gem.

A GovKit for your country?

Let us know if you'd like to build a govkit for your region! We'd love to link to you. Your gem should be called, for example, govkit-uk (ISO 3166 country code), and your methods should live in the GovKit::GB namespace (for example).

Copyright (c) 2010 Participatory Politics Foundation, released under the MIT license