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.AsyncClientobject, anaiohttp.ClientSessionobject is a required argument. - The synchronous
googlemaps.Clienthas 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
- When creating the
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:
- ('Preferred' usage) Use an async context manager for the
aiohttp.ClientSessionthat will be passed to theasync_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)
- (More flexible) Create your
aiohttp.ClientSessionobject 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
- Get Started with Google Maps Platform
- Generating/restricting an API key
- Authenticating with a client ID
API docs
Metadata
Release files for async-googlemaps 0.0.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| async_googlemaps-0.0.10.tar.gz | 26.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| async_googlemaps-0.0.10-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 60.8 kB
Release files / async_googlemaps-0.0.10.tar.gz
| Download URL | async_googlemaps-0.0.10.tar.gz |
|---|---|
| Size | 26.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c982e333d3be1900f22cfb3fe6a7bca422d2d741f918ad45f8fc3afa4cb645d1
|
|
BLAKE2b-256 checksum How to use checksums |
ea5d549cad8935c76500200a839222c99fa22068025c55f5073b1f0128e6538e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / async_googlemaps-0.0.10-py3-none-any.whl
| Download URL | async_googlemaps-0.0.10-py3-none-any.whl |
|---|---|
| Size | 34.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9abcc40aa2e145821f420013d4b6b374efc288619ed6c4461d378b912253bb13
|
|
BLAKE2b-256 checksum How to use checksums |
be7eab64a62f222b25f567d5e79ff252a53f24c17fb9231dd303111f01ce2572
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for async-googlemaps 0.0.10
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.