launchpadlib
launchpadlib is an officially supported Python library for scripting Launchpad.net through its web services interfaces. It allows interaction with Launchpad objects like bugs, blueprints, and packages. The current version is 2.1.0, and it generally follows an as-needed release cadence for bug fixes and Python compatibility updates.
Common errors
-
ImportError: No module named 'launchpadlib.launchpad'
cause launchpadlib is not installed, or you are running in a different Python environment than where it was installed.fixEnsure launchpadlib is installed in your active Python environment: `pip install launchpadlib`. -
launchpadlib.errors.HTTPError: [401] Unauthorized
cause Attempted to access private data or perform an action requiring authentication without valid credentials, or the provided credentials are incorrect/expired.fixUse `Launchpad.login_with_creds()` and ensure you have valid, cached credentials. If running interactively, it should prompt you. For scripts, verify `~/.launchpadlib/creds` exists and is valid, or explicitly provide a `credentials_file`. -
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:XXXX)
cause The underlying `httplib2` library is failing to verify the SSL certificate of Launchpad.net. This can be due to outdated system CA certificates or network configurations (e.g., corporate proxies intercepting SSL).fixUpdate your operating system's CA certificates. If behind a corporate proxy, consult your IT department for proper proxy configuration (e.g., `HTTP_PROXY`, `HTTPS_PROXY` env vars) or necessary custom certificate installations. -
launchpadlib.errors.HTTPError: [404] Not Found
cause The requested Launchpad object (e.g., a person, bug, project) does not exist or its URL is incorrect.fixDouble-check the identifier or URL you are using. For example, ensure the person's Launchpad ID or project name is spelled correctly.
Warnings
- breaking launchpadlib 2.0.0+ requires Python 3.8 and is incompatible with Python 2.x. Older versions (pre-2.0.0) were Python 2 only.
- gotcha SSL/TLS Certificate Verification Errors due to `httplib2` dependency.
- gotcha Authentication issues with `login_with_creds` in non-interactive environments.
- gotcha Launchpad API Rate Limiting can cause requests to fail with HTTP 429 Too Many Requests.
Install
-
pip install launchpadlib
Imports
- Launchpad
from launchpadlib.launchpad import Launchpad
Quickstart
import os
from launchpadlib.launchpad import Launchpad
# Anonymous access (read-only for most public data)
# Use a unique application name, e.g., 'my-app-name-dev'
launchpad_anon = Launchpad.login_anonymously('my-checklist-day-app', 'production')
print(f"Logged in anonymously as {launchpad_anon.me}")
# Authenticated access (for writing data, private access)
# This will prompt for credentials if not already cached.
# Launchpad credentials are often stored in ~/.launchpadlib/creds
# To avoid interactive prompts in automated scripts, ensure credentials
# are pre-configured or use a 'testing' or 'staging' service root.
# For example, to avoid prompting, you could use:
# launchpad_auth = Launchpad.login_with_creds(
# 'my-checklist-day-app-auth',
# 'production',
# credentials_file='~/.launchpadlib/creds_my_app'
# )
try:
# This may prompt for credentials interactively if not cached
launchpad_auth = Launchpad.login_with_creds('my-checklist-day-app-auth', 'production')
print(f"Logged in as {launchpad_auth.me}")
# Example: Access your personal information
# print(f"My email address: {launchpad_auth.me.preferred_email_address}")
except Exception as e:
print(f"Could not log in with credentials: {e}")
print("To enable authenticated access, run this script interactively once to cache credentials.")
# Example of using the anonymous connection to get a person:
person = launchpad_anon.people['canonical']
print(f"Canonical's display name: {person.display_name}")