Python: Data SDK
Fetch vehicle data using the Python Data SDK
Overview
Similar to the Data SDK in TypeScript, we also offer a Data SDK written in Python. The Python SDK is an open-source SDK built to facilitate developers in connecting to the API Services. The objective of the Python Data SDK is to handle actions that interact with the DIMO APIs.
Getting Started
To get started with the Python Data SDK, you should always start by defining which API your application is interested in using. Depending on what you want access to, you may need the following:
developer_jwt
: This uses the Developer License public credentials and the private key (API Key) of the app. A developer would get this JWT on the backend through Auth. This is sometimes referred to asaccess_token.
vehicle_jwt:
This is the second layer of security around getting vehicle data. A developer would first need end users to grand permissions to the Developer License, and then get this JWT through Token Exchange. This is sometimes referred to asprivilege_token
.
To learn more about the different JWTs and what they mean, visit the JWT section in Authentication.
Using the SDK
Installation
pip install dimo-python-sdk
Import
Import the SDK:
from dimo import DIMO
Initiate the SDK depending on the environment of your interest, we currently support both Production
and Dev
environments:
dimo = DIMO("Production")
# OR
dimo = DIMO("Dev")
Function Calls
Before you can get privileged data for vehicles via the Vehicle JWT, a user must have already shared vehicles with you (via your developer license). For more information on how to allow users to share their vehicle data with you, navigate to Login with DIMO.
Getting a Developer JWT
Use the client_id
, domain
(aka redirectUri
), and api_key
from your application that you configured in the Developer Console.
# Call to get a Developer JWT
auth_header = dimo.auth.get_token(
client_id = '<client_id>',
domain = '<domain>',
private_key = '<api_key>'
)
# Store the Developer JWT from the auth_header dictionary
dev_jwt = auth_header["access_token"]
Getting a Vehicle JWT
Your developer_jwt
will be the dev_jwt
from the previous section, for Getting a Developer JWT.
The privileges
should be in list format – the below is just an example of privileges. You can read more about privileges under SACD Permissions Contract.
The token_id
is the token_id of the vehicle you'll be requesting data for, e.g. getting Telemetry data.
# Call to get a Vehicle JWT
get_vehicle_jwt = dimo.token_exchange.exchange(
developer_jwt = dev_jwt,
privileges=[1, 3, 4, 5],
token_id=<token_id>
)
# Store the Vehicle JWT from the get_vehicle_jwt response
vehicle_jwt = get_vehicle_jwt['token']
Contributions
Last updated
Was this helpful?