Python client library for Ola Maps API Services
Project description
Ola Maps Python API Wrapper Library (Unofficial)
The Ola Maps Python library provides convenient access to the Ola Maps API from any Python 3.9+ application. The library currently includes type definitions for Routing APIs, Roads APIs, Places APIs, Geocoding and Maps Tiles details can be found here.
Installation
# install from PyPI
pip install py_olamaps
Postman Collection
Generate API Key
Follow the official documentation of Ola Maps to generate the API Key.
Usage
Initialize Client
import os
from py_olamaps.OlaMaps import OlaMaps
client = OlaMaps(
api_key=os.environ.get("OLA_MAPS_API_KEY"),
)
# OR
client = OlaMaps(client_id=os.environ.get("OLA_MAPS_CLIENT_ID"),
client_secret=os.environ.get("OLA_MAPS_CLIENT_SECRET"))
Routing API
Directions API
import os
from py_olamaps.OlaMaps import OlaMaps
client = OlaMaps(
api_key=os.environ.get("OLA_MAPS_API_KEY"),
)
routing_direction = client.routing.directions(
"12.993103152916301,77.54332622119354",
"12.972006793201695,77.5800850011884"
)
Distance Matrix API
import os
from py_olamaps.OlaMaps import OlaMaps
client = OlaMaps(
api_key=os.environ.get("OLA_MAPS_API_KEY"),
)
distance_matrix = client.routing.distance_matrix(
"28.71866756826579,77.03699668376802|28.638555357785652,76.96550156007675",
"28.638555357785652,76.96550156007675|28.53966907108812,77.05190669909288"
)
Roads API
Snap To Road API
import os
from py_olamaps.OlaMaps import OlaMaps
client = OlaMaps(
api_key=os.environ.get("OLA_MAPS_API_KEY"),
)
snap_to_Road = client.roads.snap_to_road(
"12.99927894246456,77.67323803525812|12.992086564113583,77.65899014102202|12.992567456375086,77.65989136324778|12.992672238708593,77.64337109685341|12.99127113597667,77.65716623889841",
)
Nearest Roads API
import os
from py_olamaps.OlaMaps import OlaMaps
client = OlaMaps(
api_key=os.environ.get("OLA_MAPS_API_KEY"),
)
nearest_roads = client.roads.nearest_roads(
"12.99927894246456,77.67323803525812|12.992086564113583,77.65899014102202|12.992567456375086,77.65989136324778",
)
Places API
Autocomplete API
import os
from py_olamaps.OlaMaps import OlaMaps
client = OlaMaps(
api_key=os.environ.get("OLA_MAPS_API_KEY"),
)
autocomplete = client.places.autocomplete(
"kempe"
)
Place Details API
import os
from py_olamaps.OlaMaps import OlaMaps
client = OlaMaps(
api_key=os.environ.get("OLA_MAPS_API_KEY"),
)
place_details = client.places.place_details(
"ola-platform:a79ed32419962a11a588ea92b83ca78e"
)
Nearby Search API
import os
from py_olamaps.OlaMaps import OlaMaps
client = OlaMaps(
api_key=os.environ.get("OLA_MAPS_API_KEY"),
)
nearby_search = client.places.nearby_search(
"venue",
"12.931544865377818,77.61638622280486"
)
Text Search API
import os
from py_olamaps.OlaMaps import OlaMaps
client = OlaMaps(
api_key=os.environ.get("OLA_MAPS_API_KEY"),
)
text_search = client.places.text_search(
"Cafes in Koramangala"
)
Geocode API
Forward Geocode API
import os
from py_olamaps.OlaMaps import OlaMaps
client = OlaMaps(
api_key=os.environ.get("OLA_MAPS_API_KEY"),
)
forward_geocode = client.geocode.forward_geocode("Mumbai")
Reverse Geocode API
import os
from py_olamaps.OlaMaps import OlaMaps
client = OlaMaps(
api_key=os.environ.get("OLA_MAPS_API_KEY"),
)
reverse_geocode = client.geocode.reverse_geocode("12.931316595874005,77.61649243443775")
Map Tiles API
Vector Map Tiles API
Array of data API
import os
from py_olamaps.OlaMaps import OlaMaps
client = OlaMaps(
api_key=os.environ.get("OLA_MAPS_API_KEY"),
)
array_of_data = client.map_tiles.array_of_data("planet")
Styles API
import os
from py_olamaps.OlaMaps import OlaMaps
client = OlaMaps(
api_key=os.environ.get("OLA_MAPS_API_KEY"),
)
styles = client.map_tiles.get_map_style()
Detail of a style API
import os
from py_olamaps.OlaMaps import OlaMaps
client = OlaMaps(
api_key=os.environ.get("OLA_MAPS_API_KEY"),
)
detail_of_style = client.map_tiles.get_style_details("default-light-standard")
Static Map Tiles API
Static Map Image based on Center Point API
import os
from py_olamaps.OlaMaps import OlaMaps
client = OlaMaps(
api_key=os.environ.get("OLA_MAPS_API_KEY"),
)
# note - the below returns an object as it contains an image
smi_center_point = client.map_tiles.static_map_image_based_on_center_point("default-light-standard", 77.61, 12.93, 15,
800, 600, "png")
Static Map Image based on Bounding Box API
import os
from py_olamaps.OlaMaps import OlaMaps
client = OlaMaps(
api_key=os.environ.get("OLA_MAPS_API_KEY"),
)
# note - the below returns an object as it contains an image
smi_bounding_box = client.map_tiles.static_map_image_based_on_bounding_box("default-light-standard", 77.611182859373,
12.93219851203095, 77.61513567417848,
12.935739723360513, 800, 600, "png")
Static Map Image
import os
from py_olamaps.OlaMaps import OlaMaps
client = OlaMaps(
api_key=os.environ.get("OLA_MAPS_API_KEY"),
)
# note - the below returns an object as it contains an image
static_map_image = client.map_tiles.static_map_image("default-light-standard", 800, 600, "png",
"77.61,12.93|77.61190639293811,12.937637130956137|width:6|stroke:#00ff44")
While you can provide an api_key
keyword argument,
we recommend using python-dotenv
to add OLA_MAPS_API_KEY="My API Key"
or OLA_MAPS_CLIENT_ID="My Client Id"
and OLA_MAPS_CLIENT_SECRET="My Client Secret"
to your .env
file
so that your API Key is not stored in source control.
Handling errors
Error codes are as followed:
Status Code | Error Type |
---|---|
400 | Bad Request |
401 | Unauthorized |
403 | Forbidden |
404 | Not Found |
409 | Conflict |
422 | Unprocessable Entity |
429 | Too Many Requests |
>=500 | InternalServerError |
Retries
Coming Soon...
Timeouts
Coming Soon...
Versioning
This package generally follows SemVer conventions, though certain backwards-incompatible changes may be released as minor versions:
- Changes that only affect static types, without breaking runtime behavior.
- Changes to library internals which are technically public but not intended or documented for external use. (Please open a GitHub issue to let us know if you are relying on such internals).
- Changes that we do not expect to impact the vast majority of users in practice.
We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.
We are keen for your feedback; please open an issue with questions, bugs, or suggestions.
Requirements
Python 3.9 or higher.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file py_olamaps-0.4.0.tar.gz
.
File metadata
- Download URL: py_olamaps-0.4.0.tar.gz
- Upload date:
- Size: 15.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.9.19 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4201f5e6c30fc3281331dacae162f72b1ce83dba6ce75b47dd5fc7cbacd3e6e |
|
MD5 | 75899a98ef696401fa7cbde2e8d4b8ec |
|
BLAKE2b-256 | 8b1eb5422c62115ffa361d9486b099e7fa518e9e53e0a494b42f9b7f95f58c20 |
File details
Details for the file py_olamaps-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: py_olamaps-0.4.0-py3-none-any.whl
- Upload date:
- Size: 18.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.9.19 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01719c55391eb4cc1a369ad0734e2af6d493901bb5f73418c15159818b3ad0b0 |
|
MD5 | 78d6b8e6157a213fd8d24caf40f619a0 |
|
BLAKE2b-256 | 4cb50a44bfbe55411f63c2caa1b94b59d29bd2668996b26d95692a2b7575b5fb |