Install & Compatibility
Where this runs
tested against v0.14.6 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 21.8MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 2.3s · import 0.000s · 22MB
24MB installed
● package 24MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
ServiceRoot
✓ from lazr.restfulclient import ServiceRoot
✗ from lazr.restfulclient import ServiceRoot
Demonstrates how to initialize a `ServiceRoot` client and access a top-level collection. This example uses a placeholder URL and assumes a basic RESTful service structure.
import os
from lazr.restfulclient.client import ServiceRoot
from lazr.restfulclient.errors import HTTPError
# Example: Connect to a mock service root (replace with your actual service URL)
# For Launchpad services, the root URL would be like 'https://api.launchpad.net/1.0/'
SERVICE_ROOT_URL = os.environ.get('LAZR_SERVICE_URL', 'https://api.example.com/')
try:
# Initialize a ServiceRoot. The first argument is typically an authorizer, or None for unauthenticated access.
service = ServiceRoot(None, SERVICE_ROOT_URL)
# Attempt to access a top-level collection, e.g., 'users'
# This will trigger an HTTP GET request to SERVICE_ROOT_URL/users
# Note: Replace 'users' with an actual collection name for your service
users_collection = service.users
print(f"Successfully accessed collection: {users_collection.lp_self_link}")
# Example: Fetch a specific item from the collection (if it supports key-based lookup)
# Assuming 'users_collection' can be indexed by ID, e.g., user with ID '123'
# This will perform another HTTP GET request
# user = users_collection[123]
# print(f"Fetched user: {user.display_name}")
except HTTPError as e:
print(f"HTTP Error encountered: {e.status} - {e.reason}\n{e.response}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
Debug
Known issues
breakingThe WSGI authentication middleware was moved from `lazr.restful` to `lazr.authentication` in `lazr.restfulclient` version 0.9.9. Direct usage of the old authentication middleware will break.fixUpdate to use the `lazr.authentication` library or the updated `lazr.restfulclient` authentication mechanisms if relying on the WSGI authentication middleware.
affects: <0.9.9
gotchaClient-side objects can 're-type' after fetching data. If a collection is initially configured to contain a generic resource type, but the server returns a more specific type upon fetching, the client-side object will adopt the properties of the actual, more specific type. This can be confusing if not expected.fixBe aware that the object's available attributes and methods might change after a network fetch (`lp_refresh()` or first attribute access) based on the server's response. Inspect `lp_attributes` or `resource_type_link` after fetching to understand the object's current state.
affects: All versions
gotchaThe library automatically retries requests on transient server errors (HTTP 502, 503) a configurable number of times. However, it will NOT retry on client-side errors (e.g., HTTP 400 Bad Request or 404 Not Found), escalating them directly as exceptions.fixHandle client-side HTTP errors (4xx) explicitly in your code, as `lazr.restfulclient` will not attempt to retry them. Use the `max_retries` constructor argument for `ServiceRoot` to adjust retry behavior for server errors if needed.
affects: All versions
gotchaIncompatibilities with `httplib2` versions have occurred. If you encounter unexpected HTTP connection issues or errors related to `httplib2`, ensure your `httplib2` version is compatible with `lazr.restfulclient`.fixCheck `lazr.restfulclient`'s release notes for specific `httplib2` version requirements. As of 0.14.2, it requires `httplib2 >= 0.7.7` for Python 3. If issues persist, try upgrading or downgrading `httplib2` to a version explicitly known to work with your `lazr.restfulclient` version.
affects: Various, particularly around `httplib2` 0.9 and 0.12.0
Upgrade
Version history
0.14.6latest on PyPI · released Jan 8, 2024
Audit
Dependencies
python3-distrorequiredLinux OS platform information API.
python3-httplib2requiredComprehensive HTTP client library (version >= 0.7.7 required).
python3-lazr.urirequiredLibrary for parsing, manipulating, and generating URIs.
python3-oauthlibrequiredGeneric, spec-compliant implementation of OAuth.
python3-pkg-resourcesrequiredPackage Discovery and Resource Access (from setuptools).
python3-wadllibrequiredLibrary for navigating WADL files (version >= 1.1.4 required).