Finding the right endpoint for your workflow can be challenging. The MapRoulette Java Client helps abstract some of the must-have Project, Challenge, and Task management functionality into a single Java library.
We wanted to provide a similar experience for the growing Python community. That’s where our latest Python Client steps into the spotlight. The Locana OSM team is excited to introduce the new MapRoulette Python Client!
We decided to build a Python Client with two goals in mind:
- Empower our team and the OpenStreetMap community to build custom tools to help manage and gain insights from MapRoulette data.
- Reduce code redundancy and improve the overall experience with the MapRoulette API.
The new API Client is essentially a wrapper for the Requests library that supports several common use-cases. In just two months since our first release, we’ve managed to eliminate duplicate code while maintaining core functionality.
This article introduces some of the Python Client’s features. Let’s walk through some examples.
Creating a Configuration Object
The Configuration object controls how we connect to the MapRoulette server. You can pass a number of parameters including hostname, protocol, api_key, and certs. A common parameter to set would be the api_key as many API calls require passing an API key in the request headers. While the default hostname is maproulette.org, this parameter is configurable because the MapRoulette application can be deployed in different locations. You can also control whether to use HTTPS or HTTP protocols. If the instance of MapRoulette you’re trying to connect to requires client-side certs, you can pass those when creating the Configuration object. In this example I’ll stick to the default hostname, but pass my custom API key (intentionally removed):
import maproulette
config = maproulette.Configuration(api_key='{YOUR_API_KEY}')
That’s it! Now you have a Configuration object that you can use to make API calls.
Creating API Objects
API objects are another fundamental part of the Python Client. At the time of writing, you have access to four objects containing different API calls: Project, Challenge, Task, and User. Each object requires a Configuration object as an argument. For example, if you want access to the Project methods, create a Project API object.
project_api = maproulette.Project(config)