This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
# Run all tests
nox
# Run tests with coverage
python3 -m pytest tests/ -v --cov=googlemaps --cov-report=term-missing
# Run a single test file
python3 -m pytest tests/test_directions.py -v
# Run a single test
python3 -m pytest tests/test_directions.py::DirectionsTest::test_simple_directions -v
# Build documentation
nox -e docs
# Install package in development mode
pip install -e .This is a Python client library for Google Maps Platform Web Services APIs.
-
googlemaps/client.py— CentralClientclass that handles:- Authentication (API key or enterprise client_id/client_secret)
- HTTP requests with automatic retry logic
- Rate limiting (queries_per_second/queries_per_minute)
- Response extraction via
_get_body()or customextract_bodyfunctions
-
googlemaps/exceptions.py— Exception hierarchy:ApiError— API returned an error statusTransportError— Network/transport issuesHTTPError— Unexpected HTTP status codesTimeout— Request timeout_OverQueryLimit— Rate limit exceeded (retriable)
-
googlemaps/convert.py— Utilities for converting Python types to API-compatible strings (lat/lng formatting, time conversion, etc.)
Each API (directions, geocoding, places, etc.) is implemented as a separate module with:
- Standalone function — Takes
clientas first parameter, returns API response - Helper functions —
_xxx_extract()for custom response handling (some APIs return different formats) - Registration in client.py — Imported and attached to
Clientclass viamake_api_method()
Example from directions.py:
def directions(client, origin, destination, ...):
# Build params, call client._request(), return responseThen in client.py:
from googlemaps.directions import directions
Client.directions = make_api_method(directions)-
Classic APIs — Use GET requests to
maps.googleapis.com/maps/api/...with query parameters. Response hasstatusfield. -
Newer APIs (Routes, Solar, Weather, Air Quality, etc.) — Use POST with JSON body to service-specific domains. Response handling requires custom
_extractfunctions.
- Uses
unittestwithresponseslibrary for HTTP mocking - Base test class in
tests/__init__.pyprovidesTestCasewithassertURLEqual()helper - Test files mirror module names:
tests/test_directions.pytestsgooglemaps/directions.py