Netflix API Forums

I Need Help!

RSS Feed

Example Python client

    • Jeremy
    • Topic created 9 months ago

    I wrote a simple python client for anyone who'd like to see how to get it all to work I'm sure its not the most efficient way to access the API, and there is almost no error checking, but its a start. Download here: http://www.dinkumator.com/netflix.py

    Don't expect me to support this, again this is just an "working" example

  1. JR Conlin9 months ago

    Thanks for putting that together, although I did notice something that needs a bit of clarification.

    The rate limits are: Each developer gets 5000 calls per day for general use not associated with a specific user. Each active user gets 5000 API calls per day allocated to them per application. To be clear, these are allocated per user and are not pooled.

    So, basically, you get 5K per day requests for things from the catalog, and you also get 5K per day per user for user related actions (e.g. add/remove things from the queue). In fact, you really DON'T want to pass along the oAuth Token (the user credentials) when doing a catalog lookup. We do add things like eTags to help reduce the number of calls you need to make and help with caching data on your server.

    Sorry for any confusion. Yes, Adam is adding this to the FAQ so it's clearer.

  2. Michael Hart9 months ago

    One other note: you <may> want to call the catalog with the OAuth access token if you're making a ton of catalog calls and would like to leverage the per user limit of the user of your app.

  3. JR Conlin9 months ago

    Michael would know better than I would regarding rate limits.

  4. Jeremy9 months ago

    OK, just to double-check this, Michael says that what I did is best if you dont want to use up the consumer-5000 call limit (which will probably be easy to do when testing...). Thanks for checking JR, glad to know at least someone else has looked through the code.

    I just fixed the POST request call, now theres a function to add to a users queue. with this, it should be pretty clear how to perform most queries in the API now.

  5. Kirsten Jones4 months ago

    I noticed that this didn't work quite right for the newer versions of python (for those of us on, say, macs, where 2.4 isn't standard). I've created a newer version, you're welcome to retrieve it from http://www.synedra.org/netflix.py

    If there is any interest, I can create an installable module for this. I didn't know how many people were using the current version and didn't want to spend too much time if it's not needed. I'll do some support if there are feature requests or bug fixes needed.

  6. Kirsten Jones4 months ago

    I've made some changes to the app to make it easier for a user to see how various things work.

    You can give it a -v to get more verbose output (it will print out the URLs it's using for requests)
    You can give it a -a to use the user authentication (without this, it only needs your consumer key/secret, so this allows you to play without it before doing the user key/secret dance)
    -q still adds the disc to the queue, assuming the user is authenticated (otherwise it complains and exits)

  7. Kirsten Jones4 months ago

    Not sure if anyone's following along, but I do like making libraries to access REST resources, so I've started putting together an object-oriented python module based around the resources available from the API.

    It currently has pretty basic methods for catalog, user, and disc. I'll be updating it as I have time.

    http://code.google.com/p/pyflix/

  8. JR Conlin4 months ago

    Cool! Thanks!

    Mind if I add it to the Resources page?

  9. Kirsten Jones4 months ago

    Please do. It's fully functional in its current state, if minimally so :-)

    It's got some example code and working tests in there so people have examples of how to use the module - and I've organized the objects structure so that the resources requiring user authentication are methods of the User object. Hopefully this will make it easier for people to understand how the various oauth levels work (by example). Seems like this is a big topic of discussion :-)

  10. JR Conlin4 months ago

    Heh, you should see what it's like on the OAuth discussion groups. Very cool.

  11. Kirsten Jones4 months ago

    Not to be too fussy or anything, but could you change my name to "Kirsten"? I know, it's late and all. But still...

    Any thoughts on when that hack day might be? The irony of all this is that I started out planning to make a cool cover-flow-ish movie browser, but I got sidetracked by the python thing.

  12. JR Conlin4 months ago

    Fixed. Caught me in the middle of the update.

    About the hack day? Well, we're going to skip the Open Hack Day in favor of something cooler. (And considering that I was REALLY pulling for the Open Hack Day and think what we're going to be doing is, indeed, much cooler, hopefully will help.)

    When we get all the details worked out, we'll let you know.

  13. Kirsten Jones4 months ago

    The pyflix code is pretty much done (well, to version 0.1, anyhow). It needs some documentation love, but the example.py code gives a pretty comprehensive overview of the options available, until I get to documenting all the functions.

    Here's the basic description:

    Python module for accessing Netflix APIs

    This module is set up to access the REST resources from the netflix APIs as objects. There are currently Catalog, User, Disc and Queue objects (as well as a Client object to handle the connections). You can search for titles or people, and there are methods to retrieve authentication tokens. The user object can be used to retrieve metadata about the user as well as look at their rental queue. There are functions for viewing the queues, and adding, deleting, and moving things around. User authentication is only used for user protected resources.

    Once you have an API Key, you can insert the key and secret into the example.py file and work with it right away. The example.py code is smart enough to only try to access protected resources if requested via the command line flag -a. That file is fairly well commented to help folks figure out what's possible.

    In order to access any of the user-protected resources, follow the instructions in the README to generate consumer request and access tokens for your use in example.py or test.py. In the real world you'll want to be generating those consumer tokens for the specific user using your own code, but it's very helpful to see what you can do at the different levels of access.

    There is a test.py file which works with py.test, but you will need to insert the appropriate key/secrets in this as well to make it work for you.

    http://code.google.com/p/pyflix/

    Folks are welcome to ping me for help/fixes/requests. I think I'll take a break on this for a bit and make a java client :-)

  14. Chris Drackett3 months ago

    I'm trying to run the example code and I keep getting the following error after entering the EXAMPLE_USER.request key and secret:

    Expired or invalid request token

    my app also does not appear on http://www.netflix.com/ThirdPartyAccess even though from a users point of view the link seems to have taken place...

  15. Kirsten Jones3 months ago

    If I run it with just the API_KEY, API_SECRET, APP_NAME and CALLBACK, like so:

    kirsten-jones-computer:pyflix kirsten$ python example.py -a
    Authorize user access here: https://api-user.netflix.com/oauth/login?application_name=Movie%20browser&oauth_consumer_key=nbf4kr594esg4af25qexwtnu&oauth_token=eqtd656j6r36c6rh38qg548d&oauth_callback=http%3A%2F%2Fwww.synedra.org
    and then put this key / secret in EXAMPLE_USER.request:
    'key': '<something here>',
    'secret': '<something else here>'

    and run again.
    **************
    Then I go to the URL and click "Yes", and insert the "key" and "secret" into example.py under "request".

    And then you have to run it again to get an access token:

    kirsten-jones-computer:pyflix kirsten$ python bare.py -a
    now put this key / secret in EXAMPLE_USER.access so you don't have to re-authorize again:
    'key': '<long string>',
    'secret': '<short string>'

    Then you can put that key/secret under 'access'. Note that the request key/secret are *different* than the access key/secret, and you need *both* in order to be able to do things as a user.

    After that if I run 'example.py -a'

  16. Kirsten Jones3 months ago

    Blech, sent too early. The summary is, if I do 'example.py -a' and follow the instructions until it starts working, it works for me. You need to do it twice to get the user key/secret stuff you need.

  17. Chris Drackett2 months ago

    Just a note to everyone that I've branched Kirsten's excellent work on the netflix wrapper on github and started adding some properties to the various classes as well as adding a Person class.

    http://github.com/chrisdrackett/pyflix/tree/master

    I plan to keep development active, so more is on the way.

    there are some examples of how my additions work in the readme here:
    http://github.com/chrisdrackett/pyflix/blob/ad5f36eb3714217b49ad6275dd7fca9f25f167b9/README.markdown

    Its still a work in progress, feel free to fork my work, or send me any comments or suggestions!

  18. JR Conlin2 months ago

    Awesome! Thanks!