The OGC Maps API provides maps and map data through dynamically rendered electronic maps. The API has multiple endpoints, each providing geospatial data using a variety of parameters.
In this blog post, I’ll be citing the work I did during this year’s Google Summer of Code (GSoC) under the guidance of my mentor Mr Benjamin Pross. For more detailed information, please visit my introductory blog post, midterm blog post, GitHub repository, and the API wrapper documentation.
This project aims to develop a terminal client and an API wrapper for the REST API endpoints in Python. These include the styles, collections, and the maps endpoint as a whole.
The main objectives of the project are as follows:
- Create a scalable API wrapper in Python
- Create a terminal client using the helper functions from the API wrapper
- Create tests for all the endpoints
- Setup CI/CD
The API wrapper uses utility functions to process and parse data accordingly, which makes the wrapper highly scalable in the future. Some features have been described below.
- When optional parameters are used, the helper function generates a dynamic URI and invalidates parameters if they are not valid for that particular endpoint.
- The wrapper returns a JSON response by default, unless explicitly specified. When using the terminal client, an optional -p flag can be used to prettify the JSON response.
- Endpoints returning images are automatically saved in the current working directory. Image format is png by default and can be changed by passing the format option separately.
- A caching system has been implemented to cache the GET requests. This would be useful in Python scripts involving reuse of data. The cache is invalidated after 180 seconds.
The API wrapper can be used as follows:
The terminal client has been built using the click library. Click has various options to build CLI (Command Line Interface) apps according to our needs. Some features of the terminal client have been described below.
- A context object is maintained during the entire time a command is run. This context object contains optional parameters passed by the user and a Boolean specifying whether to pretty print the output.
- The wrapper functions are used along with some other helper functions to build the CLI commands. This indirectly serves as a bridge between the API wrapper and the terminal client.
- If any command is incomplete, then the nearest matching command is returned by the Click library.
Caching works for the terminal client as well. The Python package has been published to the Python package index (PIP) which collectively installs the terminal client.
A simple usage of the terminal client:
The command will give an error if required arguments are not passed:
The output can be pretty-printed by using the -p/–prettify flag:
Docs and Tests
The docs are set up using the Sphinx library. Sphinx has various options to generate the docs. Currently, the autodoc tool of Sphinx generates the documentation automatically from the function docstrings using CSS and vanilla JS. A GitHub workflow generates the docs on every push on the main branch and commits the generated docs to the gh-pages branch for hosting.
The entire API wrapper has been covered with tests. The tests use Pytest fixtures to match the JSON response keys and validate the function. CI/CD has been set up on GitHub to run them on every push and pull request.
I thank all the mentors and organizations that chose me as a student developer for this year’s Google Summer of Code. I had a wonderful learning experience. I am grateful to my mentor Benjamin Pross for his guidance and advice during this time.
Weekly meetings have helped me improve my presentation skills and made it easier to express my ideas and always suggest a plan to go further. Working on this project has helped me to improve myself a lot and learn something new every day. It was an amazing experience.