Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Python wrapper for the Sunlight Lab's Real Time Congress API

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 tests
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .vimrc
Octocat-spinner-32 MANIFEST.in
Octocat-spinner-32 README.markdown
Octocat-spinner-32 RTC.py
Octocat-spinner-32 RTC_helpers.py
Octocat-spinner-32 __init__.py
Octocat-spinner-32 requirements.txt
Octocat-spinner-32 setup.py
README.markdown

RTC Python Wrapper Library

This is a Python wrapper for the Sunlight Foundation's Real Time Congress API.

Sunlight Labs takes government data and transforms it into services developers can use. The Real Time Congress (RTC) API is a RESTful API over the artifacts of Congress, in as close to real-time as possible.

WARNING: This may create a more transparent government. If you don't want change then stop reading here.

Requirements

  • python >= 2.6

List of Files

  • README.markdown - you're reading it
  • requirements.txt - list of required Python packages
  • RTC_helpers.py - Simple file to hold help and doc string text related to the RTC python library.
  • RTC.py - Python library for interacting with the Sunlight Labs Real Time Congress API.
  • tests/ - Folder containing all tests (files that start with 'test_')
    • RTCtest.py - File demonstrating some of the API usage.

Example Usage

You can specify the sections you want to pull from the RESTful API.


sections = ('bill_id', 'sponsor', 'committees')
bill = Bill.get_bill(bill_id='hr3-112', sections=sections)
print bill['sponsor']

Otherwise, it uses the default that's specified in the library.


bill = RTC.Bill.get_bill(bill_id='hr3-112')
print bill['sponsor_id'], bill['vetoed'], bill['last_action']['text']

See tests/RTCtest.py for more examples usage.

How to contribute

  • Fork the project.
  • Read through the outstanding issues, or report new ones here.
  • Write some tests to make sure we don't accidentally break your code later. We've created a test example for you.
  • Enter helper text into the RTC_helpers.py after writing a new classmethod to help document what you've done.
  • Send us a pull request.

How to create class methods for collections

This is the basic structure:


class Bill(RTC_Client): #name of collection (eg: bills, videos, floor_updates)
    """  __doc__ string goes here """
    __help__ = RTC_helpers.BILL_HELPER #string created and imported from RTC_helpers.py
    ...
    @classmethod
    def get_bill(cls, bill_id, make_obj=False, sections=RTC_helpers.BILL_DEFAULT_SECTIONS):
        endpoint = "bills.json"
        params = {'bill_id': bill_id}
        result = super(Bill, cls)._apicall(endpoint, sections, make_obj, **params)
        bill = result['bills'][0]
        return bill

Running tests

Make sure you have the discover package installed. It is included in our requirements.txt, which you can install with this command:

$ pip install -r requirements.txt

Then, in the project directory you can run all the tests with:

$ python -m discover

You can run individual or grouped tests based on patterns: $ python -m discover -p 'test_videos.py'

or

$ python -m discover -p '*.py'

Development Notes for Contributors

dict2obj is a function that coverts the json converted dictionary into a usable object. Since much of the RTC API's fields are not guaranteed, this may help avoid the extra coding for keyErrors. Additionally, it is convenient to use dot notation instead of dictionaries.

Something went wrong with that request. Please try again.