ms-graph 1.5.2__py3-none-any.whl
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.
- ms_graph/__init__.py +5 -0
- ms_graph/client.py +546 -0
- ms_graph/drive_items.py +296 -0
- ms_graph/drives.py +384 -0
- ms_graph/groups.py +51 -0
- ms_graph/logger/logger_setup.py +7 -0
- ms_graph/mail.py +1073 -0
- ms_graph/notes.py +276 -0
- ms_graph/personal_contacts.py +226 -0
- ms_graph/search.py +48 -0
- ms_graph/session.py +182 -0
- ms_graph/users.py +45 -0
- ms_graph/utils/range.py +331 -0
- ms_graph/workbooks_and_charts/__init__.py +23 -0
- ms_graph/workbooks_and_charts/application.py +109 -0
- ms_graph/workbooks_and_charts/comments.py +159 -0
- ms_graph/workbooks_and_charts/enums.py +252 -0
- ms_graph/workbooks_and_charts/range.py +694 -0
- ms_graph/workbooks_and_charts/table.py +467 -0
- ms_graph/workbooks_and_charts/workbook.py +253 -0
- ms_graph/workbooks_and_charts/worksheets.py +636 -0
- ms_graph-1.5.2.dist-info/METADATA +319 -0
- ms_graph-1.5.2.dist-info/RECORD +25 -0
- ms_graph-1.5.2.dist-info/WHEEL +4 -0
- ms_graph-1.5.2.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
import json
|
|
3
|
+
from typing import Union
|
|
4
|
+
from ms_graph.session import GraphSession
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def build_endpoint(inputs: dict) -> str:
|
|
8
|
+
"""Builds the endpoint for the Range object.
|
|
9
|
+
|
|
10
|
+
### Parameters
|
|
11
|
+
----
|
|
12
|
+
inputs : dict
|
|
13
|
+
The `locals()` of the function.
|
|
14
|
+
|
|
15
|
+
### Raises
|
|
16
|
+
----
|
|
17
|
+
ValueError:
|
|
18
|
+
If an item id or item path is not specified
|
|
19
|
+
an error will be raised.
|
|
20
|
+
|
|
21
|
+
### Returns
|
|
22
|
+
----
|
|
23
|
+
str:
|
|
24
|
+
The full URL path.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
item_id = inputs.get("item_id", None)
|
|
28
|
+
item_path = inputs.get("item_path", None)
|
|
29
|
+
worksheet_name_or_id = inputs.get("worksheet_name_or_id", None)
|
|
30
|
+
address = inputs.get("address", None)
|
|
31
|
+
name = inputs.get("name", None)
|
|
32
|
+
table_name_or_id = inputs.get("table_name_or_id", None)
|
|
33
|
+
column_name_or_id = inputs.get("column_name_or_id", None)
|
|
34
|
+
|
|
35
|
+
if item_id:
|
|
36
|
+
workbook_path = f"/me/drive/items/{item_id}/workbook/"
|
|
37
|
+
elif item_path:
|
|
38
|
+
workbook_path = f"/me/drive/root:/{item_path}:/workbook/"
|
|
39
|
+
else:
|
|
40
|
+
raise ValueError("Must specify an Item ID or Item Path.")
|
|
41
|
+
|
|
42
|
+
if (worksheet_name_or_id and address):
|
|
43
|
+
range_path = f"worksheets/{worksheet_name_or_id}/range(address='{address}')"
|
|
44
|
+
elif name:
|
|
45
|
+
range_path = f"names/{name}/range"
|
|
46
|
+
elif (table_name_or_id and column_name_or_id):
|
|
47
|
+
range_path = f"tables/{table_name_or_id}/columns/{column_name_or_id}/range"
|
|
48
|
+
|
|
49
|
+
return workbook_path + range_path
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class Table:
|
|
53
|
+
|
|
54
|
+
"""
|
|
55
|
+
### Overview:
|
|
56
|
+
----
|
|
57
|
+
Represents an Excel Table Object, also called an
|
|
58
|
+
Excel List Object.
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
def __init__(self, session: object) -> None:
|
|
62
|
+
"""Initializes the `Table` object.
|
|
63
|
+
|
|
64
|
+
# Parameters
|
|
65
|
+
----
|
|
66
|
+
session : object
|
|
67
|
+
An authenticated session for our Microsoft Graph Client.
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
# Set the session.
|
|
71
|
+
self.graph_session: GraphSession = session
|
|
72
|
+
|
|
73
|
+
@staticmethod
|
|
74
|
+
def build_endpoint(**kwargs):
|
|
75
|
+
""" Build endpoint for MS Graph Session depending
|
|
76
|
+
and the resource required to be called """
|
|
77
|
+
|
|
78
|
+
item_id = kwargs.get("item_id", None)
|
|
79
|
+
workbook_path = kwargs.get("workbook_path", None)
|
|
80
|
+
item_path = kwargs.get("item_path", None)
|
|
81
|
+
worksheet_name_or_id = kwargs.get("worksheet_name_or_id", None)
|
|
82
|
+
table_name_or_id = kwargs.get("table_name_or_id", None)
|
|
83
|
+
endpoint_resource = kwargs.get("endpoint_resource", None)
|
|
84
|
+
|
|
85
|
+
if item_id:
|
|
86
|
+
workbook_path = f"/me/drive/items/{item_id}/workbook/"
|
|
87
|
+
elif item_path:
|
|
88
|
+
workbook_path = f"/me/drive/root:/{item_path}:/workbook/"
|
|
89
|
+
else:
|
|
90
|
+
raise ValueError("Must specify an Item ID or Item Path.")
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
if (worksheet_name_or_id and table_name_or_id):
|
|
94
|
+
table_path = f"worksheets/{worksheet_name_or_id}/tables/{table_name_or_id}"
|
|
95
|
+
elif table_name_or_id:
|
|
96
|
+
table_path = f"tables/{table_name_or_id}"
|
|
97
|
+
|
|
98
|
+
endpoint = workbook_path + table_path
|
|
99
|
+
|
|
100
|
+
if endpoint_resource == "add":
|
|
101
|
+
endpoint = endpoint + "/add"
|
|
102
|
+
elif endpoint_resource == "rows":
|
|
103
|
+
endpoint = endpoint + "/rows"
|
|
104
|
+
elif endpoint_resource == "columns":
|
|
105
|
+
endpoint = endpoint + "/columns"
|
|
106
|
+
elif endpoint_resource == "range":
|
|
107
|
+
endpoint = endpoint + "/range"
|
|
108
|
+
elif endpoint_resource == "headerrowrange":
|
|
109
|
+
endpoint = endpoint + "/headerrowrange"
|
|
110
|
+
elif endpoint_resource == "databodyrange":
|
|
111
|
+
endpoint = endpoint + "/databodyrange"
|
|
112
|
+
|
|
113
|
+
return endpoint
|
|
114
|
+
|
|
115
|
+
def get_table(
|
|
116
|
+
self,
|
|
117
|
+
table_name_or_id: str = None,
|
|
118
|
+
worksheet_name_or_id: str = None,
|
|
119
|
+
item_id: str = None,
|
|
120
|
+
item_path: str = None,
|
|
121
|
+
) -> dict:
|
|
122
|
+
"""Retrieve the properties and relationships of table object.
|
|
123
|
+
|
|
124
|
+
### Parameters
|
|
125
|
+
----
|
|
126
|
+
table_name_or_id : str (optional, Default=None)
|
|
127
|
+
The name of the table or the resource id.
|
|
128
|
+
|
|
129
|
+
worksheet_name_or_id : str (optional, Default=None)
|
|
130
|
+
The name of the worksheet or the resource id.
|
|
131
|
+
|
|
132
|
+
item_id : str (optional, Default=None)
|
|
133
|
+
The Drive Item Resource ID.
|
|
134
|
+
|
|
135
|
+
item_path : str (optional, Default=None)
|
|
136
|
+
The Item Path. An Example would be the following:
|
|
137
|
+
`/TestFolder/TestFile.txt`
|
|
138
|
+
|
|
139
|
+
### Returns
|
|
140
|
+
----
|
|
141
|
+
dict:
|
|
142
|
+
A WorkbookTable object.
|
|
143
|
+
"""
|
|
144
|
+
|
|
145
|
+
endpoint = self.build_endpoint(
|
|
146
|
+
table_name_or_id=table_name_or_id,
|
|
147
|
+
worksheet_name_or_id=worksheet_name_or_id,
|
|
148
|
+
item_id=item_id,
|
|
149
|
+
item_path=item_path
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
content = self.graph_session.make_request(
|
|
153
|
+
method="get",
|
|
154
|
+
endpoint=endpoint
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
return content
|
|
158
|
+
|
|
159
|
+
def add_table(
|
|
160
|
+
self,
|
|
161
|
+
address: str,
|
|
162
|
+
has_headers: bool,
|
|
163
|
+
table_name_or_id: str = None,
|
|
164
|
+
worksheet_name_or_id: str = None,
|
|
165
|
+
item_id: str = None,
|
|
166
|
+
item_path: str = None,
|
|
167
|
+
) -> dict:
|
|
168
|
+
"""Create a new WorkbookTable Object.
|
|
169
|
+
|
|
170
|
+
### Overview
|
|
171
|
+
----
|
|
172
|
+
The range source address determines the worksheet under
|
|
173
|
+
which the table will be added. If the table cannot be
|
|
174
|
+
added (e.g., because the address is invalid, or the table
|
|
175
|
+
would overlap with another table), an error will be thrown.
|
|
176
|
+
|
|
177
|
+
### Parameters
|
|
178
|
+
----
|
|
179
|
+
address : str
|
|
180
|
+
Address or name of the range object representing the
|
|
181
|
+
data source. If the address does not contain a sheet
|
|
182
|
+
name, the currently-active sheet is used.
|
|
183
|
+
|
|
184
|
+
imported has column labels. If the source does not
|
|
185
|
+
contain headers (i.e,. when this property set to
|
|
186
|
+
`False`), Excel will automatically generate header
|
|
187
|
+
shifting the data down by one row.
|
|
188
|
+
|
|
189
|
+
table_name_or_id : str (optional, Default=None)
|
|
190
|
+
The name of the table or the resource id.
|
|
191
|
+
|
|
192
|
+
worksheet_name_or_id : str (optional, Default=None)
|
|
193
|
+
The name of the worksheet or the resource id.
|
|
194
|
+
|
|
195
|
+
item_id : str (optional, Default=None)
|
|
196
|
+
The Drive Item Resource ID.
|
|
197
|
+
|
|
198
|
+
item_path : str (optional, Default=None)
|
|
199
|
+
The Item Path. An Example would be the following:
|
|
200
|
+
`/TestFolder/TestFile.txt`
|
|
201
|
+
|
|
202
|
+
### Returns
|
|
203
|
+
----
|
|
204
|
+
dict:
|
|
205
|
+
A WorkbookTable Object.
|
|
206
|
+
"""
|
|
207
|
+
# build endpoint
|
|
208
|
+
endpoint=self.build_endpoint(
|
|
209
|
+
table_name_or_id=table_name_or_id,
|
|
210
|
+
worksheet_name_or_id=worksheet_name_or_id,
|
|
211
|
+
item_id=item_id,
|
|
212
|
+
item_path=item_path,
|
|
213
|
+
endpoint_resource="add"
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
body = {"address": address, "hasHeaders": has_headers}
|
|
217
|
+
|
|
218
|
+
content = self.graph_session.make_request(
|
|
219
|
+
method="post",
|
|
220
|
+
json=body,
|
|
221
|
+
additional_headers={"Content-type": "application/json"},
|
|
222
|
+
endpoint=endpoint
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
return content
|
|
226
|
+
|
|
227
|
+
def update_table(
|
|
228
|
+
self,
|
|
229
|
+
name: str = None,
|
|
230
|
+
show_headers: bool = None,
|
|
231
|
+
show_totals: bool = None,
|
|
232
|
+
style: Union[str, Enum] = None,
|
|
233
|
+
table_name_or_id: str = None,
|
|
234
|
+
worksheet_name_or_id: str = None,
|
|
235
|
+
item_id: str = None,
|
|
236
|
+
item_path: str = None,
|
|
237
|
+
):
|
|
238
|
+
"""Update the properties of table object.
|
|
239
|
+
|
|
240
|
+
### Parameters
|
|
241
|
+
----
|
|
242
|
+
name : str (optional, Default=None)
|
|
243
|
+
The name of the table.
|
|
244
|
+
|
|
245
|
+
show_headers : bool (optional, Default=None)
|
|
246
|
+
Indicates whether the header row is visible or not. This
|
|
247
|
+
value can be set to show or remove the header row.
|
|
248
|
+
|
|
249
|
+
show_totals : bool (optional, Default=None)
|
|
250
|
+
Indicates whether the total row is visible or not. This
|
|
251
|
+
value can be set to show or remove the total row.
|
|
252
|
+
|
|
253
|
+
style : Union[str, Enum] (optional, Default=None)
|
|
254
|
+
Constant value that represents the Table style. The possible
|
|
255
|
+
values are: `TableStyleLight1` through `TableStyleLight21`,
|
|
256
|
+
`TableStyleMedium1` through `TableStyleMedium28`, `TableStyleDark1`
|
|
257
|
+
through `TableStyleDark11`. A custom user-defined style
|
|
258
|
+
present in the workbook can also be specified.
|
|
259
|
+
|
|
260
|
+
table_name_or_id : str (optional, Default=None)
|
|
261
|
+
The name of the table or the resource id.
|
|
262
|
+
|
|
263
|
+
worksheet_name_or_id : str (optional, Default=None)
|
|
264
|
+
The name of the worksheet or the resource id.
|
|
265
|
+
|
|
266
|
+
item_id : str (optional, Default=None)
|
|
267
|
+
The Drive Item Resource ID.
|
|
268
|
+
|
|
269
|
+
item_path : str (optional, Default=None)
|
|
270
|
+
The Item Path. An Example would be the following:
|
|
271
|
+
`/TestFolder/TestFile.txt`
|
|
272
|
+
|
|
273
|
+
### Returns
|
|
274
|
+
----
|
|
275
|
+
dict:
|
|
276
|
+
A WorkbookTable object.
|
|
277
|
+
"""
|
|
278
|
+
#build endpoint
|
|
279
|
+
endpoint=self.build_endpoint(
|
|
280
|
+
item_id=item_id,
|
|
281
|
+
item_path=item_path,
|
|
282
|
+
worksheet_name_or_id=worksheet_name_or_id,
|
|
283
|
+
table_name_or_id=table_name_or_id
|
|
284
|
+
)
|
|
285
|
+
|
|
286
|
+
if isinstance(style, Enum):
|
|
287
|
+
style = style.value
|
|
288
|
+
|
|
289
|
+
body = {
|
|
290
|
+
"name": name,
|
|
291
|
+
"showHeaders": show_headers,
|
|
292
|
+
"showTotals": show_totals,
|
|
293
|
+
"style": style
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
content = self.graph_session.make_request(
|
|
297
|
+
method="patch",
|
|
298
|
+
json=body,
|
|
299
|
+
additional_headers={"Content-type": "application/json"},
|
|
300
|
+
endpoint=endpoint
|
|
301
|
+
)
|
|
302
|
+
|
|
303
|
+
return content
|
|
304
|
+
|
|
305
|
+
def list_table_rows(
|
|
306
|
+
self,
|
|
307
|
+
table_name_or_id: str = None,
|
|
308
|
+
worksheet_name_or_id: str = None,
|
|
309
|
+
item_id: str = None,
|
|
310
|
+
item_path: str = None) -> dict:
|
|
311
|
+
|
|
312
|
+
""" lists table rows """
|
|
313
|
+
|
|
314
|
+
endpoint = self.build_endpoint(
|
|
315
|
+
table_name_or_id=table_name_or_id,
|
|
316
|
+
worksheet_name_or_id=worksheet_name_or_id,
|
|
317
|
+
item_id=item_id,
|
|
318
|
+
item_path=item_path,
|
|
319
|
+
endpoint_resource="rows"
|
|
320
|
+
)
|
|
321
|
+
|
|
322
|
+
content = self.graph_session.make_request(
|
|
323
|
+
method="get",
|
|
324
|
+
additional_headers={"Content-type": "application/json"},
|
|
325
|
+
endpoint=endpoint
|
|
326
|
+
)
|
|
327
|
+
|
|
328
|
+
return content
|
|
329
|
+
|
|
330
|
+
def create_table_rows(
|
|
331
|
+
self,
|
|
332
|
+
index_row: int = None,
|
|
333
|
+
values_list: json = None,
|
|
334
|
+
table_name_or_id: str = None,
|
|
335
|
+
worksheet_name_or_id: str = None,
|
|
336
|
+
item_id: str = None,
|
|
337
|
+
item_path: str = None) -> dict:
|
|
338
|
+
|
|
339
|
+
# build endpoint
|
|
340
|
+
endpoint=self.build_endpoint(
|
|
341
|
+
item_id=item_id,
|
|
342
|
+
item_path=item_path,
|
|
343
|
+
worksheet_name_or_id=worksheet_name_or_id,
|
|
344
|
+
table_name_or_id=table_name_or_id,
|
|
345
|
+
endpoint_resource="rows"
|
|
346
|
+
)
|
|
347
|
+
|
|
348
|
+
""" lists table rows """
|
|
349
|
+
|
|
350
|
+
if index_row is not None:
|
|
351
|
+
body = {
|
|
352
|
+
"index": index_row,
|
|
353
|
+
"values": values_list
|
|
354
|
+
}
|
|
355
|
+
elif index_row is None:
|
|
356
|
+
body = {
|
|
357
|
+
"values": values_list
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
content = self.graph_session.make_request(
|
|
362
|
+
method="post",
|
|
363
|
+
json=body,
|
|
364
|
+
additional_headers={"Content-type": "application/json"},
|
|
365
|
+
endpoint=endpoint
|
|
366
|
+
)
|
|
367
|
+
|
|
368
|
+
return content
|
|
369
|
+
|
|
370
|
+
def list_table_columns(
|
|
371
|
+
self,
|
|
372
|
+
table_name_or_id: str = None,
|
|
373
|
+
worksheet_name_or_id: str = None,
|
|
374
|
+
item_id: str = None,
|
|
375
|
+
item_path: str = None
|
|
376
|
+
) -> dict:
|
|
377
|
+
|
|
378
|
+
# build endpoint
|
|
379
|
+
endpoint=self.build_endpoint(
|
|
380
|
+
item_id=item_id,
|
|
381
|
+
item_path=item_path,
|
|
382
|
+
worksheet_name_or_id=worksheet_name_or_id,
|
|
383
|
+
table_name_or_id=table_name_or_id,
|
|
384
|
+
endpoint_resource="columns"
|
|
385
|
+
)
|
|
386
|
+
|
|
387
|
+
content = self.graph_session.make_request(
|
|
388
|
+
method="get",
|
|
389
|
+
additional_headers={"Content-type": "application/json"},
|
|
390
|
+
endpoint=endpoint
|
|
391
|
+
)
|
|
392
|
+
|
|
393
|
+
return content
|
|
394
|
+
|
|
395
|
+
def get_table_range(
|
|
396
|
+
self,
|
|
397
|
+
table_name_or_id: str = None,
|
|
398
|
+
worksheet_name_or_id: str = None,
|
|
399
|
+
item_id: str = None,
|
|
400
|
+
item_path: str = None) -> dict:
|
|
401
|
+
|
|
402
|
+
# build endpoint
|
|
403
|
+
endpoint=self.build_endpoint(
|
|
404
|
+
item_id=item_id,
|
|
405
|
+
item_path=item_path,
|
|
406
|
+
worksheet_name_or_id=worksheet_name_or_id,
|
|
407
|
+
table_name_or_id=table_name_or_id,
|
|
408
|
+
endpoint_resource="range"
|
|
409
|
+
)
|
|
410
|
+
|
|
411
|
+
content = self.graph_session.make_request(
|
|
412
|
+
method = "get",
|
|
413
|
+
additional_headers = {"content-type": "application/json"},
|
|
414
|
+
endpoint = endpoint
|
|
415
|
+
)
|
|
416
|
+
|
|
417
|
+
return content
|
|
418
|
+
|
|
419
|
+
def get_header_row_range(
|
|
420
|
+
self,
|
|
421
|
+
table_name_or_id: str = None,
|
|
422
|
+
worksheet_name_or_id: str = None,
|
|
423
|
+
item_id: str = None,
|
|
424
|
+
item_path: str = None
|
|
425
|
+
) -> dict:
|
|
426
|
+
|
|
427
|
+
#build endpoint
|
|
428
|
+
endpoint = self.build_endpoint(
|
|
429
|
+
item_id=item_id,
|
|
430
|
+
item_path=item_path,
|
|
431
|
+
worksheet_name_or_id=worksheet_name_or_id,
|
|
432
|
+
table_name_or_id=table_name_or_id,
|
|
433
|
+
endpoint_resource="headerrowrange"
|
|
434
|
+
)
|
|
435
|
+
|
|
436
|
+
content = self.graph_session.make_request(
|
|
437
|
+
method = "get",
|
|
438
|
+
additional_headers = {"content-type": "application/json"},
|
|
439
|
+
endpoint = endpoint
|
|
440
|
+
)
|
|
441
|
+
|
|
442
|
+
return content
|
|
443
|
+
|
|
444
|
+
def get_data_body_range(
|
|
445
|
+
self,
|
|
446
|
+
table_name_or_id: str = None,
|
|
447
|
+
worksheet_name_or_id: str = None,
|
|
448
|
+
item_id: str = None,
|
|
449
|
+
item_path: str = None
|
|
450
|
+
) -> dict:
|
|
451
|
+
|
|
452
|
+
#build endpoint
|
|
453
|
+
endpoint = self.build_endpoint(
|
|
454
|
+
item_id=item_id,
|
|
455
|
+
item_path=item_path,
|
|
456
|
+
worksheet_name_or_id=worksheet_name_or_id,
|
|
457
|
+
table_name_or_id=table_name_or_id,
|
|
458
|
+
endpoint_resource="databodyrange"
|
|
459
|
+
)
|
|
460
|
+
|
|
461
|
+
content = self.graph_session.make_request(
|
|
462
|
+
method = "get",
|
|
463
|
+
additional_headers = {"content-type": "application/json"},
|
|
464
|
+
endpoint = endpoint
|
|
465
|
+
)
|
|
466
|
+
|
|
467
|
+
return content
|