dimo-python-sdk 1.0.0__tar.gz → 1.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dimo_python_sdk-1.1.0/PKG-INFO +209 -0
- dimo_python_sdk-1.1.0/README.md +191 -0
- {dimo_python_sdk-1.0.0 → dimo_python_sdk-1.1.0}/dimo/api/__init__.py +2 -10
- dimo_python_sdk-1.1.0/dimo/api/attestation.py +28 -0
- dimo_python_sdk-1.1.0/dimo/api/device_definitions.py +57 -0
- {dimo_python_sdk-1.0.0 → dimo_python_sdk-1.1.0}/dimo/api/token_exchange.py +7 -3
- {dimo_python_sdk-1.0.0 → dimo_python_sdk-1.1.0}/dimo/api/trips.py +3 -3
- dimo_python_sdk-1.1.0/dimo/api/valuations.py +32 -0
- {dimo_python_sdk-1.0.0 → dimo_python_sdk-1.1.0}/dimo/dimo.py +0 -12
- {dimo_python_sdk-1.0.0 → dimo_python_sdk-1.1.0}/dimo/environments.py +0 -8
- {dimo_python_sdk-1.0.0 → dimo_python_sdk-1.1.0}/dimo/graphql/telemetry.py +29 -22
- dimo_python_sdk-1.1.0/dimo_python_sdk.egg-info/PKG-INFO +209 -0
- {dimo_python_sdk-1.0.0 → dimo_python_sdk-1.1.0}/dimo_python_sdk.egg-info/SOURCES.txt +0 -5
- {dimo_python_sdk-1.0.0 → dimo_python_sdk-1.1.0}/pyproject.toml +1 -1
- dimo_python_sdk-1.0.0/PKG-INFO +0 -393
- dimo_python_sdk-1.0.0/README.md +0 -375
- dimo_python_sdk-1.0.0/dimo/api/attestation.py +0 -24
- dimo_python_sdk-1.0.0/dimo/api/device_data.py +0 -147
- dimo_python_sdk-1.0.0/dimo/api/device_definitions.py +0 -30
- dimo_python_sdk-1.0.0/dimo/api/devices.py +0 -254
- dimo_python_sdk-1.0.0/dimo/api/events.py +0 -14
- dimo_python_sdk-1.0.0/dimo/api/user.py +0 -53
- dimo_python_sdk-1.0.0/dimo/api/valuations.py +0 -32
- dimo_python_sdk-1.0.0/dimo/api/vehicle_signal_decoding.py +0 -90
- dimo_python_sdk-1.0.0/dimo_python_sdk.egg-info/PKG-INFO +0 -393
- {dimo_python_sdk-1.0.0 → dimo_python_sdk-1.1.0}/LICENSE +0 -0
- {dimo_python_sdk-1.0.0 → dimo_python_sdk-1.1.0}/dimo/__init__.py +0 -0
- {dimo_python_sdk-1.0.0 → dimo_python_sdk-1.1.0}/dimo/api/auth.py +0 -0
- {dimo_python_sdk-1.0.0 → dimo_python_sdk-1.1.0}/dimo/constants.py +0 -0
- {dimo_python_sdk-1.0.0 → dimo_python_sdk-1.1.0}/dimo/errors.py +0 -0
- {dimo_python_sdk-1.0.0 → dimo_python_sdk-1.1.0}/dimo/eth_signer.py +0 -0
- {dimo_python_sdk-1.0.0 → dimo_python_sdk-1.1.0}/dimo/graphql/__init__.py +0 -0
- {dimo_python_sdk-1.0.0 → dimo_python_sdk-1.1.0}/dimo/graphql/identity.py +0 -0
- {dimo_python_sdk-1.0.0 → dimo_python_sdk-1.1.0}/dimo/request.py +0 -0
- {dimo_python_sdk-1.0.0 → dimo_python_sdk-1.1.0}/dimo_python_sdk.egg-info/dependency_links.txt +0 -0
- {dimo_python_sdk-1.0.0 → dimo_python_sdk-1.1.0}/dimo_python_sdk.egg-info/requires.txt +0 -0
- {dimo_python_sdk-1.0.0 → dimo_python_sdk-1.1.0}/dimo_python_sdk.egg-info/top_level.txt +0 -0
- {dimo_python_sdk-1.0.0 → dimo_python_sdk-1.1.0}/setup.cfg +0 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: dimo-python-sdk
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: DIMO SDK in Python
|
|
5
|
+
Author-email: Barrett Kowalsky <barrettkowalsky@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/DIMO-Network/dimo-python-sdk
|
|
7
|
+
Project-URL: Issues, https://github.com/DIMO-Network/dimo-python-sdk/issues
|
|
8
|
+
Keywords: dimo,sdk,python,depin,web3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=3.8
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: requests>=2.30.0
|
|
16
|
+
Requires-Dist: eth-account==0.13.4
|
|
17
|
+
Requires-Dist: eth-utils==4.1.1
|
|
18
|
+
|
|
19
|
+
# DIMO Python Developer SDK
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
You can install the SDK using `pip`
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install dimo-python-sdk
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Unit Testing
|
|
30
|
+
|
|
31
|
+
Coming Soon
|
|
32
|
+
|
|
33
|
+
## API Documentation
|
|
34
|
+
|
|
35
|
+
Please visit the DIMO [Developer Documentation](https://docs.dimo.org/developer-platform) to learn more about building on DIMO and detailed information on the API.
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
### Developer License
|
|
39
|
+
|
|
40
|
+
In order to build on DIMO, you’ll need to get a [DIMO Developer License](https://docs.dimo.zone/developer-platform/getting-started/developer-license) via the [DIMO Dev Console](https://console.dimo.org/). The DIMO Developer license is our approach and design to a more secured, decentralized access control. As a developer, you will need to perform the following steps:
|
|
41
|
+
|
|
42
|
+
1. Sign Up for an Account - You can use your Google or Github account to register.
|
|
43
|
+
2. Complete Registration - Enter the details of the application that you’re building.
|
|
44
|
+
3. Create An App - Click “Create App”, fill out the form & select your preferred environment (at this time, please select “Production” until we’re ready to launch our Sandbox environment), then hit “Create Application”.
|
|
45
|
+
4. Finish Configuring Your Application - Once your project is initialized, you’ll use your connected wallet to generate an API Key and any optional Redirect URIs.
|
|
46
|
+
|
|
47
|
+
More information about this process can be found on our docs [here](https://docs.dimo.org/developer-platform/getting-started/developer-guide/developer-console)
|
|
48
|
+
|
|
49
|
+
## How to Use the SDK
|
|
50
|
+
|
|
51
|
+
Importing the SDK:
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from dimo import DIMO
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Initiate the SDK depending on the envionrment of your interest, we currently support both `Production` and `Dev` environments:
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
dimo = DIMO("Production")
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
or
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
dimo = DIMO("Dev")
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Authentication
|
|
70
|
+
|
|
71
|
+
To get authenticated as a developer, you must have already obtained a [Developer License via the Console](https://docs.dimo.org/developer-platform/getting-started/developer-guide/developer-console#getting-a-license). To learn more about authentication, including the User JWT, Developer JWT, and Vehicle JWT needed for accessing certain endpoints, please read: [Authentication Docs](https://docs.dimo.org/developer-platform/getting-started/developer-guide/authentication).
|
|
72
|
+
|
|
73
|
+
#### API Authentication
|
|
74
|
+
|
|
75
|
+
##### (Option 1) 3-Step Function Calls
|
|
76
|
+
|
|
77
|
+
The SDK offers 3 basic functions that maps to the steps listed in [Authentication](https://docs.dimo.org/developer-platform/getting-started/developer-guide/authentication): `generate_challenge`, `sign_challenge`, and `submit_challenge`. You can use them accordingly depending on how you build your application.
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
challenge = dimo.auth.generate_challenge(
|
|
81
|
+
client_id = '<client_id>',
|
|
82
|
+
domain = '<domain>',
|
|
83
|
+
address = '<address>'
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
signature = dimo.auth.sign_challenge(
|
|
87
|
+
message = challenge['challenge'],
|
|
88
|
+
private_key = '<private_key>'
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
tokens = dimo.auth.submit_challenge(
|
|
92
|
+
client_id = '<client_id>',
|
|
93
|
+
domain = '<domain>',
|
|
94
|
+
state = challenge['state'],
|
|
95
|
+
signature = signature
|
|
96
|
+
)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
##### (Option 2) Auth Endpoint Shortcut Function
|
|
100
|
+
|
|
101
|
+
As mentioned earlier, this is the streamlined function call to directly get the `developer_jwt`. The `address` field in challenge generation is omitted since it is essentially the `client_id` of your application per Developer License:
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
auth_header = dimo.auth.get_token(
|
|
105
|
+
client_id = '<client_id>',
|
|
106
|
+
domain = '<domain>',
|
|
107
|
+
private_key = '<private_key>'
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
# Store the Developer JWT from the auth_header dictionary
|
|
111
|
+
dev_jwt = auth_header["access_token"]
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Querying the DIMO REST API
|
|
115
|
+
|
|
116
|
+
The SDK uses the [requests](https://requests.readthedocs.io/en/latest/) library for making HTTP requests. You can perform a query like so:
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
def decode_vin():
|
|
120
|
+
device_makes = dimo.device_definitions.decode_vin(
|
|
121
|
+
developer_jwt = dev_jwt,
|
|
122
|
+
country_code = "USA",
|
|
123
|
+
vin = "<VIN>"
|
|
124
|
+
)
|
|
125
|
+
# Do something with the response
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
#### Query Parameters
|
|
129
|
+
|
|
130
|
+
For query parameters, simply feed in an input that matches with the expected query parameters:
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
dimo.device_definitions.search_device_definitions(
|
|
134
|
+
query = "Lexus gx 2023"
|
|
135
|
+
)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
#### Vehicle JWTs
|
|
140
|
+
|
|
141
|
+
As the 2nd leg of the API authentication, applications may exchange for short-lived Vehicle JWTs for specific vehicles that granted privileges to the app. This uses the [DIMO Token Exchange API](https://docs.dimo.org/developer-platform/api-references/token-exchange-api).
|
|
142
|
+
|
|
143
|
+
For the end users of your application, they will need to share their vehicle permissions via the DIMO Mobile App or through your implementation of the [Login with DIMO flow](https://docs.dimo.org/developer-platform/getting-started/developer-guide/login-with-dimo). You can use the pre-built React component SDK, or redirect users to the URLs included in the documentation [here](https://docs.dimo.org/developer-platform/getting-started/developer-guide/login-with-dimo#dont-use-react).
|
|
144
|
+
|
|
145
|
+
Typically, any endpoints that uses a NFT `tokenId` in path parameters will require JWTs. You can use this flow to obtain a privilege token.
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
|
|
149
|
+
get_vehicle_jwt = dimo.token_exchange.exchange(
|
|
150
|
+
developer_jwt = dev_jwt,
|
|
151
|
+
# The Developer JWT you received using either the three step function calls, or the .get_token() shortcut
|
|
152
|
+
privileges=[1, 3, 4, 5],
|
|
153
|
+
# The privileges you've set for this vehicle, in list format (e.g. [1, 3, 4, 5])
|
|
154
|
+
token_id="<token_id>"
|
|
155
|
+
# The Vehicle NFT Token ID that you are requesting permission to
|
|
156
|
+
)
|
|
157
|
+
vehicle_jwt = get_vehicle_jwt['token']
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Once you have the privilege token, you can pipe it through to corresponding endpoints like so:
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
def my_trips():
|
|
164
|
+
trip_data = dimo.trips.trips(
|
|
165
|
+
vehicle_jwt=vehicle_jwt,
|
|
166
|
+
token_id=<token_id>
|
|
167
|
+
)
|
|
168
|
+
return trip_data
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Querying the DIMO GraphQL API
|
|
172
|
+
|
|
173
|
+
The SDK accepts any type of valid custom GraphQL queries, but we've also included a few sample queries to help you understand the DIMO GraphQL APIs.
|
|
174
|
+
|
|
175
|
+
#### Authentication for GraphQL API
|
|
176
|
+
|
|
177
|
+
The GraphQL entry points are designed almost identical to the REST API entry points. For any GraphQL API that requires auth headers (Telemetry API for example), you can use the same pattern as you would in the REST protected endpoints.
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
|
|
181
|
+
telemetry_data = dimo.telemetry.query(
|
|
182
|
+
vehicle_jwt=vehicle_jwt,
|
|
183
|
+
query= """
|
|
184
|
+
query {
|
|
185
|
+
some_valid_GraphQL_query
|
|
186
|
+
}
|
|
187
|
+
"""
|
|
188
|
+
)
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
#### Send a custom GraphQL query
|
|
192
|
+
|
|
193
|
+
To send a custom GraphQL query, you can simply call the `query` function on any GraphQL API Endpoints and pass in any valid GraphQL query. To check whether your GraphQL query is valid, please visit our [Identity API GraphQL Playground](https://identity-api.dimo.zone/) or [Telemetry API GraphQL Playground](https://telemetry-api.dimo.zone/).
|
|
194
|
+
|
|
195
|
+
```python
|
|
196
|
+
my_query = """
|
|
197
|
+
{
|
|
198
|
+
vehicles (first:10) {
|
|
199
|
+
totalCount
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
"""
|
|
203
|
+
|
|
204
|
+
total_network_vehicles = dimo.identity.query(query=my_query)
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## How to Contribute to the SDK
|
|
208
|
+
|
|
209
|
+
You can read more about contributing [here](https://github.com/DIMO-Network/dimo-python-sdk/blob/dev-barrettk/CONTRIBUTING.md)
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# DIMO Python Developer SDK
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
You can install the SDK using `pip`
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install dimo-python-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Unit Testing
|
|
12
|
+
|
|
13
|
+
Coming Soon
|
|
14
|
+
|
|
15
|
+
## API Documentation
|
|
16
|
+
|
|
17
|
+
Please visit the DIMO [Developer Documentation](https://docs.dimo.org/developer-platform) to learn more about building on DIMO and detailed information on the API.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Developer License
|
|
21
|
+
|
|
22
|
+
In order to build on DIMO, you’ll need to get a [DIMO Developer License](https://docs.dimo.zone/developer-platform/getting-started/developer-license) via the [DIMO Dev Console](https://console.dimo.org/). The DIMO Developer license is our approach and design to a more secured, decentralized access control. As a developer, you will need to perform the following steps:
|
|
23
|
+
|
|
24
|
+
1. Sign Up for an Account - You can use your Google or Github account to register.
|
|
25
|
+
2. Complete Registration - Enter the details of the application that you’re building.
|
|
26
|
+
3. Create An App - Click “Create App”, fill out the form & select your preferred environment (at this time, please select “Production” until we’re ready to launch our Sandbox environment), then hit “Create Application”.
|
|
27
|
+
4. Finish Configuring Your Application - Once your project is initialized, you’ll use your connected wallet to generate an API Key and any optional Redirect URIs.
|
|
28
|
+
|
|
29
|
+
More information about this process can be found on our docs [here](https://docs.dimo.org/developer-platform/getting-started/developer-guide/developer-console)
|
|
30
|
+
|
|
31
|
+
## How to Use the SDK
|
|
32
|
+
|
|
33
|
+
Importing the SDK:
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from dimo import DIMO
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Initiate the SDK depending on the envionrment of your interest, we currently support both `Production` and `Dev` environments:
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
dimo = DIMO("Production")
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
or
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
dimo = DIMO("Dev")
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Authentication
|
|
52
|
+
|
|
53
|
+
To get authenticated as a developer, you must have already obtained a [Developer License via the Console](https://docs.dimo.org/developer-platform/getting-started/developer-guide/developer-console#getting-a-license). To learn more about authentication, including the User JWT, Developer JWT, and Vehicle JWT needed for accessing certain endpoints, please read: [Authentication Docs](https://docs.dimo.org/developer-platform/getting-started/developer-guide/authentication).
|
|
54
|
+
|
|
55
|
+
#### API Authentication
|
|
56
|
+
|
|
57
|
+
##### (Option 1) 3-Step Function Calls
|
|
58
|
+
|
|
59
|
+
The SDK offers 3 basic functions that maps to the steps listed in [Authentication](https://docs.dimo.org/developer-platform/getting-started/developer-guide/authentication): `generate_challenge`, `sign_challenge`, and `submit_challenge`. You can use them accordingly depending on how you build your application.
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
challenge = dimo.auth.generate_challenge(
|
|
63
|
+
client_id = '<client_id>',
|
|
64
|
+
domain = '<domain>',
|
|
65
|
+
address = '<address>'
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
signature = dimo.auth.sign_challenge(
|
|
69
|
+
message = challenge['challenge'],
|
|
70
|
+
private_key = '<private_key>'
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
tokens = dimo.auth.submit_challenge(
|
|
74
|
+
client_id = '<client_id>',
|
|
75
|
+
domain = '<domain>',
|
|
76
|
+
state = challenge['state'],
|
|
77
|
+
signature = signature
|
|
78
|
+
)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
##### (Option 2) Auth Endpoint Shortcut Function
|
|
82
|
+
|
|
83
|
+
As mentioned earlier, this is the streamlined function call to directly get the `developer_jwt`. The `address` field in challenge generation is omitted since it is essentially the `client_id` of your application per Developer License:
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
auth_header = dimo.auth.get_token(
|
|
87
|
+
client_id = '<client_id>',
|
|
88
|
+
domain = '<domain>',
|
|
89
|
+
private_key = '<private_key>'
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
# Store the Developer JWT from the auth_header dictionary
|
|
93
|
+
dev_jwt = auth_header["access_token"]
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Querying the DIMO REST API
|
|
97
|
+
|
|
98
|
+
The SDK uses the [requests](https://requests.readthedocs.io/en/latest/) library for making HTTP requests. You can perform a query like so:
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
def decode_vin():
|
|
102
|
+
device_makes = dimo.device_definitions.decode_vin(
|
|
103
|
+
developer_jwt = dev_jwt,
|
|
104
|
+
country_code = "USA",
|
|
105
|
+
vin = "<VIN>"
|
|
106
|
+
)
|
|
107
|
+
# Do something with the response
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
#### Query Parameters
|
|
111
|
+
|
|
112
|
+
For query parameters, simply feed in an input that matches with the expected query parameters:
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
dimo.device_definitions.search_device_definitions(
|
|
116
|
+
query = "Lexus gx 2023"
|
|
117
|
+
)
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
#### Vehicle JWTs
|
|
122
|
+
|
|
123
|
+
As the 2nd leg of the API authentication, applications may exchange for short-lived Vehicle JWTs for specific vehicles that granted privileges to the app. This uses the [DIMO Token Exchange API](https://docs.dimo.org/developer-platform/api-references/token-exchange-api).
|
|
124
|
+
|
|
125
|
+
For the end users of your application, they will need to share their vehicle permissions via the DIMO Mobile App or through your implementation of the [Login with DIMO flow](https://docs.dimo.org/developer-platform/getting-started/developer-guide/login-with-dimo). You can use the pre-built React component SDK, or redirect users to the URLs included in the documentation [here](https://docs.dimo.org/developer-platform/getting-started/developer-guide/login-with-dimo#dont-use-react).
|
|
126
|
+
|
|
127
|
+
Typically, any endpoints that uses a NFT `tokenId` in path parameters will require JWTs. You can use this flow to obtain a privilege token.
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
|
|
131
|
+
get_vehicle_jwt = dimo.token_exchange.exchange(
|
|
132
|
+
developer_jwt = dev_jwt,
|
|
133
|
+
# The Developer JWT you received using either the three step function calls, or the .get_token() shortcut
|
|
134
|
+
privileges=[1, 3, 4, 5],
|
|
135
|
+
# The privileges you've set for this vehicle, in list format (e.g. [1, 3, 4, 5])
|
|
136
|
+
token_id="<token_id>"
|
|
137
|
+
# The Vehicle NFT Token ID that you are requesting permission to
|
|
138
|
+
)
|
|
139
|
+
vehicle_jwt = get_vehicle_jwt['token']
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Once you have the privilege token, you can pipe it through to corresponding endpoints like so:
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
def my_trips():
|
|
146
|
+
trip_data = dimo.trips.trips(
|
|
147
|
+
vehicle_jwt=vehicle_jwt,
|
|
148
|
+
token_id=<token_id>
|
|
149
|
+
)
|
|
150
|
+
return trip_data
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Querying the DIMO GraphQL API
|
|
154
|
+
|
|
155
|
+
The SDK accepts any type of valid custom GraphQL queries, but we've also included a few sample queries to help you understand the DIMO GraphQL APIs.
|
|
156
|
+
|
|
157
|
+
#### Authentication for GraphQL API
|
|
158
|
+
|
|
159
|
+
The GraphQL entry points are designed almost identical to the REST API entry points. For any GraphQL API that requires auth headers (Telemetry API for example), you can use the same pattern as you would in the REST protected endpoints.
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
|
|
163
|
+
telemetry_data = dimo.telemetry.query(
|
|
164
|
+
vehicle_jwt=vehicle_jwt,
|
|
165
|
+
query= """
|
|
166
|
+
query {
|
|
167
|
+
some_valid_GraphQL_query
|
|
168
|
+
}
|
|
169
|
+
"""
|
|
170
|
+
)
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
#### Send a custom GraphQL query
|
|
174
|
+
|
|
175
|
+
To send a custom GraphQL query, you can simply call the `query` function on any GraphQL API Endpoints and pass in any valid GraphQL query. To check whether your GraphQL query is valid, please visit our [Identity API GraphQL Playground](https://identity-api.dimo.zone/) or [Telemetry API GraphQL Playground](https://telemetry-api.dimo.zone/).
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
my_query = """
|
|
179
|
+
{
|
|
180
|
+
vehicles (first:10) {
|
|
181
|
+
totalCount
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
"""
|
|
185
|
+
|
|
186
|
+
total_network_vehicles = dimo.identity.query(query=my_query)
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## How to Contribute to the SDK
|
|
190
|
+
|
|
191
|
+
You can read more about contributing [here](https://github.com/DIMO-Network/dimo-python-sdk/blob/dev-barrettk/CONTRIBUTING.md)
|
|
@@ -1,23 +1,15 @@
|
|
|
1
1
|
from .auth import Auth
|
|
2
|
-
from .
|
|
2
|
+
from .attestation import Attestation
|
|
3
3
|
from .device_definitions import DeviceDefinitions
|
|
4
|
-
from .devices import Devices
|
|
5
|
-
from .events import Events
|
|
6
4
|
from .token_exchange import TokenExchange
|
|
7
5
|
from .trips import Trips
|
|
8
|
-
from .user import User
|
|
9
6
|
from .valuations import Valuations
|
|
10
|
-
from .vehicle_signal_decoding import VehicleSignalDecoding
|
|
11
7
|
|
|
12
8
|
__all__ = [
|
|
13
9
|
"Auth",
|
|
14
|
-
"
|
|
10
|
+
"Attestation",
|
|
15
11
|
"DeviceDefinitions",
|
|
16
|
-
"Devices",
|
|
17
|
-
"Events",
|
|
18
12
|
"TokenExchange",
|
|
19
13
|
"Trips",
|
|
20
|
-
"User",
|
|
21
14
|
"Valuations",
|
|
22
|
-
"VehicleSignalDecoding",
|
|
23
15
|
]
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from dimo.errors import check_type
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Attestation:
|
|
5
|
+
def __init__(self, request_method, get_auth_headers):
|
|
6
|
+
self._request = request_method
|
|
7
|
+
self._get_auth_headers = get_auth_headers
|
|
8
|
+
|
|
9
|
+
def create_vin_vc(self, vehicle_jwt: str, token_id: int) -> dict:
|
|
10
|
+
check_type("vehicle_jwt", vehicle_jwt, str)
|
|
11
|
+
check_type("token_id", token_id, int)
|
|
12
|
+
params = {"force": True}
|
|
13
|
+
url = f"/v1/vc/vin/{token_id}"
|
|
14
|
+
return self._request(
|
|
15
|
+
"POST",
|
|
16
|
+
"Attestation",
|
|
17
|
+
url,
|
|
18
|
+
params=params,
|
|
19
|
+
headers=self._get_auth_headers(vehicle_jwt),
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
def create_pom_vc(self, vehicle_jwt: str, token_id: int) -> dict:
|
|
23
|
+
check_type("vehicle_jwt", vehicle_jwt, str)
|
|
24
|
+
check_type("token_id", token_id, int)
|
|
25
|
+
url = f"/v1/vc/pom/{token_id}"
|
|
26
|
+
return self._request(
|
|
27
|
+
"POST", "Attestation", url, headers=self._get_auth_headers(vehicle_jwt)
|
|
28
|
+
)
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
from dimo.errors import check_type
|
|
2
|
+
from dimo.errors import check_optional_type
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class DeviceDefinitions:
|
|
6
|
+
|
|
7
|
+
def __init__(self, request_method, get_auth_headers):
|
|
8
|
+
self._request = request_method
|
|
9
|
+
self._get_auth_headers = get_auth_headers
|
|
10
|
+
|
|
11
|
+
def decode_vin(self, developer_jwt: str, country_code: str, vin: str) -> dict:
|
|
12
|
+
check_type("developer_jwt", developer_jwt, str)
|
|
13
|
+
check_type("country_code", country_code, str)
|
|
14
|
+
check_type("vin", vin, str)
|
|
15
|
+
body = {
|
|
16
|
+
"countryCode": country_code,
|
|
17
|
+
"vin": vin,
|
|
18
|
+
}
|
|
19
|
+
response = self._request(
|
|
20
|
+
"POST",
|
|
21
|
+
"DeviceDefinitions",
|
|
22
|
+
"/device-definitions/decode-vin",
|
|
23
|
+
headers=self._get_auth_headers(developer_jwt),
|
|
24
|
+
data=body,
|
|
25
|
+
)
|
|
26
|
+
return response
|
|
27
|
+
|
|
28
|
+
def search_device_definitions(
|
|
29
|
+
self,
|
|
30
|
+
query=None,
|
|
31
|
+
make_slug=None,
|
|
32
|
+
model_slug=None,
|
|
33
|
+
year=None,
|
|
34
|
+
page=None,
|
|
35
|
+
page_size=None,
|
|
36
|
+
):
|
|
37
|
+
check_optional_type("query", query, str)
|
|
38
|
+
check_optional_type("make_slug", make_slug, str)
|
|
39
|
+
check_optional_type("model_slug", model_slug, str)
|
|
40
|
+
check_optional_type("year", year, int)
|
|
41
|
+
check_optional_type("page", page, int)
|
|
42
|
+
check_optional_type("page_size", page_size, int)
|
|
43
|
+
params = {
|
|
44
|
+
"query": query,
|
|
45
|
+
"makeSlug": make_slug,
|
|
46
|
+
"modelSlug": model_slug,
|
|
47
|
+
"year": year,
|
|
48
|
+
"page": page,
|
|
49
|
+
"pageSize": page_size,
|
|
50
|
+
}
|
|
51
|
+
response = self._request(
|
|
52
|
+
"GET",
|
|
53
|
+
"DeviceDefinitions",
|
|
54
|
+
"/device-definitions/search",
|
|
55
|
+
params=params,
|
|
56
|
+
)
|
|
57
|
+
return response
|
|
@@ -9,9 +9,13 @@ class TokenExchange:
|
|
|
9
9
|
self._get_auth_headers = get_auth_headers
|
|
10
10
|
|
|
11
11
|
def exchange(
|
|
12
|
-
self,
|
|
12
|
+
self,
|
|
13
|
+
developer_jwt: str,
|
|
14
|
+
privileges: list,
|
|
15
|
+
token_id: int,
|
|
16
|
+
env: str = "Production",
|
|
13
17
|
) -> dict:
|
|
14
|
-
check_type("
|
|
18
|
+
check_type("developer_jwt", developer_jwt, str)
|
|
15
19
|
check_type("privileges", privileges, list)
|
|
16
20
|
check_type("token_id", token_id, int)
|
|
17
21
|
body = {
|
|
@@ -23,7 +27,7 @@ class TokenExchange:
|
|
|
23
27
|
"POST",
|
|
24
28
|
"TokenExchange",
|
|
25
29
|
"/v1/tokens/exchange",
|
|
26
|
-
headers=self._get_auth_headers(
|
|
30
|
+
headers=self._get_auth_headers(developer_jwt),
|
|
27
31
|
data=body,
|
|
28
32
|
)
|
|
29
33
|
return response
|
|
@@ -7,8 +7,8 @@ class Trips:
|
|
|
7
7
|
self._request = request_method
|
|
8
8
|
self._get_auth_headers = get_auth_headers
|
|
9
9
|
|
|
10
|
-
def trips(self,
|
|
11
|
-
check_type("
|
|
10
|
+
def trips(self, vehicle_jwt: str, token_id: int, page=None) -> dict:
|
|
11
|
+
check_type("vehicle_jwt", vehicle_jwt, str)
|
|
12
12
|
check_type("token_id", token_id, int)
|
|
13
13
|
params = {}
|
|
14
14
|
if page is not None:
|
|
@@ -19,5 +19,5 @@ class Trips:
|
|
|
19
19
|
"Trips",
|
|
20
20
|
url,
|
|
21
21
|
params=params,
|
|
22
|
-
headers=self._get_auth_headers(
|
|
22
|
+
headers=self._get_auth_headers(vehicle_jwt),
|
|
23
23
|
)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from dimo.errors import check_type
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Valuations:
|
|
5
|
+
|
|
6
|
+
def __init__(self, request_method, get_auth_headers):
|
|
7
|
+
self._request = request_method
|
|
8
|
+
self._get_auth_headers = get_auth_headers
|
|
9
|
+
|
|
10
|
+
def get_valuations(self, vehicle_jwt: str, token_id: int) -> dict:
|
|
11
|
+
check_type("vehicle_jwt", vehicle_jwt, str)
|
|
12
|
+
check_type("token_id", token_id, int)
|
|
13
|
+
url = f"/v2/vehicles/{token_id}/valuations"
|
|
14
|
+
return self._request(
|
|
15
|
+
"GET", "Valuations", url, headers=self._get_auth_headers(vehicle_jwt)
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
def offers_lookup(self, vehicle_jwt: str, token_id: int) -> None:
|
|
19
|
+
check_type("vehicle_jwt", vehicle_jwt, str)
|
|
20
|
+
check_type("token_id", token_id, int)
|
|
21
|
+
url = f"v2/vehicles/{token_id}/instant-offer"
|
|
22
|
+
return self._request(
|
|
23
|
+
"GET", "Valuations", url, headers=self._get_auth_headers(vehicle_jwt)
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
def list_vehicle_offers(self, vehicle_jwt: str, token_id: int) -> dict:
|
|
27
|
+
check_type("vehicle_jwt", vehicle_jwt, str)
|
|
28
|
+
check_type("token_id", token_id, int)
|
|
29
|
+
url = f"/v2/vehicles/{token_id}/offers"
|
|
30
|
+
return self._request(
|
|
31
|
+
"GET", "Valuations", url, headers=self._get_auth_headers(vehicle_jwt)
|
|
32
|
+
)
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
from .api.attestation import Attestation
|
|
2
2
|
from .api.auth import Auth
|
|
3
|
-
from .api.device_data import DeviceData
|
|
4
3
|
from .api.device_definitions import DeviceDefinitions
|
|
5
|
-
from .api.devices import Devices
|
|
6
|
-
from .api.events import Events
|
|
7
4
|
from .api.token_exchange import TokenExchange
|
|
8
5
|
from .api.trips import Trips
|
|
9
|
-
from .api.user import User
|
|
10
6
|
from .api.valuations import Valuations
|
|
11
|
-
from .api.vehicle_signal_decoding import VehicleSignalDecoding
|
|
12
7
|
|
|
13
8
|
from .graphql.identity import Identity
|
|
14
9
|
from .graphql.telemetry import Telemetry
|
|
@@ -25,19 +20,12 @@ class DIMO:
|
|
|
25
20
|
self.urls = dimo_environment[env]
|
|
26
21
|
self.attestation = Attestation(self.request, self._get_auth_headers)
|
|
27
22
|
self.auth = Auth(self.request, self._get_auth_headers, self.env)
|
|
28
|
-
self.device_data = DeviceData(self.request, self._get_auth_headers)
|
|
29
23
|
self.device_definitions = DeviceDefinitions(
|
|
30
24
|
self.request, self._get_auth_headers
|
|
31
25
|
)
|
|
32
|
-
self.devices = Devices(self.request, self._get_auth_headers)
|
|
33
|
-
self.events = Events(self.request, self._get_auth_headers)
|
|
34
26
|
self.token_exchange = TokenExchange(self.request, self._get_auth_headers)
|
|
35
27
|
self.trips = Trips(self.request, self._get_auth_headers)
|
|
36
|
-
self.user = User(self.request, self._get_auth_headers)
|
|
37
28
|
self.valuations = Valuations(self.request, self._get_auth_headers)
|
|
38
|
-
self.vehicle_signal_decoding = VehicleSignalDecoding(
|
|
39
|
-
self.request, self._get_auth_headers
|
|
40
|
-
)
|
|
41
29
|
self.identity = Identity(self)
|
|
42
30
|
self.telemetry = Telemetry(self)
|
|
43
31
|
self._session = Request.session
|
|
@@ -3,30 +3,22 @@ dimo_environment = {
|
|
|
3
3
|
"Attestation": "https://attestation-api.dimo.zone",
|
|
4
4
|
"Auth": "https://auth.dimo.zone",
|
|
5
5
|
"Identity": "https://identity-api.dimo.zone/query",
|
|
6
|
-
"Devices": "https://devices-api.dimo.zone",
|
|
7
|
-
"DeviceData": "https://device-data-api.dimo.zone",
|
|
8
6
|
"DeviceDefinitions": "https://device-definitions-api.dimo.zone",
|
|
9
|
-
"Events": "https://events-api.dimo.zone",
|
|
10
7
|
"Telemetry": "https://telemetry-api.dimo.zone/query",
|
|
11
8
|
"TokenExchange": "https://token-exchange-api.dimo.zone",
|
|
12
9
|
"Trips": "https://trips-api.dimo.zone",
|
|
13
10
|
"User": "https://users-api.dimo.zone",
|
|
14
11
|
"Valuations": "https://valuations-api.dimo.zone",
|
|
15
|
-
"VehicleSignalDecoding": "https://vehicle-signal-decoding.dimo.zone",
|
|
16
12
|
},
|
|
17
13
|
"Dev": {
|
|
18
14
|
"Attestation": "https://attestation-api.dev.dimo.zone",
|
|
19
15
|
"Auth": "https://auth.dev.dimo.zone",
|
|
20
16
|
"Identity": "https://identity-api.dev.dimo.zone/query",
|
|
21
|
-
"Devices": "https://devices-api.dev.dimo.zone",
|
|
22
|
-
"DeviceData": "https://device-data-api.dev.dimo.zone",
|
|
23
17
|
"DeviceDefinitions": "https://device-definitions-api.dev.dimo.zone",
|
|
24
|
-
"Events": "https://events-api.dev.dimo.zone",
|
|
25
18
|
"Telemetry": "https://telemetry-api.dev.dimo.zone/query",
|
|
26
19
|
"TokenExchange": "https://token-exchange-api.dev.dimo.zone",
|
|
27
20
|
"Trips": "https://trips-api.dev.dimo.zone",
|
|
28
21
|
"User": "https://users-api.dev.dimo.zone",
|
|
29
22
|
"Valuations": "https://valuations-api.dev.dimo.zone",
|
|
30
|
-
"VehicleSignalDecoding": "https://vehicle-signal-decoding.dev.dimo.zone",
|
|
31
23
|
},
|
|
32
24
|
}
|