All Projects → nytimes → nytcampfin

nytimes / nytcampfin

Licence: other
A thin Python client for The New York Times Campaign Finance API

Programming Languages

python
139335 projects - #7 most used programming language

NYT Campfin

A very basic Python client for the New York Times Campaign Finance API. You'll need an API key, which should be set as an environment variable to run the tests. The client returns JSON only, not full Python objects, and attempts to implement each response in The Times' API.

Install

$ pip install nytcampfin

Or download and run

$ python setup.py install

Requirements

NYT Campfin uses the Kenneth Reitz's Requests library for retrieving API endpoints and Roman Haritonov's requests-cache library for local caching. The cache is preconfigured to use a local sqlite database and set to expire after 5 minutes.

Tests

To run the tests, set your API key as an environment variable NYT_CAMPFIN_API_KEY:

$ export NYT_CAMPFIN_API_KEY=YOUR-API-KEY

and then run the tests:

$ python test.py

The use of caching is disabled in the tests.

Usage

>>> from nytcampfin import NytCampfin
>>> finance = NytCampfin(YOUR_NYT_CAMPAIGN_FINANCE_API_KEY)

# retrieve today's filings
>>> today = finance.filings.today()
>>> today[0]['filing_id']
793150

# retrieve a committee's details
>>> cmte = finance.committees.get('C00490219',2012)
>>> cmte['id']
u'C00490219'

# retrieve a candidate's details
>>> cand = finance.candidates.get('H4NY11138')
>>> cand['name']
u'CLARKE, YVETTE D'

See the tests for plenty more examples.

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it.
  • Send a pull request. Bonus points for topic branches.

Authors

Derek Willis, [email protected]

Copyright

Copyright (c) 2012 The New York Times Company. See LICENSE for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].