Package: async-googlemaps
Asynchronous Python Client for Google Maps ServicesDescriptionThis library is essentially an async "wrapper" (not really wrapping anything, but not sure what better term to use)
of thegoogle-maps-services-pythonlibraryIt includes all APIs used ingoogle-maps-services-pythonDirections APIDistance Matrix APIElevation APIGeocoding APIGeolocation APITime Zone APIRoads APIPlaces APIMaps Static APIKey DifferencesAt time of writing,aiohttpis used for making asynchronous http requests
and (for now) can't be substituted.When creating theasync_googlemaps.AsyncClientobject, anaiohttp.ClientSessionobject is a required argument.The synchronousgooglemaps.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 withaiohttp, you should go read the Client quickstart guide
in theaiohttp docsSee Usage for detailsRequirementsPython 3.5 or later.A Google Maps API key.API KeysEach 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 ofGoogle Cloud console.For even more information on getting started with Google Maps Platform and generating/restricting an API key, seeGet Started with Google Maps Platformin our docs.Important:This key should be kept secret on your server.Installation$ pip install -U async_googlemapsUsageThere are basically two ways to create theasync_googlemaps.AsyncClientThese examples use the Geocoding API and the Directions API with an API key:('Preferred' usage) Use an async context manager for theaiohttp.ClientSessionthat will be passed to theasync_googlemaps.AsyncClientfromasync_googlemapsimportAsyncClientimportaiohttpfromdatetimeimportdatetimeasyncdefmain():asyncwithaiohttp.ClientSession()asmaps_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 addressgeocode_result=awaitgmaps.geocode('1600 Amphitheatre Parkway, Mountain View, CA')# Look up an address with reverse geocodingreverse_geocode_result=awaitgmaps.reverse_geocode((40.714224,-73.961452))# Request directions via public transitnow=datetime.now()directions_result=awaitgmaps.directions("Sydney Town Hall","Parramatta, NSW",mode="transit",departure_time=now)(More flexible) Create youraiohttp.ClientSessionobject without a context-manager, and manually close the ClientSession.fromasync_googlemapsimportAsyncClientimportaiohttpasyncdefmain():session=aiohttp.ClientSession()gmaps=AsyncClient(session,key='Add Your Key here')# Geocoding an addressgeocode_result=awaitgmaps.geocode('1600 Amphitheatre Parkway, Mountain View, CA')reverse_geocode_result=awaitgmaps.reverse_geocode((40.714224,-73.961452))# aio_client must be closed manuallyawaitsession.close()FeaturesRetry on FailureAutomatically retry when intermittent failures occur. That is, when any of the retriable 5xx errors
are returned from the API.Documentation & resourcesDocumentation for thegoogle-maps-services-pythonlibraryGetting startedGet Started with Google Maps PlatformGenerating/restricting an API keyAuthenticating with a client IDAPI docsGoogle Maps Platform web servicesDirections APIDistance Matrix APIElevation APIGeocoding APIGeolocation APITime Zone APIRoads APIPlaces APIMaps Static API