API¶
Congress¶
A Python client for the ProPublica Congress API
API docs: https://propublica.github.io/congress-api-docs/
-
class
congress.
Congress
(apikey=None, cache='.cache', http=None)¶ Implements the public interface for the ProPublica Congress API
Methods are namespaced by topic (though some have multiple access points). Everything returns decoded JSON, with fat trimmed.
In addition, the top-level namespace is itself a client, which can be used to fetch generic resources, using the API URIs included in responses. This is here so you don’t have to write separate functions that add on your API key and trim fat off responses.
Create a new instance with your API key, or set an environment variable called
PROPUBLICA_API_KEY
.Congress uses httplib2, and caching is pluggable. By default, it uses httplib2.FileCache, in a directory called
.cache
, but it should also work with memcache or anything else that exposes the same interface as FileCache (per httplib2 docs).
Example: Using a custom cache object¶
Redis is a good option for a cache that can be shared between processes.
>>> from redis import StrictRedis
>>> from congress import Congress
>>> db = StrictRedis()
>>> congress = Congress(API_KEY, cache=db)
>>> senate = congress.members.filter('senate') # hits the API, caching the result
>>> senate = congress.members.filter('senate') # uses the cache
Members¶
-
class
congress.members.
MembersClient
(apikey=None, cache='.cache', http=None)¶ -
bills
(member_id, type='introduced')¶ Same as BillsClient.by_member
-
compare
(first, second, chamber, type='votes', congress=116)¶ See how often two members voted together in a given Congress. Takes two member IDs, a chamber and a Congress number.
-
departing
(chamber, congress=116)¶ Takes a chamber and congress and returns a list of departing members
-
filter
(chamber, congress=116, **kwargs)¶ Takes a chamber and Congress, OR state and district, returning a list of members
-
get
(member_id)¶ Takes a bioguide_id, returns a legislator
-
list_chamber
(chamber, congress=116)¶ Returns full member list for a chamber, the members.json endpoint
-
new
(**kwargs)¶ Returns a list of new members
-
party
()¶ Get state party counts for the current Congress
-
Bills¶
-
class
congress.bills.
BillsClient
(apikey=None, cache='.cache', http=None)¶ -
by_member
(member_id, type='introduced')¶ Takes a bioguide ID and a type: (introduced|updated|cosponsored|withdrawn) Returns recent bills
-
introduced
(chamber, congress=116)¶ Shortcut for getting introduced bills
-
major
(chamber, congress=116)¶ Shortcut for major bills
-
passed
(chamber, congress=116)¶ Shortcut for passed bills
-
recent
(chamber, congress=116, type='introduced')¶ Takes a chamber, Congress, and type: (introduced|updated) Returns a list of recent bills
-
upcoming
(chamber, congress=116)¶ Shortcut for upcoming bills
-
updated
(chamber, congress=116)¶ Shortcut for getting updated bills
-
Votes¶
-
class
congress.votes.
VotesClient
(apikey=None, cache='.cache', http=None)¶ -
by_date
(chamber, date)¶ Return votes cast in a chamber on a single day
-
by_month
(chamber, year=None, month=None)¶ Return votes for a single month, defaulting to the current month.
-
by_range
(chamber, start, end)¶ Return votes cast in a chamber between two dates, up to one month apart.
-
by_type
(chamber, type, congress=116)¶ Return votes by type: missed, party, lone no, perfect
-
get
(chamber, rollcall_num, session, congress=116)¶ Return a specific roll-call vote, including a complete list of member positions
-
loneno
(chamber, congress=116)¶ How often is each member the lone no vote?
-
missed
(chamber, congress=116)¶ Missed votes by member
-
nominations
(congress=116)¶ Return votes on nominations from a given Congress
-
party
(chamber, congress=116)¶ How often does each member vote with their party?
-
perfect
(chamber, congress=116)¶ Who never misses a vote?
-
recent
(chamber)¶ Return recent roll call votes for a given chamber. Also helpful if trying to find current session.
-
today
(chamber)¶ Return today’s votes in a given chamber
-