Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/astagi/pyphoton
🗺 Light Komoot Photon client written in Python
https://github.com/astagi/pyphoton
geocoding hacktoberfest localization location maps python
Last synced: 4 days ago
JSON representation
🗺 Light Komoot Photon client written in Python
- Host: GitHub
- URL: https://github.com/astagi/pyphoton
- Owner: astagi
- License: mit
- Created: 2020-02-25T20:53:31.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-05-21T00:45:29.000Z (8 months ago)
- Last Synced: 2024-12-25T01:11:43.327Z (11 days ago)
- Topics: geocoding, hacktoberfest, localization, location, maps, python
- Language: Python
- Homepage: https://photon.komoot.io
- Size: 51.8 KB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pyphoton
🗺 Light Photon client written in Python
[![Latest Version](https://img.shields.io/pypi/v/pyphoton.svg)](https://pypi.python.org/pypi/pyphoton/)
[![codecov](https://codecov.io/gh/astagi/pyphoton/branch/master/graph/badge.svg)](https://codecov.io/gh/astagi/pyphoton)
[![Build Status](https://github.com/astagi/pyphoton/actions/workflows/ci.yml/badge.svg)](https://github.com/astagi/pyphoton/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/astagi/pyphoton/blob/master/LICENSE)## Install
```sh
pip install pyphoton
```## Usage
If you need some code ready to use, [spike.py](https://github.com/astagi/pyphoton/blob/master/spike.py) is a good starting point
### Execute queries
Python Photon client allows you to make queries to Photon service easily.
```py
from pyphoton import Photonclient = Photon()
location = client.query('berlin', limit=1)print (location.city)
print (location.latitude)
print (location.longitude)
````Photon` object accepts two parameters:
- `host`: the url where Photon instance is running (default `https://photon.komoot.io`)
- `language`: the preferred language (default is `en`)You can pass the `query` method the following parameters along the query string:
- `limit`: limit number of results
- `language`: force language in the query
- `latitude` and `longitude`: use them to search with priority to a geo position
- `location_bias_scale`: use to search with location bias
- `osm_tags`: a `string` or `list` containing [osm tags filters](https://github.com/komoot/photon#filter-results-by-tags-and-values)
- `bbox`: a `string` with comma-separated values or `list` containing [bounding box coordinates](https://github.com/komoot/photon#filter-results-by-bounding-box)`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.
```py
from pyphoton import Photonclient = 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:
- `latitude` and `longitude`: use them to search using a geo position
- `limit`: limit number of results### Deal with errors
If there's an error in your query, a `PhotonException` will be raised
```py
from pyphoton import Photon
from pyphoton.errors import PhotonExceptionclient = Photon()
try:
location = client.query('', limit=1)
except PhotonException as ex:
print (ex)
```## Run tests
```sh
pip install -r requirements-dev.txt
make test
```## WIP Features
- Method to fetch [latest data](http://download1.graphhopper.com/public/)