Python SDK¶
Access geocoding, search, routing, and more from Python with just a few lines of code.
The Stadia Maps Python SDK is the easiest way to access our APIs from Python scripts, notebooks, and server-side applications. The SDK includes docstrings straight from our spec, and editors like PyCharm bring the official docs to your fingertips. And the type hints make it easier than ever to explore the flexibility of our advanced APIs.
Looking for maps?
If you need maps in your Python project, head over to maps for data visualization.
Quickstart¶
Installation¶
The Stadia Maps Python SDK is available through any package manager that supports PyPi.
pip install stadiamaps
poetry add stadiamaps
Getting an API Key¶
You'll need an API key to use the client in your project.
- Sign in to the client dashboard. (If you don't have an account yet, sign up for free; no credit card required!)
- Click "Manage Properties."
- If you have more than one property (ex: for several websites or apps), make sure you have selected the correct property from the dropdown at the top of the page.
- Under "Authentication Configuration," you can generate, view or revoke your API key.
Video: How to generate your API key¶
Example Code¶
Here's a quick usage example of how to set up a client and do some geocoding.
import os
import stadiamaps
from stadiamaps.rest import ApiException
from pprint import pprint
# Defining the host is optional and defaults to https://api.stadiamaps.com
# You can also use our EU endpoint to keep traffic within the EU like so:
# configuration = stadiamaps.Configuration(host="https://api-eu.stadiamaps.com")
# See configuration.py for a list of all supported configuration parameters.
configuration = stadiamaps.Configuration()
# Configure API key authentication. (1)
# This example assumes it is injected via an environment variable.
configuration.api_key['ApiKeyAuth'] = os.environ["API_KEY"]
# Enter a context with an instance of the API client
with stadiamaps.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = stadiamaps.GeocodingApi(api_client)
text = "Põhja pst 27" # str | The place name (address, venue name, etc.) to search for.
try:
# Search and geocode quickly based on partial input.
res = api_instance.autocomplete(text)
print("The response of GeocodingApi->autocomplete:\n")
pprint(res)
except ApiException as e:
print("Exception when calling GeocodingApi->autocomplete: %s\n" % e)
- Learn how to get an API key in our authentication guide.
You can find additional usage examples on the endpoint documentation pages.
Source Code¶
Our Python SDK is completely open source! You can find the source code and class documentation on GitHub.