Working with Launchpad API !
![]() |
Launchpad API |
Since last few weeks I was working with launchpad-api in order to generate some statistical and analytical reports for OpenERP project, I found launchpad-api quite powerful and interesting but required improvement in terms of developer experience, during my several days of work I have worked with the branches, bugs and merge proposal object.
Here I would like to share some of the interesting examples with methods that I used to work in the production.
Working with launchpadlib
launchpadlib is an open-source Python library that lets you treat the HTTP resources published by Launchpad's web service as Python objects responding to a standard set of commands. With launchpadlib you can integrate your applications into Launchpad without knowing a lot about HTTP client programming.Installation !
sudo apt-get install python-launchpadlibLaunchpad's web service currently exposes the following major parts of Launchpad:
- People and teams
- Team memberships
- Bugs and bugtasks
- The project registry
- Hosted files, such as bug attachments and mugshots.
Anonymous access
The Launchpad.login_anonymously() method will give you automatic read-only access to public Launchpad data.
from launchpadlib.launchpad import Launchpad
launchpad = Launchpad.login_anonymously('just testing', 'production', cachedir)
Authenticated access
To get read-write access to Launchpad, or to see a user's private data, you'll need to get an OAuth credential for that user. If you're writing an application that the user will run on their own computer, this is easy: just call the Launchpad.login_with() method.
This method takes two important arguments: the name of your application, and the name of the Launchpad server you want to run against. The default server name is 'staging', so that you don't destroy data by accident while developing. When you do a release, you can change this to 'production'.
from launchpadlib.launchpad import Launchpad
launchpad = Launchpad.login_with('My Application', 'staging')
Authenticated access for website integration
Things are a little more difficult if you want to integrate Launchpad's functionality into your own website. You can't call Launchpad.login_with(), because that will open up a web browser on your webserver--not on your user's computer.
Instead, you create a Credentials object identifying your website and call get_request_token() to ask Launchpad for a request token. Be sure to pass in the name of the Launchpad server you want to use (probably "production" as web_root.
from launchpadlib.credentials import Credentials
credentials = Credentials("my website")
request_token_info = credentials.get_request_token(web_root="production")
You'll get back a string that looks like 'https://launchpad.net/+authorize-token?oauth_token=...' This is the URL your end-user needs to visit in order to authorize your token.
At this point, you should redirect your user to that URL. Then, start periodically calling exchange_request_token_for_access_token():
from lazr.restfulclient.errors import HTTPError
complete = False
while not complete:
try:
credentials.exchange_request_token_for_access_token(
web_root="production")
complete = True
except HTTPError:
# The user hasn't authorized the token yet.
Once exchange_request_token_for_access_token() successfully executes, an authorized access token will be present in credentials.access_token. You can then pass the Credentials object into the Launchpad constructor.
Top Level objects
- .bugs: All the bugs in Launchpad
- .people: All the people in Launchpad
- .me: You
- .distributions: All the distributions in Launchpad
- .projects: All the projects in Launchpad
- .project_groups: All the project groups in Launchpad
Accessing project's branches
project = launchpad.projects['openobject-addons']branches = project.getBranches(status = ['Experimental', 'Development', 'Mature', 'Merged', 'Abandoned'])
for branch in branches:
#Iteration over the branch list and access branch data
Refer Launchpad API documentation to understand what you can assess with reference of branch.
Accessing project's merge proposals
project = launchpad.projects['openobject-addons']proposals = project.getMergeProposals(status=['Work in progress', 'Approved', 'Needs review', 'Rejected', 'Merged', 'Code failed to merge', 'Queued', 'Superseded'])
for merge in proposals:
#Iteration over the proposals and branch merge data
Refer Launchpad API documentation to understand what you can assess with branch merge proposal.
Accessing project's bugs
project = launchpad.projects['openobject-addons']bugs = project.searchTasks(status = ['New', 'Incomplete', 'Triaged', 'Opinion', 'Invalid', 'Won\'t Fix', 'Confirmed', 'In Progress', 'Fix Committed', 'Fix Released'])
for bug in bugs:
#Iteration over the bugs and bug data
Refer Launchpad API documentation to understand what you can assess with bug object.
Launchpad Analytic in OpenERP
I made an synchronization of branches, merge proposals, branches and user related to each information in OpenERP that generate lots of statistical information that gives me an view of openobject and related projects and its activities.
![]() |
Month wise branches merged in each project |
![]() |
Merged proposals accepted in trunk by category |