Google Maps API client. For full API documentation go to:
http://python-gmaps.readthedocs.org
There are a bunch of libraries for Google Maps Web Service. To name a few:
What's wrong with them? googlemaps uses deprecated google API and forces you to format your parameters instead of using native python datatypes. And what about google.directions? Just take a look inside it's code...
So here is code for new Google Maps API endpoints. It requires requests, supports native python datatypes and is sweetened with some syntactic sugar. Nothing more. No bells and whistles.
Any contributions (code/issues) are welcome.
pip install python-gmaps
Just import API endpoint of your choice and start querying:
from gmaps import Geocoding
api = Geocoding()
api.geocode("somwhere")
api.reverse(51.123, 21.123)
If you need to use Google Maps API for Business then instantiate your endpoint
with api_key
param
from gmaps import Geocoding
api = Geocoding(api_key='your_secret_api_key')
Each endpoint method raises adequate exception when status of query is different
than OK
. It also unpacks results list from Google API output dict so you have
one key less to access but it does nothing more.
So if Google geocoding api outputs something like:
{
results: [
...
],
status: 'OK'
}
You will get only get list that was inside result
value. At least one element
returned is always assured, otherwise gmnaps.errors.NoResults
exception is
raised.
For each API endpoint you can specify:
- default
sensor
value - protocol (http/https)
- api key (only for http)
Available endpoints:
Geocoding()
Directions()
Timezone()
For detailed documentation of each endpoint refer to dosctrings or this API documentation. If you need list of available values for some parameters (like geocoding components, languages, regions etc.) refer to Google Maps API docs. These values can change anytime so there is no reason to check for them in this lib - they will be checked anyway.
gmaps.errors.GmapException
inherits fromException
instead ofBaseException
- fixed lists serialization issue (#1) thanks to @feighter09
- added pep8 compliance test using flake8
- pep8 compliance
- python 3.3 support
Timezone
endpoint added
Directions
endpoint added
- initial release
Geocoding
endpoint