# 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.**

{% embed url="<https://pypi.org/project/dimo-python-sdk/>" %}
Python Data SDK on PyPI
{% endembed %}

## 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:

1. `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 [<mark style="color:red;">Auth</mark>](https://docs.dimo.org/developer-platform/getting-started/developer-guide/authentication). This is sometimes referred to as `access_token.`&#x20;
2. `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 [<mark style="color:red;">Token Exchange</mark>](https://docs.dimo.org/developer-platform/api-references/token-exchange-api). This is sometimes referred to as `privilege_token`.&#x20;

To learn more about the different JWTs and what they mean, visit the JWT section in [<mark style="color:red;">Authentication</mark>](https://docs.dimo.org/developer-platform/getting-started/developer-guide/authentication#getting-a-jwt).

## Using the SDK

### Installation

```sh
pip install dimo-python-sdk
```

### Import

Import the SDK:

```python
from dimo import DIMO
```

Initiate the SDK depending on the environment of your interest, we currently support both `Production` and `Dev` environments:

```python
dimo = DIMO("Production")

# OR

dimo = DIMO("Dev")
```

### Function Calls

{% hint style="warning" %}
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 [<mark style="color:red;">Login with DIMO</mark>](https://docs.dimo.org/developer-platform/developer-guide/developer-suite/dimo-developer-sdks/login-with-dimo-sdk).&#x20;
{% endhint %}

#### Getting a Developer JWT

Use the `client_id`, `domain` (aka `redirectUri`), and `api_key` from your application that you configured in the [<mark style="color:red;">Developer Console</mark>](https://docs.dimo.org/developer-platform/developer-guide/developer-console).&#x20;

```python
# 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 [<mark style="color:red;">SACD Permissions Contract</mark>](https://docs.dimo.org/developer-platform/developer-guide/permissions-contract-sacd). &#x20;

The `token_id` is the token\_id of the vehicle you'll be requesting data for, e.g. getting Telemetry data.

```python
# 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

{% embed url="<https://github.com/DIMO-Network/dimo-python-sdk/blob/master/CONTRIBUTING.md>" %}
