API

The full API reference for all public classes and functions.

Querying Data

class mygeotab.api.API(username, password=None, database=None, session_id=None, server='my.geotab.com', timeout=300)[source]

A simple and Pythonic wrapper for the MyGeotab API.

add(type_name, entity)[source]

Adds an entity using the API. Shortcut for using call() with the ‘Add’ method.

Parameters:
  • type_name (str) – The type of entity.
  • entity (dict) – The entity to add.
Raises:
Returns:

The id of the object added.

Return type:

str

authenticate(is_global=True)[source]

Authenticates against the API server.

Parameters:

is_global – If True, authenticate globally. Local login if False.

Raises:
Returns:

A Credentials object with a session ID created by the server.

Return type:

Credentials

call(method, **parameters)[source]

Makes a call to the API.

Parameters:
  • method (str) – The method name.
  • parameters – Additional parameters to send (for example, search=dict(id=’b123’) ).
Raises:
Returns:

The results from the server.

Return type:

dict or list

static from_credentials(credentials)[source]

Returns a new API object from an existing Credentials object.

Parameters:credentials (Credentials) – The existing saved credentials.
Returns:A new API object populated with MyGeotab credentials.
Return type:API
get(type_name, **parameters)[source]

Gets entities using the API. Shortcut for using call() with the ‘Get’ method.

Parameters:
  • type_name (str) – The type of entity.
  • parameters – Additional parameters to send.
Raises:
Returns:

The results from the server.

Return type:

list

multi_call(calls)[source]

Performs a multi-call to the API.

Parameters:

calls (list((str, dict))) – A list of call 2-tuples with method name and params (for example, (‘Get’, dict(typeName=’Trip’)) ).

Raises:
Returns:

The results from the server.

Return type:

list

remove(type_name, entity)[source]

Removes an entity using the API. Shortcut for using call() with the ‘Remove’ method.

Parameters:
  • type_name (str) – The type of entity.
  • entity (dict) – The entity to remove.
Raises:
set(type_name, entity)[source]

Sets an entity using the API. Shortcut for using call() with the ‘Set’ method.

Parameters:
  • type_name (str) – The type of entity.
  • entity (dict) – The entity to set.
Raises:
class mygeotab.api.MyGeotabException(full_error, *args, **kwargs)[source]

There was an exception while handling your call.

class mygeotab.api.TimeoutException(server, *args, **kwargs)[source]

The request timed out while handling your request.

Credentials & Authentication

class mygeotab.api.Credentials(username, session_id, database, server, password=None)[source]

The MyGeotab Credentials object.

get_param()[source]

A simple representation of the credentials object for passing into the API.authenticate() server call.

Returns:The simple credentials object for use by API.authenticate().
Return type:dict
class mygeotab.api.AuthenticationException(username, database, server, *args, **kwargs)[source]

Unsuccessful authentication with the server.

Date Helpers

mygeotab.dates

Date helper objects for timezone shifting and date formatting for the MyGeotab API.

mygeotab.dates.format_iso_datetime(datetime_obj)[source]

Formats the given datetime as a UTC-zoned ISO 8601 date string.

Parameters:datetime_obj (datetime) – The datetime object.
Returns:The datetime object in 8601 string form.
Return type:datetime
mygeotab.dates.localize_datetime(datetime_obj, tz=<UTC>)[source]

Converts a naive or UTC-localized date into the provided timezone.

Parameters:
  • datetime_obj (datetime) – The datetime object.
  • tz (datetime.tzinfo) – The timezone. If blank or None, UTC is used.
Returns:

The localized datetime object.

Return type:

datetime

Extras

Data Feed

class mygeotab.ext.feed.DataFeed(client_api, listener, type_name, interval, search=None, results_limit=None)[source]

A simple wrapper for the MyGeotab Data Feed. Create a listener that inherits from DataFeedListener to pass in.

start(threaded=True)[source]

Start the data feed.

Parameters:threaded – If True, run in a separate thread.
class mygeotab.ext.feed.DataFeedListener[source]

The abstract DataFeedListener to override

on_data(data)[source]

Called when rows of data are received.

Parameters:data – A list of data objects.
on_error(error)[source]

Called when server errors are encountered. Return False to close the stream.

Return type:bool
Parameters:error – The error object.
Returns:If True, keep listening. If False, stop the data feed.