Times Developer Network Forums

Chat about your code

Python API wrapper in development

I'm developing a Python library for accessing this API. My primary interest is in the congressional data, but the code is structured so that it would be very simple to add hooks and tests for the other API interfaces. The code is on GitHub here:

http://github.com/hoprocker/nytimes-api/

If there are people using Python for other parts of the API, I'd love to get patches incorporating them into the library. It should be pretty straightforward from the existing code, but let me know if you need more info.

I reasoned that since the nytAPI is rest-ful, I could just abstract the endpoints, and then caching could be accomplished via any key-value storage system indexed on the func_name+args. Flat-namespacing also makes it pretty straight-forward to parameterize unittests across library classes.

My approach borrows liberally from the Sunlight Labs python wrapper for their API (http://github.com/sunlightlabs/python-sunlightapi), so credit to them. One of the things that we need to do with the API is to add URIs for linked resources into responses. We've begun doing that, but v3 of the API will do that across the board, limiting the number of calls needed to accomplish fairly simple tasks.

That'd be awesome. My original idea was to use dicts to store info about the fundamental units (member, bill, session, and others), assigning relationships by reference wherever possible, then supporting some sort of path-query to let developers access specific traits. That could have turned out to impose a restriction in its own way; developers would need to accommodate *my* structuring of the data. That's why I went with the endpoint-style implementation. But looking at what you've done, I'm starting to have second thoughts. Static umbrella classes are similar to using dicts, but enable relationship verification by the Python interpreter as well. And, when you're aware of what basic units are being used, it follows easily to write the access wrapper in terms of those and their relationships.

Hey guys I'm using python and the NYT Api to create a sort of critics pick search application and I think it would be a great idea to create a library that stretches across all of the categories. I realize that this would take a lot of work, but if we each added functions and/or classes to an overarching library applying to the topic we each are working in, we could get it done. Maybe create a public code workspace? Just a thought.

I'm interested in using Python for my Api as well. If you are still compiling your library let me know where I can add and have a look at the existing library. A public code workspace sounds cool, I wonder if Google docs or something similar would work?

Hey tomsmm,
I never actually started a library because I didn't see any other interested people, and I do not have much experience with library coding but now that you are interested I would help create a library. I think google has a google code section or something like that and maybe we could start there. I created the little application that I wanted to by the way and it worked great, but the code is not as concise as it could be because I had to create all my own functions to read through the api files. I think a library would greatly simplify this. If you would like to see my code I will send it to you (it takes your city and state and finds critics picks movies near you) and I would love your help if your interested in packaging this in an actual application that could be distributed after a GUI and other features are added. Thanks!

I've just developed a Python client for the Districts API. I'd be interested in feedback, and if anyone wants to collaborate to make a more generalized client, I'm totally game; if there's enough interest I might release it to PyPi.