API

 

Please Vote for Sunlight's “Civic Hacking in Pursuit of Democracy” Video

Here’s an appeal for our readers: please help Sunlight spread the news of the great work civic hackers do as far and wide as possible by voting for our storytelling video in the Looking@Democracy contest organized by the Illinois Humanities Council with support from the MacArthur Foundation. (Voting ends May 16.)

We couldn’t wait to tell this (previously) untold story through a short video to demonstrate how the nascent movement of civic hackers are creating apps and tools using open government data to make their communities better. These men and women are equipped with laptops, open data and creative ideas to positively reconstruct the way we relate with government.

Read more

A New Focus on Sunlight's APIs

Sunlight Foundation APIsAt Sunlight we're immensely proud of our community of API users and today we're launching a new section of our website to learn more about them, see how others use the data and a snazzy query builder to easily see what's possible. Sunlight creates APIs to power our own tools as well as to provide infrastructure to the Open Gov and advocacy community at large. We hope this free and open data will improve your ability to create transparency around the issues you care about.

API stands for application programming interface and is a system that makes it easy for programers to use each other's data. At Sunlight we are eager for you to be able to access and build great projects on top of the data we use in our own projects. Nonprofit organizations, political campaigns, media outlets, students and citizens all use our collection of APIs with more than 7,000 keys issued and 735 million API calls made to date.

On the overview page we include a list of the APIs we provide, which projects each API powers, if it's functioning normally and an in-browser ability to see the kind of queries possible. We are showcasing Open Gov projects that could use technical or non-technical contributions on the community page, such as helping LittleSis track influence by building profiles and connections for powerful people and organizations or helping the unitedstates project on github to collect data on Congress. The bottom of the community page is a section called "When We Dream" where we share problems we'd love to see addressed and hope to open up a conversation on how to tackle the issue. On the events page we feature upcoming meetups, hackathons, conferences and camps that may pique your interest.

The new API section also features a gallery of how others use our data in interesting ways along with analytics on our number of keys, average daily calls and total calls. This section will hopefully serve as inspiration with ideas like how MinnPost used our Open States API to build a feature tracking the most important legislative bills in Minnesota, or how One Block Off the Grid added a call your member of Congress feature to their solar estimator tool to find local incentives. We list other organizations that have used our free data in the sidebar of the overview and although we can't endorse or claim any responsibility for how others use our data, we're just happy to see people using it!

We feature the new API section of our website in the top level navigation across our site to reflect our renewed focus on the data we provide and hope that you are inspired to sign-up for a key to build something. Keep up with the latest news about our APIs through the Sunlight Labs API Google Group or follow Sunlight Labs on Twitter.

Regulations.gov Continues to Improve, but Still Has Potential for Growth

rdg_shotRecently, the EPA eRulemaking team released a new version of Regulations.gov, a website that tracks the various stages of the rulemaking processes of hundreds of federal agencies, and collects and publishes comments from the public about this rulemaking. We’ve written about Regulations.gov before, and continue to be impressed with the site’s progress in making the sometimes-daunting intricacies of federal regulations more approachable to members of the general public.

This release brings several new features that further this goal. Styling on many document pages has been significantly improved, making it much easier to read both rule and comment text. The presentation of metadata has also been made cleaner, so researchers can more easily find identifiers that help them connect a particular rule to related documents on other websites, such as FederalRegister.gov or RegInfo.gov. New panes have also been added to help users understand the public participation that has occurred so far in a given rulemaking, and to more easily recognize opportunities for further participation.

Of course, since last year’s release of the Regulations.gov API, Regulations.gov is more than just an informational website; it has also become a data provider that now facilitates a variety of third-party participation and analysis tools, as their Developers page now highlights. One such tool is Sunlight’s recently-released Docket Wrench, which uses Regulations.gov data to explore questions of corporate and public influence in the federal regulatory process. Docket Wrench evolved from two years’ worth of effort exploring the possibilities of analysis on federal regulatory comment data, and we believe the time we’ve spent building it has given us a unique perspective on the avenues of research this data makes available, as well as the opportunities for further growth and improvement in regulatory comment data going forward.

The team behind Regulations.gov deserves enormous credit for the progress they’ve made, but there remains much work to be done to give the public a complete, accessible and useful path into the federal regulatory process.

Read more

New Districts in Sunlight Congress API

Good news if you were one of the users waiting on our Congress API to support the newly drawn congressional districts! As of today it is possible to pass the districts=2012 flag to the Congress API's districts.getDistrictFromLatLong method to instruct the API to return the district in effect for the 2012 elections.

As you may recall, the data wasn't previously available in a uniform format but thanks to a recent data release from Census.gov we were able to get this data loaded, with days to spare until the election.

The default will remain to return the districts in effect for purposes of representation until the swearing in of the 113th Congress in January 2013 at which point the temporary districts=2012 flag will be retired (but it will be safe to continue to pass the parameter indefinitely).

