Module Index

Quick Start

Quick start guide

Install

Probably, the best and simplest way — use PIP:

$ pip install route4me-sdk

See also

The full installation guide: Installation guide

Use

from route4me import Route4Me
from route4me.constants import ALGORITHM_TYPE, DISTANCE_UNIT, TRAVEL_MODE, OPTIMIZE

API_KEY = "11111111111111111111111111111111"
r4m = Route4Me(API_KEY)
optimization = r4m.optimization
address = r4m.address
optimization.algorithm_type(ALGORITHM_TYPE.TSP)
optimization.share_route(0)
optimization.store_route(0)
optimization.route_time(7 * 600)
optimization.rt(True)
optimization.route_max_duration(86400)
optimization.route_name('Single Driver Round Trip')
optimization.optimize(OPTIMIZE.TIME)
optimization.distance_unit(DISTANCE_UNIT.MI)
optimization.travel_mode(TRAVEL_MODE.DRIVING)
address.add_address(
    address='754 5th Ave New York, NY 10019',
    lat=40.7636197,
    lng=-73.9744388,
    alias='Bergdorf Goodman',
    is_depot=True,
    time=0
)
address.add_address(
    address='717 5th Ave New York, NY 10022',
    lat=40.7669692,
    lng=-73.9693864,
    alias='Giorgio Armani',
    time=60
)
address.add_address(
    address='888 Madison Ave New York, NY 10014',
    lat=40.7715154,
    lng=-73.9669241,
    alias='Ralph Lauren Women\'s and Home',
    time=60
)
address.add_address(
    address='1011 Madison Ave New York, NY 10075',
    lat=40.7772129,
    lng=-73.9669,
    alias='Yigal Azrou\u00ebl',
    time=60
)
address.add_address(
    address='440 Columbus Ave New York, NY 10024',
    lat=40.7808364,
    lng=-73.9732729,
    alias='Frank Stella Clothier',
    time=60
)
address.add_address(
    address='324 Columbus Ave #1 New York, NY 10023',
    lat=40.7803123,
    lng=-73.9793079,
    alias='Liana',
    time=60
)
address.add_address(
    address='110 W End Ave New York, NY 10023',
    lat=40.7753077,
    lng=-73.9861529,
    alias='Toga Bike Shop',
    time=60
)
address.add_address(
    address='555 W 57th St New York, NY 10019',
    lat=40.7718005,
    lng=-73.9897716,
    alias='BMW of Manhattan',
    time=60
)
address.add_address(
    address='57 W 57th St New York, NY 10019',
    lat=40.7558695,
    lng=-73.9862019,
    alias='Verizon Wireless',
    time=60
)

response = r4m.run_optimization()
print("Optimization Problem ID: {}".format(response.get("optimization_problem_id")))
for a in response.get("addresses", []):
    print('{} - {} - {}'.format(a.get("sequence_no"), a.get("alias"), a.get("address")))

Installation guide

There are several ways to install Route4Me Python SDK.

PyPI

To install Route4Me Python SDK run this command in your terminal:

$ pip install route4me-sdk

If you don’t have pip installed you can use this guide to install pip.

Source Code

The source code of Route4Me Python SDK is open, public and live on GitHub: https://github.com/route4me/route4me-python-sdk.

You can either clone the entire repository:

$ git clone git://github.com/route4me/route4me-python-sdk.git

Or, download the zip/tarball:

# tarball
$ curl -OL https://github.com/route4me/route4me-python-sdk/tarball/master

# zip version:
$ curl -OL https://github.com/route4me/route4me-python-sdk/archive/master.zip

Now you can explore/modify code or embed it in your own project.

API

class route4me.api.Route4Me(key, headers={'Accept': '*/*', 'Accept-Encoding': 'identity, deflate, compress, gzip', 'User-Agent': 'python-sdk'}, redirects=True, verify_ssl=True, proxies={})[source]

Bases: object

Route4Me Python SDK

__init__(key, headers={'Accept': '*/*', 'Accept-Encoding': 'identity, deflate, compress, gzip', 'User-Agent': 'python-sdk'}, redirects=True, verify_ssl=True, proxies={})[source]

