{"id":5336,"library":"mygeotab","title":"MyGeotab Python Client","description":"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.","status":"active","version":"0.9.4","language":"en","source_language":"en","source_url":"https://github.com/geotab/mygeotab-python","tags":["telematics","API client","fleet management","Geotab SDK","vehicle data"],"install":[{"cmd":"pip install mygeotab","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Used for making HTTP requests to the MyGeotab API.","package":"requests","optional":false}],"imports":[{"symbol":"API","correct":"from mygeotab import API"}],"quickstart":{"code":"import os\nfrom mygeotab import API\n\n# Retrieve credentials from environment variables for security\nUSERNAME = os.environ.get('MYGEOTAB_USERNAME', 'your_username@example.com')\nPASSWORD = os.environ.get('MYGEOTAB_PASSWORD', 'your_password')\nDATABASE = os.environ.get('MYGEOTAB_DATABASE', 'YourDatabaseName')\n\nif USERNAME == 'your_username@example.com' or PASSWORD == 'your_password':\n    print(\"Please set MYGEOTAB_USERNAME, MYGEOTAB_PASSWORD, and MYGEOTAB_DATABASE environment variables.\")\nelse:\n    try:\n        # Initialize the API client\n        client = API(username=USERNAME, password=PASSWORD, database=DATABASE)\n        \n        # Authenticate the client\n        client.authenticate()\n        print(f\"Successfully authenticated to database: {DATABASE}\")\n        \n        # Example: Get the first 5 devices\n        devices = client.get('Device', resultsLimit=5)\n        print(f\"Retrieved {len(devices)} devices:\")\n        for device in devices:\n            print(f\"  - Device ID: {device.get('id')}, Name: {device.get('name')}\")\n            \n        # Example: Get version information (unauthenticated call example, though client is authenticated)\n        version_info = client.call('GetVersion')\n        print(f\"API Version: {version_info.get('apiVersion')}\")\n\n    except Exception as e:\n        print(f\"An error occurred: {e}\")","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade your Python environment to 3.7+ and then upgrade the `mygeotab` library to 0.9.0 or later: `pip install --upgrade mygeotab`.","message":"Version 0.9.0 dropped support for Python 2.x and Python 3.6. Ensure your environment uses Python 3.7 or newer to avoid compatibility issues.","severity":"breaking","affected_versions":"< 0.9.0"},{"fix":"Replace calls like `client.search('Device', name='%Test Dev%')` with `client.get('Device', search={'name': '%Test Dev%'})`.","message":"The `API.search()` and `API.search_async()` methods were deprecated in v0.5.0 and subsequently removed in v0.6.0. Their functionality was integrated into the `client.get()` method by using the `search` parameter.","severity":"deprecated","affected_versions":"0.5.0 - 0.5.x"},{"fix":"Always use double quotes for JSON keys and string values within your API call parameters, for example: `client.get('Device', search={'name': 'MyDevice'})`.","message":"When constructing JSON parameters for API calls, ensure all property names and string values are enclosed in double quotes. Using single quotes (e.g., `{'name': 'value'}` instead of `{\"name\": \"value\"}`) will result in a `Geotab.Serialization.JsonSerializerException` error from the MyGeotab API as of release 5.7.2103.","severity":"gotcha","affected_versions":"All (API-side enforcement since MyGeotab 5.7.2103)"},{"fix":"Implement logic to check for session validity before authenticating. If `session_id` is present and valid, proceed directly to API calls. Only call `authenticate()` when starting a new session or re-authenticating after an `InvalidUserException`. The `mygeotab` library's `client.authenticate()` should handle the standard username/password flow correctly, but be mindful when integrating with existing session IDs.","message":"If you already have a `session_id`, `client.authenticate()` should generally only be called if the existing `session_id` is invalid or expired (e.g., after an `InvalidUserException`). Repeatedly calling `authenticate()` with a valid `session_id` is often unnecessary and can lead to unexpected behavior or deprecated method warnings (specifically, the undocumented usage of `Authenticate` with an authenticated credentials object was deprecated around MyGeotab 9.0 on the API side). The `ExtendSession()` method (on the API) is for extending sessions.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}