Skip to main content

A python library for OptimoRoute's web service

Project description

Optimo Python library

This is a python library for OptimoRoute’s web service.


Note:

Although this is used internally and we continually improve it, it is still Beta software. Use with care.


Build Status PyPI version

Requirements

  • Python (has only been tested with python 2.7)

  • An access key provided to you by OptimoRoute

Installation

Installation using pip:

pip install optimo

Usage

from datetime import datetime
from decimal import Decimal
from optimo import OptimoAPI, Driver, WorkShift, Order, RoutePlan


# Instantiate the interface to optimoroute's API.
optimo_api = OptimoAPI('https://api.optimoroute.com', 'some_access_key')

# Create a workshift for the driver.
work_shift = WorkShift(
    start_work=datetime(year=2014, month=12, day=5, hour=8, minute=0),
    end_work=datetime(year=2014, month=12, day=5, hour=14, minute=0),
)

# Create the driver and also pass the workshift we created above.
driver = Driver(
    id='123',
    start_lat=Decimal('53.350046'),
    start_lng=Decimal('-6.274655'),
    end_lat=Decimal('53.341191'),
    end_lng=Decimal('-6.260402'),
    work_shifts=[work_shift],
)

order1 = Order(
    id='123',
    lat=Decimal('53.343204'),
    lng=Decimal('-6.269798'),
    duration=20,
)

order2 = Order(
    id='456',
    lat=Decimal('53.341820'),
    lng=Decimal('-6.264991'),
    duration=25,
)

# Create the route plan, and also pass the orders and the driver created above.
# The 'request_id' is the one we'll use later to check the results of the
# plan optimization.
routeplan = RoutePlan(
    request_id='1234',
    callback_url='https://callback.com/1234',
    status_callback_url='https://status.callback.com/1234',
    drivers=[driver],
    orders=[order1, order2],
)

# Start the plan optimization. If there is no exception raised then we assume
# success.
optimo_api.plan(routeplan)

# Get the result of the optimization. We use the 'request_id' we provided to
# optimoroute previously.
data = optimo_api.get('1234')

# If the optimization has finished we can see the result. Otherwise the data
# will be None.
{
    u'creationTime': u'2014-12-04T17:01:52',
    u'requestId': u'1234',
    u'result': {
        u'routes': [
            {
                u'driverId': u'123',
                u'orders': [
                    {u'id': u'123', u'scheduledAt': u'2014-12-05T08:04'},
                    {u'id': u'456', u'scheduledAt': u'2014-12-05T08:27'}
                ]
            }
        ],
        u'unservedOrders': []
    },
    u'success': True
}

# We can stop an already running optimization. If stopped previously no
# exceptions will be raised, it will return None implying it was successful.
optimo_api.stop('1234')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

optimo-0.2.3.tar.gz (20.1 kB view details)

Uploaded Source

Built Distribution

optimo-0.2.3-py2-none-any.whl (23.3 kB view details)

Uploaded Python 2

File details

Details for the file optimo-0.2.3.tar.gz.

File metadata

  • Download URL: optimo-0.2.3.tar.gz
  • Upload date:
  • Size: 20.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.7.0 setuptools/36.0.1 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/2.7.12

File hashes

Hashes for optimo-0.2.3.tar.gz
Algorithm Hash digest
SHA256 d84846a1eac4f46b054c4802abe1275fe166614149494ad70eafe0c2a4b740e6
MD5 091f02654e8065844b5169165c335984
BLAKE2b-256 4f9a3ed602ccf41826c20e7123ab880b1de9230957a20245c055f90908a68f21

See more details on using hashes here.

File details

Details for the file optimo-0.2.3-py2-none-any.whl.

File metadata

  • Download URL: optimo-0.2.3-py2-none-any.whl
  • Upload date:
  • Size: 23.3 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.7.0 setuptools/36.0.1 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/2.7.12

File hashes

Hashes for optimo-0.2.3-py2-none-any.whl
Algorithm Hash digest
SHA256 3b8ddfefeb9fe06eb1c2603ce6c56e0aa29db6c84110bcd017107d42be904c35
MD5 1c7bfde423bd2d9655b1e07665d3b216
BLAKE2b-256 6acd93cf858fe9ffc4149ebd6e826760c7bcc81f26038c1f311efe425fbee806

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page