Initialize self. See help(type(self)) for accurate signature.

export_request_to_json(file_name)[source]

Export resquest to JSON File :param file_name: :return:

export_result_to_json(file_name)[source]

Export response to JSON File :param file_name: :return:

get(request_method)[source]

Execute optimization :param request_method: :return: JSON

get_optimization(optimization_problem_id)[source]

Get optimization given optimization_problem_id :param optimization_problem_id: :return:

parse_response()[source]

Parse response and set it to Route4me instance :return:

re_optimization(optimization_id, data={})[source]

Execute reoptimization :param optimization_id: :param data: :return: response as a object

run_optimization()[source]

Run optimization and return response as an object. :return: response as an object

Data Structures

Enums and constants

route4me.constants.auto_enum(*sequential, **named)[source]

Create enum :param sequential: :param named: :return:

route4me.constants.enum(**enums)[source]

Create enums with custom values to help user set their params :param enums: :return:

API endpoints

Members

class route4me.members.Members(api)[source]

Bases: route4me.base.Base

Members management.

__init__(api)[source]

Members Instance :param api: :return:

app_purchase_user_license(**kwargs)[source]

Application purchase user License :param kwargs: :return: API response content

get_api_key_users(**kwargs)[source]

Get users taht belong to a given api_key using GET request :return: API response

get_users(**kwargs)[source]

Get users using GET request :return: API response

member_authenticate(**kwargs)[source]

Member Authenticate :param kwargs: :return: API response content

register(**kwargs)[source]

Register Action :param kwargs: :return: API response content

validate_session(**kwargs)[source]

Validate Session :param kwargs: :return: API response content

verify_device_license(**kwargs)[source]

Verify User License :param kwargs: :return: API response content

webinar_registration(**kwargs)[source]

Webinar Register :param kwargs: :return: API response content

Optimization

class route4me.optimization.Optimization(api)[source]

Bases: route4me.base.Base

An Optimization Problem is a collection of addresses that need to be visited. This is distinct from a Route, which is a sequence of addresses that need to be visited by a single vehicle and a single driver in a fixed time period. Solving an Optimization Problem results in a number of routes.

__init__(api)[source]

Optimization Instance :param api: :return:

delete_address_from_optimization(**kwargs)[source]

Delete Address from an optimization using DELETE request :return: API response :raise: ParamValueException if required params are not present.

delete_optimization(**kwargs)[source]

Delete optimization using DELETE request :return: API response :raise: ParamValueException if required params are not present.

get_optimization(**kwargs)[source]

Get optimization using GET request :return: API response :raise: ParamValueException if required params are not present.

get_optimizations(**kwargs)[source]

Get optimizations using GET request :return: API response :raise: ParamValueException if required params are not present.

update_optimization(**kwargs)[source]

Update optimization using PUT request :return: API response :raise: ParamValueException if required params are not present.

Utilities

Typeconv

route4me.utils.json2obj(data)[source]

Parse JSON to object :param data: JSON data :return: object

Errors

exception route4me.exceptions.APIException(status_code, response, url)[source]

Bases: Exception

Handle API Exceptions

__init__(status_code, response, url)[source]

Initialize self. See help(type(self)) for accurate signature.

get_response()[source]

Return response :return:

get_status_code()[source]

Status code :return:

exception route4me.exceptions.ParamValueException(param, msg)[source]

Bases: Exception

Handle Params exceptions

__init__(param, msg)[source]

Initialize self. See help(type(self)) for accurate signature.

get_msg()[source]

Message from exception :return:

CHANGELOG

This is the history of changes of the route4me-python package

This file should be filled by maintainers, using pull requests Please, follow this guide

[0.0.7.0] - 2020-09-01

Removed

  • Python 2 support
  • Pypy build
  • Set Tracking Data Test

Added

  • Documentation
  • Changelog file
  • Tox
  • MANIFEST file
  • VERSION file

Fixed

  • Bug in Optimization Callback example
  • Some Test Cases that were failing

Changed

  • setup.py
  • Travis config file

[0.0.6.1] - 2019-11-11

Added

  • Added Exception when the server could not geo-code some addresses

