astagi / pyphoton

🗺 Light Komoot Photon client written in Python
https://photon.komoot.io
MIT License
6 stars 1 forks source link
geocoding hacktoberfest localization location maps python

pyphoton

🗺 Light Photon client written in Python

Latest Version codecov Build Status License: MIT

Install

pip install pyphoton

Usage

If you need some code ready to use, spike.py is a good starting point

Execute queries

Python Photon client allows you to make queries to Photon service easily.

from pyphoton import Photon

client = Photon()
location = client.query('berlin', limit=1)

print (location.city)
print (location.latitude)
print (location.longitude)

Photon object accepts two parameters:

You can pass the query method the following parameters along the query string:

Location object (or objects if you don't set limit=1) is generated from the json returned and contains all the information you need: name, state, street, city, osm attributes, extent_from.latitude, extent_from.longitude, extent_to.latitude, extent_to.longitude ...

Reverse search

Python Photon client allows you to make reverse search.

from pyphoton import Photon

client = Photon()
locations = client.reverse(latitude=52, longitude=10)

for location in locations:
    print ('🌉 Location #{0}\n{1}\n'.format(location.osm_id, location))

You can pass to the reverse method the following parameters:

Deal with errors

If there's an error in your query, a PhotonException will be raised

from pyphoton import Photon
from pyphoton.errors import PhotonException

client = Photon()
try:
    location = client.query('', limit=1)
except PhotonException as ex:
    print (ex)

Run tests

pip install -r requirements-dev.txt
make test

WIP Features