This change does not yet impact other Sunlight API methods. The Open States district methods and the ZIP code related methods will be updated as that data is available, as described in our last update.)

Read more

Open States API at Hacks for Democracy in Philadelphia

This month, the first Hacks for Democracy event has been ongoing in Philadelphia. A new hackathon idea, #hacks4d hopes to address a frequent criticism of civic hackathons: projects are often started with enthusiasm, but less often carried through to finished product. To that end, the event, which began as a weekend-long hackathon from 9/14 through the 9/16, has invited its participants back on 9/17, 9/24 and 10/1. The post-hackathon events are meant to encourage continued development and advisement over the course of a month. On the final day of the initial hackathon, a first round of demos and judging took place. A second round will be conducted on October 5th, one month before the general election.

Hacks for Democracy is being organized by Azavea, a Philadelphia data firm specializing in geospatial analysis, and Knight-Mozilla OpenNews. VentureF0rth has been providing the venue.

The initial reception event and the hackathon itself were both very well attended. At the reception, both technologists and non-technical stakeholder activists were represented, and more than a dozen excellent ideas were proposed. Excitement around the resources available was obvious, and this initial event gave each resource provider an opportunity to give a brief tour of what was available and the terms of use (Sunlight's presentation can be found here).

Five teams formed, each taking on one of the proposed ideas. The excellent organization of the event can be seen on its home page, which allows participants and observers to track progress on the ongoing projects, and see brief descriptions of the other solutions proposed during the initial brainstorm. This site also served as a central directory of the resources available to each team from sponsors and participating organizations.

State Gov Tracker

Sunlight's Open States API is being put to use by the State Gov Tracker project. The team's goal is to “create a simple-to-use web application that makes monitoring the activity of state elected officials much easier for the average person.” The final product will be a dashboard that includes basic information about a user's representatives, as well as multiple real time streams representing roll call votes, social media messaging and campaign finance data.

Using the Open States API, the team has been able to obtain recent votes and co-sponsorships in the PA General Assembly. Their software performs continuous analysis of this data to “create ideology/preference scores” in order to describe each member of the General Assembly on a continuum between conservative and liberal.

Sunlight Goes Back to School

It’s August and that means soon it’ll be back to school for students and teachers. Even if you have long put away your TI-84 Calculator or finally paid off your student loans, it’s still never too late to pick up a new skill.

Get ready to sharpen your figurative pencils and sign up for Sunlight Academy, our new interactive training portal that provides instructional and educational resources to make government more transparent and accountable. So whether you are an investigative journalist trying to get insight on a complex data set, an activist uncovering the hidden influence behind your issue or a congressional staffer in need of mastering legislative data, our transparency training program will teach you how to better connect the dots and make our tools and resources work for you.

The modules on offer at the Sunlight Academy are diverse. Ever wondered how to create a pivot table to analyze government data? Need help understanding the different lobbying reports? Or what exactly are APIs (and why do we talk about them so often)? Watch this tutorial to find out. After you have finished a lesson, don’t forget to mark the module as “completed” to earn prizes and other rewards.

Online courses are a popular, helpful and low-cost (zero, for Sunlight Academy!) way to boost your knowledge in the workplace or classroom. In fact, the John S. and James L. Knight Foundation just released a new report indicating that newsrooms are eager for digital learning opportunities.

Sunlight Academy aims to share the knowledge and expertise of the Sunlight Foundation, but we need your help to keep the courses fresh and relevant. Email tutorial suggestions to  training@sunlightfoundation.com.

In the meantime, sign up for an account at Sunlight Academy and check back often for new training lessons and events.

Never stop learning!

What Redistricting Means For Sunlight's APIs

Gerrymandering political cartoon

With the election 4 months away we're starting to get questions about when our various APIs and projects that depend upon them will return the newly redistricted legislative boundaries.

The short answer is that we will most likely not be able to support new district boundaries until after the November 2012 election (but before they technically go into effect for the purposes of representation in 2013).

If you're interested in the reasoning behind this decision, read on, but be warned, redistricting is a lot more complex than "the state has released new boundaries, let's load them."

Read more

Tools for Transparency: Using Python for government transparency

Disclaimer: The opinions expressed by the guest blogger and those providing comments are theirs alone and do not reflect the opinions of the Sunlight Foundation or any employee thereof. Sunlight Foundation is not responsible for the accuracy of any of the information within the guest blog.

Earlier, our labs team introduced Python-Sunlight an open source project that will unify all Sunlight APIs and make it easier to use.  Today, Eric Davis a lead developer at the Nevada Policy Research Institute, a think tank located in Las Vegas has taken on using Python for government transparency and is here to share the steps with us. Eric specializes in using technology to make government more open and has developed and currently maintains TransparentNevada, Nevada Journal and TweetNevada.

Note: The code in is this post was written for Mac/Linux -- it'll run fine on Windows, but you'll need to make some adjustments around path names when using virtualenv and when placing your API key in your home directory.

The past few years have seen an explosion in the amount of publicly available government data. From White House visitor logs to House expenditures to electronic campaign finance data, there is an unprecedented amount of government data available. This information shines a light on how our government operates, while also requiring bigger and more powerful programs to help make sense of it all.

Compared to the average computer user, it’s likely that most transparency activists already possess an above-average level of computer literacy. We work with huge spreadsheets and massive databases on a daily basis. Yet as important and useful as these programs are, in each case we’re forced to work within the constraints of the program itself.

So what happens if you need to do something that can’t be accomplished with the programs you already use?

You create your own.

For the rest of this article, I’m going to focus on the Python programming language and why it is a good “tool for transparency.” Two features, in particular, make Python an excellent programming language: solid documentation and extensive libraries. When you’re first starting out, having access to well-written documentation can be the difference between “getting it” and “getting lost.” In addition, an extensive number of libraries — pre-written code to handle common tasks — are easily available, which helps you focus on the task at hand rather than re-inventing the wheel.

To help introduce Python, we’re going to write a mini-program that collects the names and Twitter accounts for all the members of Congress.

If you’re a complete beginner to programming, I recommend you read at least the first few chapters of Zed Shaw’s “Learn Python the Hard Way” before continuing. It’s a free, online book that will teach you the basics of running simple programs. At a bare minimum, you should be able to complete exercises 0 and 1. You should be comfortable with editing text in a text editor and running programs from the command line before moving on.

For this program, we’ll be using “Sunlight Labs Services,” a service provided by the Sunlight Foundation that enables programmers to access government data easily and efficiently. The first thing you’ll need to do is register for a key. Click that link and enter your name and email along with the place you work. For “intended usage” put something like “Grab Twitter accounts for members of Congress.” Once you receive your key via e-mail, open your text editor and copy it into a file called ‘.sunlight.key’ (note the leading period) in your home directory. With this key, you’ll be able to access all of the Sunlight Labs Services.

Next, download virtualenv.py into your home directory. Now open your terminal and type: python virtualenv.py learn-to-program.

After that, change into the ‘learn-to-program’ directory. Now, we’re going to install two libraries.  Type: ./bin/pip install sunlight tablib.

That’s it for the setup; now comes the fun stuff.

Open up your text editor and type in the following:

 

Save this file as twitter_accounts.py inside the ‘learn-to-program’ directory that was created earlier.

There are five “parts” of this program, each separated by an empty line:

Line 1:

Remember those libraries we installed with ./bin/pip? We import them so they can be used.

Line 3:

Now that we’ve imported the sunlight library, here’s how we’re going to use it. This creates a variable — lawmakers — that holds information on each lawmaker currently in Congress.

Line 5:

Just like we made use of the sunlight library above, now we’re going to use tablib — short for “tabular library” — here. This creates another variable, names_and_twitter that will hold lawmaker names in one column and twitter accounts in another. We also tell it that the data will have the headers “name” and “twitter.”

Lines 7-10:

Line 7 goes through each lawmaker in lawmakers. Lines 8-10 are run for each lawmaker in the lawmakers variable. First, it sets the name variable by combining the lawmaker’s first and last names with a space. Next, it sets the twitter variable to the lawmaker’s twitter_id. Finally, it appends the name and twitter variables to the names_and_twitter dataset for use in the next step.

Lines 12-14:

This creates a file — ‘twitter.xls’ — and tells Python we’re going to be writing binary data to it. The next line writes the data from the names_and_twitter variable as an Excel spreadsheet to the file. Finally, we close the file to tell python we’re done with it.

Now back in your terminal and from inside the ‘learn-to-program’ directory, type ./bin/python twitter_accounts.py. This tells python to run the code you just entered.

 

Assuming everything was typed correctly, you’ll now have a ‘twitter.xls’ file next to your ‘twitter_accounts.py’ file. Open ‘twitter.xls’ with Excel or OpenOffice and you’ll see the full name in column A and that lawmaker’s twitter account in column B.

Congratulations: You just created your first program!

If you don’t have Excel or OpenOffice or want to generate a CSV (comma separated value) file instead of an Excel spreadsheet, replace names_and_twitter.xls with names_and_twitter.csv in line 13 and change ‘twitter.xls’ to ‘twitter.csv’ in line 12. Whereas Excel files have to be opened with special programs, one nice thing about CSV files is they are plain text and can be used to copy data to various other systems – like databases -- quite easily.

So where do you go from here? Try adding features to what you just wrote. Include the lawmaker’s party next to his or her name. Add another column with the lawmaker’s phone number (don’t forget to update the dataset headers). Explore other parts of the Congress API to, for example, find all the lawmakers for a given zip code.

Have fun!

Interested in writing a guest blog for Sunlight? Email us at guestblog@sunlightfoundation.com