dimo-python-sdk 0.0.1__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-0.0.1/LICENSE +201 -0
- dimo_python_sdk-0.0.1/PKG-INFO +385 -0
- dimo_python_sdk-0.0.1/README.md +368 -0
- dimo_python_sdk-0.0.1/dimo/__init__.py +3 -0
- dimo_python_sdk-0.0.1/dimo/auth.py +85 -0
- dimo_python_sdk-0.0.1/dimo/constants.py +10 -0
- dimo_python_sdk-0.0.1/dimo/device_data.py +118 -0
- dimo_python_sdk-0.0.1/dimo/device_definitions.py +39 -0
- dimo_python_sdk-0.0.1/dimo/devices.py +252 -0
- dimo_python_sdk-0.0.1/dimo/dimo.py +79 -0
- dimo_python_sdk-0.0.1/dimo/environments.py +30 -0
- dimo_python_sdk-0.0.1/dimo/events.py +13 -0
- dimo_python_sdk-0.0.1/dimo/identity.py +222 -0
- dimo_python_sdk-0.0.1/dimo/request.py +33 -0
- dimo_python_sdk-0.0.1/dimo/telemetry.py +131 -0
- dimo_python_sdk-0.0.1/dimo/test.py +92 -0
- dimo_python_sdk-0.0.1/dimo/token_exchange.py +22 -0
- dimo_python_sdk-0.0.1/dimo/trips.py +18 -0
- dimo_python_sdk-0.0.1/dimo/user.py +53 -0
- dimo_python_sdk-0.0.1/dimo/valuations.py +32 -0
- dimo_python_sdk-0.0.1/dimo/vehicle_signal_decoding.py +99 -0
- dimo_python_sdk-0.0.1/dimo_python_sdk.egg-info/PKG-INFO +385 -0
- dimo_python_sdk-0.0.1/dimo_python_sdk.egg-info/SOURCES.txt +26 -0
- dimo_python_sdk-0.0.1/dimo_python_sdk.egg-info/dependency_links.txt +1 -0
- dimo_python_sdk-0.0.1/dimo_python_sdk.egg-info/requires.txt +2 -0
- dimo_python_sdk-0.0.1/dimo_python_sdk.egg-info/top_level.txt +1 -0
- dimo_python_sdk-0.0.1/pyproject.toml +28 -0
- dimo_python_sdk-0.0.1/setup.cfg +4 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2024 DIMO Foundation
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: dimo-python-sdk
|
|
3
|
+
Version: 0.0.1
|
|
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: web3>=6.20.0
|
|
17
|
+
|
|
18
|
+
# DIMO Python Developer SDK
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
You can install the SDK using `pip`
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install dimo-python-sdk
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Unit Testing
|
|
29
|
+
|
|
30
|
+
Coming Soon
|
|
31
|
+
|
|
32
|
+
## API Documentation
|
|
33
|
+
|
|
34
|
+
Please visit the DIMO [Developer Documentation](https://docs.dimo.zone/developer-platform) to learn more about building on DIMO and detailed information on the API.
|
|
35
|
+
|
|
36
|
+
## How to Use the SDK
|
|
37
|
+
|
|
38
|
+
Importing the SDK:
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from dimo import DIMO
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Initiate the SDK depending on the envionrment of your interest, we currently support both `Production` and `Dev` environments:
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
dimo = DIMO("Production")
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
or
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
dimo = DIMO("Dev")
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Developer License
|
|
57
|
+
|
|
58
|
+
As part of the authentication process, you will need to register a set of `client_id` and `redirect_uri` (aka `domain`) on the DIMO Network. The [DIMO Developer License](https://docs.dimo.zone/developer-platform/getting-started/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:
|
|
59
|
+
|
|
60
|
+
1. [Approving the Dev License to use of $DIMO](https://docs.dimo.zone/developer-platform/getting-started/developer-license/licensing-process#step-1-approving-the-dev-license-to-use-of-usddimo)
|
|
61
|
+
2. [Issue the Dev License](https://docs.dimo.zone/developer-platform/getting-started/developer-license/licensing-process#step-2-issue-the-dev-license) (Get a `client_id` assigned to you)
|
|
62
|
+
3. [Configuring the Dev License](https://docs.dimo.zone/developer-platform/getting-started/developer-license/licensing-process#step-3-configuring-the-dev-license) (Set `redirect_uri` aka `domain`)
|
|
63
|
+
4. [Enable Signer(s)](https://docs.dimo.zone/developer-platform/getting-started/developer-license/licensing-process#step-4-enable-signer-s), the `private_key` of this signer will be required for API access
|
|
64
|
+
|
|
65
|
+
### DIMO Streams
|
|
66
|
+
|
|
67
|
+
Coming Soon
|
|
68
|
+
|
|
69
|
+
### Authentication
|
|
70
|
+
|
|
71
|
+
In order to authenticate and access private API data, you will need to [authenticate with the DIMO Auth Server](https://docs.dimo.zone/developer-platform/getting-started/authentication). The SDK provides you with all the steps needed in the [Wallet-based Authentication Flow](https://docs.dimo.zone/developer-platform/getting-started/authentication/wallet-based-authentication-flow) in case you need it to build a wallet integration around it. We also offer expedited functions to streamline the multiple calls needed.
|
|
72
|
+
|
|
73
|
+
#### Prerequisites for Authentication
|
|
74
|
+
|
|
75
|
+
1. A valid Developer License.
|
|
76
|
+
2. Access to a signer wallet and its private keys. Best practice is to rotate this frequently for security purposes.
|
|
77
|
+
|
|
78
|
+
> At its core, a Web3 wallet is a software program that stores private keys, which are necessary for accessing blockchain networks and conducting transactions. Unlike traditional wallets, which store physical currency, Web3 wallets store digital assets such as Bitcoin, Ethereum, and NFTs.
|
|
79
|
+
|
|
80
|
+
NOTE: The signer wallet here is recommended to be different from the spender or holder wallet for your [DIMO Developer License](https://github.com/DIMO-Network/developer-license-donotus).
|
|
81
|
+
|
|
82
|
+
#### API Authentication
|
|
83
|
+
|
|
84
|
+
##### (Option 1) 3-Step Function Calls
|
|
85
|
+
|
|
86
|
+
The SDK offers 3 basic functions that maps to the steps listed in [Wallet-based Authentication Flow](https://docs.dimo.zone/developer-platform/getting-started/authentication/wallet-based-authentication-flow): `generate_challenge`, `sign_challenge`, and `submit_challenge`. You can use them accordingly depending on how you build your application.
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
challenge = await dimo.auth.generate_challenge(
|
|
90
|
+
client_id: '<client_id>',
|
|
91
|
+
domain: '<domain>',
|
|
92
|
+
address: '<address>'
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
signature = await dimo.auth.sign_challenge(
|
|
96
|
+
message: challenge['challenge'],
|
|
97
|
+
private_key: '<private_key>'
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
tokens = await dimo.auth.submit_challenge(
|
|
101
|
+
client_id: '<client_id>',
|
|
102
|
+
domain: '<domain>',
|
|
103
|
+
state: challenge['state'],
|
|
104
|
+
signature: signature
|
|
105
|
+
)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
##### (Option 2) Auth Endpoint Shortcut Function
|
|
109
|
+
|
|
110
|
+
As mentioned earlier, this is the streamlined function call to directly get the `access_token`. The `address` field in challenge generation is omitted since it is essentially the `client_id` of your application per Developer License:
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
auth_header = await dimo.auth.get_token(
|
|
114
|
+
client_id: '<client_id>',
|
|
115
|
+
domain: '<domain>',
|
|
116
|
+
private_key: '<private_key>'
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
# Store the access_token from the auth_header dictionary
|
|
120
|
+
access_token = auth_header["access_token"]
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
##### (Option 3) Credentials.json File
|
|
124
|
+
|
|
125
|
+
Coming Soon
|
|
126
|
+
|
|
127
|
+
### Querying the DIMO REST API
|
|
128
|
+
|
|
129
|
+
The SDK supports async/await syntax using the [asyncio](https://docs.python.org/3/library/asyncio.html) library, and for making HTTP requests using the [requests](https://requests.readthedocs.io/en/latest/) library.
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
async def main():
|
|
133
|
+
device_makes = await dimo.device_definitions.list_device_makes()
|
|
134
|
+
# Do something with the response
|
|
135
|
+
|
|
136
|
+
if __name__ == "__main__":
|
|
137
|
+
asyncio.run(main())
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
#### Query Parameters
|
|
141
|
+
|
|
142
|
+
For query parameters, simply feed in an input that matches with the expected query parameters:
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
await dimo.device_definitions.get_by_mmy(
|
|
146
|
+
make="<vehicle_make>",
|
|
147
|
+
model="<vehicle_model>",
|
|
148
|
+
year=2024
|
|
149
|
+
)
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
#### Path Parameters
|
|
153
|
+
|
|
154
|
+
Path parameters work similarly - simply feed in an input, such as id.
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
await dimo.device_definitions.get_by_id(id='26G4j1YDKZhFeCsn12MAlyU3Y2H')
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
#### Body Parameters
|
|
161
|
+
|
|
162
|
+
#### Privilege Tokens
|
|
163
|
+
|
|
164
|
+
As the 2nd leg of the API authentication, applications may exchange for short-lived privilege tokens for specific vehicles that granted privileges to the app. This uses the [DIMO Token Exchange API](https://docs.dimo.zone/developer-platform/api-references/dimo-protocol/token-exchange-api/token-exchange-api-endpoints).
|
|
165
|
+
|
|
166
|
+
For the end users of your application, they will need to share their vehicle permissions via the DIMO Mobile App or through your own implementation of privilege sharing functions - this should be built on the [`setPrivilege` function of the DIMO Vehicle Smart Contract](https://polygonscan.com/address/0xba5738a18d83d41847dffbdc6101d37c69c9b0cf#writeProxyContract).
|
|
167
|
+
|
|
168
|
+
Typically, any endpoints that uses a NFT `tokenId` in path parameters will require privilege tokens. You can get the privilege token and pipe it through to corresponding endpoints like this:
|
|
169
|
+
|
|
170
|
+
```python
|
|
171
|
+
privilege_token = await dimo.token_exchange.exchange(access_token, privileges=[1,3,4], token_id=<vehicle_token_id>)
|
|
172
|
+
|
|
173
|
+
await dimo.device_data.get_vehicle_status(token=privilege_token, vehicle_id=<vehicle_token_id>)
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Querying the DIMO GraphQL API
|
|
177
|
+
|
|
178
|
+
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.
|
|
179
|
+
|
|
180
|
+
#### Authentication for GraphQL API
|
|
181
|
+
|
|
182
|
+
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.
|
|
183
|
+
|
|
184
|
+
```python
|
|
185
|
+
privilege_token = await dimo.token_exchange.exchange(access_token, privileges=[1,3,4], token_id=<vehicle_token_id>)
|
|
186
|
+
|
|
187
|
+
telemetry = await dimo.telemetry.query(
|
|
188
|
+
token=privilege_token,
|
|
189
|
+
query= """
|
|
190
|
+
query {
|
|
191
|
+
some_valid_GraphQL_query
|
|
192
|
+
}
|
|
193
|
+
"""
|
|
194
|
+
)
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
#### Send a custom GraphQL query
|
|
198
|
+
|
|
199
|
+
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/).
|
|
200
|
+
|
|
201
|
+
```python
|
|
202
|
+
my_query = """
|
|
203
|
+
{
|
|
204
|
+
vehicles (first:10) {
|
|
205
|
+
totalCount
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
"""
|
|
209
|
+
|
|
210
|
+
total_network_vehicles = await dimo.identity.query(query=my_query)
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
#### Built in graphQL Queries: Identity API (Common Queries)
|
|
214
|
+
|
|
215
|
+
##### .count_dimo_vehicles()
|
|
216
|
+
|
|
217
|
+
Returns the first 10 vehicles
|
|
218
|
+
|
|
219
|
+
_Example:_
|
|
220
|
+
|
|
221
|
+
```python
|
|
222
|
+
first_10_vehicles = await dimo.identity.count_dimo_vehicles()
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
##### .list_vehicle_definitions_per_address()
|
|
226
|
+
|
|
227
|
+
Requires an **address** and a **limit**. Returns vehicle definitions (limited by requested limit) for the given owner address.
|
|
228
|
+
|
|
229
|
+
_Example:_
|
|
230
|
+
|
|
231
|
+
```python
|
|
232
|
+
my_vehicle_definitions = await dimo.identity.list_vehicle_definitions_per_address(
|
|
233
|
+
address = "<0x address>",
|
|
234
|
+
limit = 10
|
|
235
|
+
)
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
##### .mmy_by_owner()
|
|
239
|
+
|
|
240
|
+
Requires an **address** and a **limit**. Returns the makes, models, and years(limited by requested limit) for the given owner address.
|
|
241
|
+
|
|
242
|
+
_Example:_
|
|
243
|
+
|
|
244
|
+
```python
|
|
245
|
+
my_mmy = await dimo.identity.mmy_by_owner(
|
|
246
|
+
address = "<0x address>",
|
|
247
|
+
limit = 10
|
|
248
|
+
)
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
##### .list_token_ids_privileges_by_owner()
|
|
252
|
+
|
|
253
|
+
Requires an **address** a **vehicle_limit**, and a **privileges_limit**. Returns the Token IDs and privileges for a given owner address.
|
|
254
|
+
|
|
255
|
+
_Example:_
|
|
256
|
+
|
|
257
|
+
```python
|
|
258
|
+
my_vehicle_id_and_privileges = await dimo.identity.list_vehicle_definitions_per_address(
|
|
259
|
+
address = "<0x address>",
|
|
260
|
+
vehicle_limit = 4,
|
|
261
|
+
privileges_limit = 4,
|
|
262
|
+
)
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
##### .list_token_ids_granted_to_dev_by_owner()
|
|
266
|
+
|
|
267
|
+
Requires a **dev_address**, **owner_address**, and **limit**. Returns the Token IDs granted to a developer from an owner.
|
|
268
|
+
|
|
269
|
+
_Example:_
|
|
270
|
+
|
|
271
|
+
```python
|
|
272
|
+
my_vehicle_definitions = await dimo.identity.list_token_ids_granted_to_dev_by_owner(
|
|
273
|
+
dev_address = "<0x dev address>",
|
|
274
|
+
owner_address = "0x owner address>",
|
|
275
|
+
limit = 10
|
|
276
|
+
)
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
##### .dcn_by_owner()
|
|
280
|
+
|
|
281
|
+
Requires an **address** and **limit**. Returns a list of DCNs attached to the vehicles owned for a given owner.
|
|
282
|
+
|
|
283
|
+
_Example:_
|
|
284
|
+
|
|
285
|
+
```python
|
|
286
|
+
my_vehicle_definitions = await dimo.identity.dcn_by_owner(
|
|
287
|
+
address = "<0x address>",
|
|
288
|
+
limit = 10
|
|
289
|
+
)
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
##### .mmy_by_token_id
|
|
293
|
+
|
|
294
|
+
Requires a **token_id**. Returns the make, model, year and Token IDs for a given vehicle Token ID.
|
|
295
|
+
|
|
296
|
+
_Example:_
|
|
297
|
+
|
|
298
|
+
```python
|
|
299
|
+
my_mmy_token_id = await dimo.identity.mmy_by_token_id(token_id=21957)
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
##### .rewards_by_owner
|
|
303
|
+
|
|
304
|
+
Requires an **address**. Returns the rewards data for a given owner.
|
|
305
|
+
|
|
306
|
+
_Example:_
|
|
307
|
+
|
|
308
|
+
```python
|
|
309
|
+
my_rewards = await dimo.identity.rewards_by_owner(address="<0x address>")
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
##### .rewards_history_by_owner
|
|
313
|
+
|
|
314
|
+
Requires an **address** and **limit**. Returns the rewards history data for a given owner.
|
|
315
|
+
|
|
316
|
+
_Example:_
|
|
317
|
+
|
|
318
|
+
```python
|
|
319
|
+
my_rewards_history = await dimo.identity.rewards_history_by_owner(address="<0x address>", limit=50)
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
#### Built in graphQL Queries: Telemetry API (Common Queries)
|
|
323
|
+
|
|
324
|
+
Note, that the below queries for the Telemetry API require providing a privilege token (see above on how to obtain this token.)
|
|
325
|
+
|
|
326
|
+
##### .get_signals_latest()
|
|
327
|
+
|
|
328
|
+
Requires a **privilege_token** and **token_id**. Returns latest vehicle signals based on a provided Token ID.
|
|
329
|
+
|
|
330
|
+
_Example:_
|
|
331
|
+
|
|
332
|
+
```python
|
|
333
|
+
my_latest_signals = await dimo.telemetry.get_signals_latest(
|
|
334
|
+
token=my_privileged_token, token_id=12345)
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
##### .get_daily_signals_autopi()
|
|
338
|
+
|
|
339
|
+
Requires a **privilege_token**, **token_id**, **start_date**, and **end_date**. Returns daily vehicle signals based on the specified time range for an autopi device.
|
|
340
|
+
|
|
341
|
+
_Example:_
|
|
342
|
+
|
|
343
|
+
```python
|
|
344
|
+
my_daily_signals = await dimo.telemetry.get_daily_signals_autopi(
|
|
345
|
+
token=my_privileged_token,
|
|
346
|
+
token_id=12345,
|
|
347
|
+
start_date="2024-07-04T18:00:00Z",
|
|
348
|
+
end_date="2024-07-12T18:00:00Z")
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
##### .get_daily_average_speed()
|
|
352
|
+
|
|
353
|
+
Requires a **privilege_token**, **token_id**, **start_date**, and **end_date**. Returns the daily average speed for a specified vehicle, based on the specified time range.
|
|
354
|
+
|
|
355
|
+
_Example:_
|
|
356
|
+
|
|
357
|
+
```python
|
|
358
|
+
my_daily_avg_speed = await dimo.telemetry.get_daily_avg_speed(
|
|
359
|
+
token=my_privileged_token,
|
|
360
|
+
token_id=12345,
|
|
361
|
+
start_date="2024-07-04T18:00:00Z",
|
|
362
|
+
end_date="2024-07-12T18:00:00Z")
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
##### .get_daily_max_speed()
|
|
366
|
+
|
|
367
|
+
Requires a **privilege_token**, **token_id**, **start_date**, and **end_date**. Returns the daily MAX speed for a specified vehicle, based on the specified time range.
|
|
368
|
+
|
|
369
|
+
_Example:_
|
|
370
|
+
|
|
371
|
+
```python
|
|
372
|
+
my_daily_max_speed = await dimo.telemetry.get_daily_max_speed(
|
|
373
|
+
token=my_privileged_token,
|
|
374
|
+
token_id=12345,
|
|
375
|
+
start_date="2024-07-04T18:00:00Z",
|
|
376
|
+
end_date="2024-07-12T18:00:00Z")
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
## How to Contribute to the SDK
|
|
380
|
+
|
|
381
|
+
You can read more about contributing [here](https://github.com/DIMO-Network/dimo-python-sdk/blob/dev-barrettk/CONTRIBUTING.md)
|
|
382
|
+
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
```
|