MyGeotab Python Client

0.9.4 · active · verified Mon Apr 13

The `mygeotab` library is a Python client for the MyGeotab SDK, providing a clean, Pythonic API for interacting with the MyGeotab telematics platform. It handles automatic serialization and deserialization of API call results and is compatible with Python 3.9+. As of version 0.9.4, it continues to be actively developed with frequent releases addressing improvements and bug fixes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `mygeotab` client, authenticate using environment variables, and perform basic API calls such as retrieving devices and checking API version information. It handles potential authentication failures gracefully.

import os
from mygeotab import API

# Retrieve credentials from environment variables for security
USERNAME = os.environ.get('MYGEOTAB_USERNAME', 'your_username@example.com')
PASSWORD = os.environ.get('MYGEOTAB_PASSWORD', 'your_password')
DATABASE = os.environ.get('MYGEOTAB_DATABASE', 'YourDatabaseName')

if USERNAME == 'your_username@example.com' or PASSWORD == 'your_password':
    print("Please set MYGEOTAB_USERNAME, MYGEOTAB_PASSWORD, and MYGEOTAB_DATABASE environment variables.")
else:
    try:
        # Initialize the API client
        client = API(username=USERNAME, password=PASSWORD, database=DATABASE)
        
        # Authenticate the client
        client.authenticate()
        print(f"Successfully authenticated to database: {DATABASE}")
        
        # Example: Get the first 5 devices
        devices = client.get('Device', resultsLimit=5)
        print(f"Retrieved {len(devices)} devices:")
        for device in devices:
            print(f"  - Device ID: {device.get('id')}, Name: {device.get('name')}")
            
        # Example: Get version information (unauthenticated call example, though client is authenticated)
        version_info = client.call('GetVersion')
        print(f"API Version: {version_info.get('apiVersion')}")

    except Exception as e:
        print(f"An error occurred: {e}")

view raw JSON →