Skip to main content

Asynchronous Python client library for Google Maps Platform

Project description

Asynchronous Python Client for Google Maps Services

Description

This library is essentially an async "wrapper" (not really wrapping anything, but not sure what better term to use) of the google-maps-services-python library

It includes all APIs used in google-maps-services-python

  • Directions API
  • Distance Matrix API
  • Elevation API
  • Geocoding API
  • Geolocation API
  • Time Zone API
  • Roads API
  • Places API
  • Maps Static API

Key Differences

  • At time of writing, aiohttp is used for making asynchronous http requests and (for now) can't be substituted.
    • When creating the async_googlemaps.AsyncClient object, an aiohttp.ClientSession object is a required argument.
    • The synchronous googlemaps.Client has an optional parameter, requests_session, which is the synchronous version.
    • It's required here because (to my knowledge) there's no way to (internally) ensure the async client can be properly closed before the event-loop is closed, therefore it must be handled on the user's end.
    • If you're unfamiliar with aiohttp, you should go read the Client quickstart guide in the aiohttp docs
    • See Usage for details

Requirements

  • Python 3.5 or later.
  • A Google Maps API key.

API Keys

Each Google Maps Web Service request requires an API key or client ID. API keys are generated in the 'Credentials' page of the 'APIs & Services' tab of Google Cloud console.

For even more information on getting started with Google Maps Platform and generating/restricting an API key, see Get Started with Google Maps Platform in our docs.

Important: This key should be kept secret on your server.

Installation

$ pip install -U async_googlemaps

Usage

There are basically two ways to create the async_googlemaps.AsyncClient

These examples use the Geocoding API and the Directions API with an API key:

  1. ('Preferred' usage) Use an async context manager for the aiohttp.ClientSession that will be passed to the async_googlemaps.AsyncClient
from async_googlemaps import AsyncClient
import aiohttp
from datetime import datetime

async def main():
   async with aiohttp.ClientSession() as maps_session:
      gmaps = AsyncClient(maps_session, key='Add Your Key here')

      # Then use the APIs just as you would with the synchronous version,
      # but with an await keyword prefacing the method
      
      # Geocoding an address
      geocode_result = await gmaps.geocode('1600 Amphitheatre Parkway, Mountain View, CA')
          
      # Look up an address with reverse geocoding
      reverse_geocode_result = await gmaps.reverse_geocode((40.714224, -73.961452))
          
      # Request directions via public transit
      now = datetime.now()
      directions_result = await gmaps.directions("Sydney Town Hall",
                                                   "Parramatta, NSW",
                                                   mode="transit",
                                                   departure_time=now)
  1. (More flexible) Create your aiohttp.ClientSession object without a context-manager, and manually close the ClientSession.
from async_googlemaps import AsyncClient
import aiohttp


async def main():
  session = aiohttp.ClientSession()
  gmaps = AsyncClient(session, key='Add Your Key here')

  # Geocoding an address
  geocode_result = await gmaps.geocode('1600 Amphitheatre Parkway, Mountain View, CA')
  
  reverse_geocode_result = await gmaps.reverse_geocode((40.714224, -73.961452))
  
  # aio_client must be closed manually
  await session.close()

Features

Retry on Failure

Automatically retry when intermittent failures occur. That is, when any of the retriable 5xx errors are returned from the API.

Documentation & resources

Documentation for the google-maps-services-python library

Getting started

API docs

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

async_googlemaps-0.0.10.tar.gz (26.7 kB view details)

Uploaded Source

Built Distribution

async_googlemaps-0.0.10-py3-none-any.whl (34.1 kB view details)

Uploaded Python 3

File details

Details for the file async_googlemaps-0.0.10.tar.gz.

File metadata

  • Download URL: async_googlemaps-0.0.10.tar.gz
  • Upload date:
  • Size: 26.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/0.0.0 pkginfo/1.8.2 readme-renderer/27.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.6 tqdm/4.62.0 importlib-metadata/4.8.1 keyring/23.4.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.6

File hashes

Hashes for async_googlemaps-0.0.10.tar.gz
Algorithm Hash digest
SHA256 c982e333d3be1900f22cfb3fe6a7bca422d2d741f918ad45f8fc3afa4cb645d1
MD5 943e783c99bd0283e53891954f387da0
BLAKE2b-256 ea5d549cad8935c76500200a839222c99fa22068025c55f5073b1f0128e6538e

See more details on using hashes here.

File details

Details for the file async_googlemaps-0.0.10-py3-none-any.whl.

File metadata

  • Download URL: async_googlemaps-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 34.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/0.0.0 pkginfo/1.8.2 readme-renderer/27.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.6 tqdm/4.62.0 importlib-metadata/4.8.1 keyring/23.4.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.6

File hashes

Hashes for async_googlemaps-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 9abcc40aa2e145821f420013d4b6b374efc288619ed6c4461d378b912253bb13
MD5 6c2675acc14fd8e2c0947791bc74de1f
BLAKE2b-256 be7eab64a62f222b25f567d5e79ff252a53f24c17fb9231dd303111f01ce2572

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page