Geosupport ➡️ API
Previously we introduced how to use the python-geosupport package to geocode addresses at scale. Bringing Geosupport to Python opens up a lot of possibilities. Building on top of python-geosupport we can easily turn the package into a web service and share the power of Geosupport across the internet 🎉, so that people can access Geosupport without having to go through any installation headaches.
In this post, we will show how to use python-geosupport and Flask, a micro web framework, so that you can quickly develop your own geocoding web service.
- Make sure you have python-geosupport configured and save the following script as app.py. Read more about how to set up a Flask application here
2. By running “python app.py”, you will be able to start the web service. If it’s working, you will see the geocoding results by navigating to the following link in your browser:
http://0.0.0.0:5000/1b?house_number=120&street_name=broadway&borough=MN
If you couldn’t get it to work locally, check here for a sample response.
3. To further streamline the deployment process, we containerized the python-geosupport computing environment and we make quarterly updates to our docker-geosupport image on DockerHub, so that we’re in sync with the Geosupport release cycle.
Since geosupport doesn’t run on Mac and the setup processes can vary depending on the operating system, we encourage you to look into containerization using Docker, which would allow you to run the same version of Geosupport with the same configuration across different operating systems. To get started with Docker, check out this blog.
This light-weight Geosupport API web service helped us in cases when we had small datasets to geocode and we didn’t want to run geocoding as a separate step. Using the python requests library, we can easily geocode without having to worry about any external dependencies. Here is an example:
Once you have the geosupport Flask web API running locally (or you can just use the one we deployed for prototyping), you can create a geocoding function using requests and json. Using this function, you can geocode without having to worry about installing any dependencies or configuring environmental variables.
To further simplify the setup process for the Geosupport Flask web API, we created and maintain the api-geosupport Docker image, which allows you to spin up a local geosupport Flask web API in a Docker container using the following command:
If everything runs correctly, you will have a container running in the background with a geosupport Flask web API running inside of the container. Navigate to http://0.0.0.0:5000/1b?house_number=120&street_name=broadway&borough=MN
to see if it works.
With the Geosupport API deployed, we can geocode in a lot of different places such as Google Sheets (running with google app script) or even Excel. Geocoding is no longer bounded to a specific programing language or software interface and anyone can create and customize his or her geocoding web service according to specific needs.