LPPythonAPI
Revision 2 as of 2008-11-07 19:33:42
Clear message
Ubuntu Open Week - Writing Python programs using the Launchpad API - Barry Warsaw - Fri, Nov 7th, 2008
(02:02:48 PM) barry: jcastro: thanks! hello everybody
(02:03:21 PM) barry: i'm going to to try to provide some instruction on using launchpadlib to write python programs that access launchpad through its webservice
(02:04:08 PM) barry: i've never done an ubuntu open week session before so please be gentle :)
(02:04:16 PM) barry: first some background:
(02:04:52 PM) barry: as you know, there are lots of things you can do through launchpad's web interface. you can submit and manage bugs, register branches, answer questions ,etc.
(02:05:06 PM) barry: you also have a lot of data in launchpad that you can access through the web ui
(02:05:52 PM) barry: our intent is that anything you can do through the web ui, you shoudl be able to do in a script
(02:06:17 PM) barry: we've published a REST interface to launchpad, making it a "web service"
(02:06:35 PM) barry: and we provide supported python bindings to that REST interface, to make it really easy for you to script launchpad via python
(02:06:58 PM) barry: it's feasible for third parties to write bindings for the REST interface in other languages, though we won't support it officially
(02:07:18 PM) barry: you can get the python bindings from here:
(02:07:37 PM) barry: https://launchpad.net/launchpadlib
(02:07:40 PM) barry: and...
(02:07:53 PM) barry: https://code.launchpad.net/launchpadlib
(02:08:02 PM) barry: and all the documentation is here:
(02:08:09 PM) barry: https://help.launchpad.net/API/launchpadlib
(02:08:19 PM) barry: any questions so far?
(02:09:23 PM) barry: stdin: reminds me that launchpadlib is packaged in intrepid, so it's easier to get
(02:09:27 PM) barry: stdin: thanks
(02:09:38 PM) barry: python-launchpadlib
(02:09:56 PM) barry: we haven't yet put the code in the cheeseshop, but that will happen at some point
(02:11:08 PM) barry: the api docs mentioned above provide a nice starter for scripting launchpad, but there are a couple of things to be aware of
(02:12:11 PM) barry: first, there's an open bug describing a problem scripting the staging server, so it is recommended that you test against edge for now. be careful though because edge has real data, so try to use read-only changes to start with
(02:12:22 PM) barry: also, you will need a web browser available because launchpadlib must authenticate you through your browser
(02:12:29 PM) barry: your browser is the only client you trust :)
(02:13:37 PM) barry: also, you need to be a launchpad beta tester currently to have access to the launchpad web service
(02:14:20 PM) barry: when you go through the tutorial on the docs page, you will be asked to grant your application various levels of authorization
(02:14:40 PM) b33r_ is now known as b33r
(02:15:37 PM) barry: does anybody have any questions?
(02:16:34 PM) barry: i should also mention that full launchpad functionality is not yet exposed in the web service. you can do a lot of stuff right now and over time we'll be fleshing out the missing pieces
(02:16:49 PM) barry: our intent is that you should be able to access any data you have permission to in the web ui
(02:16:59 PM) barry: and perform any tasks you have permission to also
(02:17:47 PM) barry: i highly recommend reading the tutorial mentioned above, it will give you a great start into scripting launchpad via python
(02:22:22 PM) barry: alright, so let's go through a simple example
(02:23:01 PM) barry: i'm assuming you already have launchpadlib installed. if not, and you're having problems with that, let me know
(02:23:42 PM) barry: note that you'll also need wadllib installed. i would think the intrepid package dtrt, but if you're installing from source, launchpadlib's setup.py doesn't yet depend on wadllib
(02:24:35 PM) barry: you need to start by authenticating to launchpad, through your browser
(02:24:54 PM) barry: make sure your browser is open and that you're logged into launchpad
(02:25:01 PM) barry: then fire up your python interpreter
(02:25:16 PM) barry: start by importing some useful objects:
(02:25:23 PM) barry: >>> from launchpadlib.launchpad import Launchpad, EDGE_SERVICE_ROOT
(02:25:58 PM) barry: generally, you will want to set up caching, as this makes interacting with launchpad much faster. to do this you need to set up a cache directory
(02:26:18 PM) barry: in the following i'm going to use /tmp/cache but you can use anything you have write permission to
(02:26:37 PM) barry: the next step is to authenticate to launchpad (again, note that i'm using edge here)
(02:26:44 PM) barry: launchpad = Launchpad.get_token_and_login('just testing', EDGE_SERVICE_ROOT, '/tmp/cache')
(02:27:08 PM) barry: this creates an aplication for you called "just testing"
(02:27:22 PM) barry: it sets your client to talk to edge and to cache data in /tmp/cache
(02:27:43 PM) barry: you'll now see a message at stdout and your python will be waiting for you to complete the task
(02:28:00 PM) barry: you should also notice your web browser has opened an authentication page
(02:28:13 PM) barry: it's at this point that you are going to grant the appropriate access to your launchpadlib application
(02:28:31 PM) barry: i recommend for now to select read-only data
(02:29:02 PM) barry: any questions or problems so far?
(02:29:56 PM) barry: great
(02:30:16 PM) barry: once you've given access to your application, go back to your python prompt and hit return
(02:30:27 PM) barry: your python client is now primed and ready to talk to launchpad
(02:31:03 PM) barry: the 'launchpad' object is your door into the vast array of objects and actions you can take
(02:31:15 PM) barry: you can think of it as the root of a big tree of resources
(02:31:25 PM) barry: i.e. web resources
(02:31:40 PM) barry: 'launchpad' has a number of top level objects directly under it
(02:32:04 PM) barry: and through it you can access bugs, people, etc
(02:32:25 PM) barry: for example, the first thing you can do is view the person object that represents yourself:
(02:32:32 PM) barry: >>> launchpad.me
(02:32:32 PM) barry: <person at https://api.edge.launchpad.net/beta/~barry>
(02:32:56 PM) barry: it's through 'launchpad.me' that you can script changes to your presence in lp
...