[0.0.6.1] - 2019-11-06

Added

  • Redirect flag to QS when redirects are disable

Fixed

  • Bug on batch geocoding

[0.0.6.0] - 2019-10-24

Changed

  • Batch Geocodig method converted to POST request.

Fixed

  • Bug that assign the geo-coordinates to the wrong addresses

[0.0.5.2] - 2018-08-24

Changed

  • All Examples to work with JSON response

Fixed

  • Some Bugs

[0.0.5.1] - 2018-08-22

Changed

  • Changed all responses to JSON.

Fixed

  • All examples to support JSON response
  • GPS Test

[0.0.5.0] - 2018-02-26

Added

  • Address-Book example to query for any field

Removed

  • Lib xmltodict dependency.
  • Limit and offset as required fields in addressbook service

Changed

  • Addresses service

[0.0.4.0] - 2017-08-03

Added

  • Optimized Callback URL feature and example

[0.0.3.11] - 2016-11-02

Added

  • Python 3 support

[0.0.3.10] - 2016-09-19

Added

  • Routes Management and Missing Examples

[0.0.3.9] - 2016-09-16

Added

  • Members Management

[0.0.3.8] - 2016-09-12

Added

  • Activity Feed Support and Examples
  • Optimization missing Examples
  • Rapid Address missing Examples, remove python env from all examples, moved geocoding examples to its own folder
  • File Uploading feature and examples
  • Avoidance Zone missing Examples

[0.0.3.7] - 2016-07-25

Added

  • Territory Support

[0.0.3.6] - 2016-07-14

Added

  • Rapid Address Support and Examples
  • Optimization Example

[0.0.3.5] - 2016-06-22

Added

  • Orders support

[0.0.3.4] - 2016-04-22

Added

  • Avoidance Zone Management
  • Address Book Management, Route Tracking

[0.0.3.3] - 2016-04-18

Added

  • Generic Example, Notes, Delete Route, Single Depot Multiple Driver, Single Depot Multiple Driver TW Examples and Features

[0.0.3.2] - 2016-03-24

Added

  • Activities, Optimizations, Routes, Telematics, and Users Examples
  • Notes, and Activities Services

[0.0.3.1] - 2016-01-21

Added

  • Trucking hazardous goods features

[0.0.3.0] - 2016-01-19

Added

  • Example to update address attributes/details in an existing route (i.e. custom data, alias, order details, weight)
  • Example to insert address into existing route
  • Example to remove address from existing route
  • Example to move address from one stop into another

[0.0.2.14] - 2015-12-17

Added

  • Optimization trucking parameters and min_tour_size

[0.0.2.13] - 2015-12-03

Changed

  • Exceptions and Algorithm Type verification

[0.0.2.12] - 2015-11-28

Added

  • Optimization parameters, added support to Algorithm 100 and 101

[0.0.2.11] - 2015-08-13

Fixed

  • Examples

[0.0.2.10] - 2015-07-16

Added

  • Turns Avoidance uturn and leftturn support

[0.0.2.9] - 2015-05-12

Changed

  • Enabled follow redirects feature

[0.0.2.8] - 2015-04-27

Added

  • Optimization parameter max_tour_size

[0.0.2.7] - 2015-04-22

Added

  • Disable redirects

[0.0.2.6] - 2015-04-19

Added

  • Retry feature in case of geocoding error

[0.0.2.5] - 2015-04-08

Changed

  • Multiple depot multiple driver example

Added

  • Geo-localization getter retry functionality in case of failure

[0.0.2.4] - 2015-04-01

Added

  • Optimization quality and route start date feature
  • Geocoding Example

[0.0.2.3] - 2015-03-31

Fixed

  • Multiple Depot, Multiple Driver, Time window Example

[0.0.2.2] - 2015-03-01

Added

  • API Endpoints
  • Batch and single address geocoding

[0.0.2.1] - 2015-02-20

Added

  • Route Exporter feature

[0.0.2.0] - 2015-02-19

Added

  • Geocoding feature

[0.0.1.0] - 2014-07-01

Added

  • First commit of the package.

License

Copyright (C) 2016-2020 Route4Me

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.