In this tutorial, you'll learn how to use SmartMonkey's API on Python in a few minutes!
- Basic Python Knowledge: Python For Beginners
- SmartMonkey's API key: you can get one for free at flake.smartmonkey.io. More documentation at: SmartMonkey Docs
- Python 2.7 or above (python installation tutorial)
- pip python package management (pip installation tutorial)
- SmartMonkey's Python library. Install it using:
pip install smartmonkey
Optimize your route
You can optimize your route following these steps:
- Import SmartMonkey library
- Initialize SmartMonkey's client with your API Key (get it here)
- Describe the vehicles
- Describe the services (stops)
- Print result
It can be done as follows:
After executing this code you'll obtain an output like:
You'll find the routes find by the optimizer inside the solutions attribute. These routes contain a series of steps with arrival and departure time, distance and id of the stop. Also, the geometry of the route is provided so it can be displayed on a map as follows:
Congratulations, that's it! You've managed to optimize your first route! Try it yourself with your own places. You can now define more restrictions, just check the documentation to learn more.
In trouble? Feel free to contact us at [email protected]
You may also be interested in our Geo Tools extension for Visual Studio Code.