ms-graph 1.5.2__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.
ms_graph-1.5.2/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 bek42
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,319 @@
1
+ Metadata-Version: 2.4
2
+ Name: ms-graph
3
+ Version: 1.5.2
4
+ Summary: A Python Client Application that allows interaction with the Microsoft Graph API.
5
+ License: MIT
6
+ License-File: LICENSE
7
+ Keywords: microsoft,graph,api,onedrive,outlook,sharepoint,excel,onenote
8
+ Author: bek42
9
+ Author-email: bharani.nitturi@gmail.com
10
+ Requires-Python: >=3.12,<4.0
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Topic :: Internet :: WWW/HTTP
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Requires-Dist: azkees (>=6.1.0,<7.0.0)
21
+ Requires-Dist: msal (>=1.29.0,<2.0.0)
22
+ Requires-Dist: pylogpy (>=1.5.2,<2.0.0)
23
+ Requires-Dist: requests (>=2.32.3,<3.0.0)
24
+ Project-URL: Changelog, https://github.com/bek42/ms_graph/blob/main/CHANGELOG.md
25
+ Project-URL: Homepage, https://github.com/bek42/ms_graph
26
+ Project-URL: Repository, https://github.com/bek42/ms_graph
27
+ Description-Content-Type: text/markdown
28
+
29
+ # ms-graph
30
+
31
+ [![PyPI version](https://img.shields.io/pypi/v/ms-graph.svg)](https://pypi.org/project/ms-graph/)
32
+ [![Python Versions](https://img.shields.io/pypi/pyversions/ms-graph.svg)](https://pypi.org/project/ms-graph/)
33
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
34
+
35
+ A Python client for the [Microsoft Graph API](https://learn.microsoft.com/en-us/graph/overview), covering OneDrive, SharePoint, Outlook Mail, OneNote, Contacts, Excel Workbooks, Users, Groups, and Search.
36
+
37
+ ---
38
+
39
+ ## Installation
40
+
41
+ ```bash
42
+ pip install ms-graph
43
+ ```
44
+
45
+ Or with Poetry:
46
+
47
+ ```bash
48
+ poetry add ms-graph
49
+ ```
50
+
51
+ ---
52
+
53
+ ## Prerequisites
54
+
55
+ Register an application in the [Azure Portal](https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationsListBlade) to obtain:
56
+
57
+ - **Client ID**
58
+ - **Client Secret**
59
+ - **Redirect URI**
60
+
61
+ Grant the required [Microsoft Graph API permissions](https://learn.microsoft.com/en-us/graph/permissions-reference) for the services you intend to use.
62
+
63
+ ---
64
+
65
+ ## Quick Start
66
+
67
+ ```python
68
+ from ms_graph import MicrosoftGraphClient
69
+
70
+ client = MicrosoftGraphClient(
71
+ client_id="YOUR_CLIENT_ID",
72
+ client_secret="YOUR_CLIENT_SECRET",
73
+ redirect_uri="YOUR_REDIRECT_URI",
74
+ scope=["Files.Read", "Files.ReadWrite", "Mail.Read"],
75
+ account_type="consumers", # or "organizations" / "common"
76
+ )
77
+
78
+ # Opens a browser prompt on first run to complete OAuth2 flow.
79
+ # Subsequent runs use a saved token / refresh token automatically.
80
+ client.login()
81
+ ```
82
+
83
+ Credentials are persisted to a local JSON file (or Azure Key Vault — see below). On subsequent runs, tokens are refreshed silently.
84
+
85
+ ---
86
+
87
+ ## Services
88
+
89
+ ### OneDrive — Drives
90
+
91
+ ```python
92
+ drives = client.drives()
93
+
94
+ # Root drive
95
+ root = drives.get_root_drive()
96
+
97
+ # Children of root
98
+ children = drives.get_root_drive_children()
99
+
100
+ # Recent files
101
+ recent = drives.get_recent_files()
102
+
103
+ # Shared with me
104
+ shared = drives.get_shared_files()
105
+ ```
106
+
107
+ ### OneDrive — Drive Items
108
+
109
+ ```python
110
+ items = client.drive_item()
111
+
112
+ # By item ID
113
+ item = items.get_drive_item(drive_id="DRIVE_ID", item_id="ITEM_ID")
114
+
115
+ # By path
116
+ item = items.get_drive_item_by_path(drive_id="DRIVE_ID", item_path="Documents/report.xlsx")
117
+
118
+ # Group drive item
119
+ item = items.get_group_drive_item(group_id="GROUP_ID", item_id="ITEM_ID")
120
+ ```
121
+
122
+ ### Outlook Mail
123
+
124
+ ```python
125
+ mail = client.mail()
126
+
127
+ # List messages for signed-in user
128
+ messages = mail.list_my_messages()
129
+
130
+ # List messages for a specific user
131
+ messages = mail.list_user_messages(user_id="user@example.com")
132
+
133
+ # Get a specific message
134
+ msg = mail.get_my_messages(message_id="MESSAGE_ID")
135
+
136
+ # Create a draft
137
+ draft = mail.create_my_message(message={
138
+ "subject": "Hello",
139
+ "body": {"contentType": "Text", "content": "Hi there"},
140
+ "toRecipients": [{"emailAddress": {"address": "recipient@example.com"}}]
141
+ })
142
+ ```
143
+
144
+ ### OneNote
145
+
146
+ ```python
147
+ notes = client.notes()
148
+
149
+ # My notebooks
150
+ notebooks = notes.list_my_notebooks()
151
+
152
+ # Notebooks for a specific user
153
+ notebooks = notes.list_user_notebooks(user_id="user@example.com")
154
+
155
+ # Notebooks for a group
156
+ notebooks = notes.list_group_notebooks(group_id="GROUP_ID")
157
+ ```
158
+
159
+ ### Personal Contacts
160
+
161
+ ```python
162
+ contacts = client.personal_contacts()
163
+
164
+ # All contacts
165
+ all_contacts = contacts.list_my_contacts()
166
+
167
+ # Contact folders
168
+ folders = contacts.list_my_contacts_folder()
169
+
170
+ # Folder by ID
171
+ folder = contacts.list_contacts_folder_by_id(user_id="USER_ID", folder_id="FOLDER_ID")
172
+ ```
173
+
174
+ ### Users
175
+
176
+ ```python
177
+ users = client.users()
178
+
179
+ all_users = users.list_users()
180
+ ```
181
+
182
+ ### Groups
183
+
184
+ ```python
185
+ groups = client.groups()
186
+
187
+ all_groups = groups.list_groups()
188
+ ```
189
+
190
+ ### Search
191
+
192
+ ```python
193
+ search = client.search()
194
+
195
+ results = search.query(search_request={
196
+ "requests": [{
197
+ "entityTypes": ["driveItem"],
198
+ "query": {"queryString": "quarterly report"}
199
+ }]
200
+ })
201
+ ```
202
+
203
+ ### Excel Workbooks
204
+
205
+ ```python
206
+ workbooks = client.workbooks()
207
+
208
+ # Create a session (enables batching edits)
209
+ session = workbooks.create_session(item_path="Documents/report.xlsx")
210
+ session_id = session["id"]
211
+
212
+ # Refresh the session
213
+ workbooks.refresh_session(session_id=session_id, item_path="Documents/report.xlsx")
214
+
215
+ # Close the session
216
+ workbooks.close_session(session_id=session_id, item_path="Documents/report.xlsx")
217
+ ```
218
+
219
+ ### Excel Worksheets
220
+
221
+ ```python
222
+ from ms_graph.workbooks_and_charts import Worksheet
223
+
224
+ worksheet = Worksheet(session=client.graph_session)
225
+
226
+ # Add a new sheet
227
+ worksheet.add_worksheet(item_path="Documents/report.xlsx", name="Summary")
228
+ ```
229
+
230
+ ### Excel Range
231
+
232
+ ```python
233
+ range_svc = client.range()
234
+
235
+ # Get a range by address
236
+ data = range_svc.get_range(
237
+ item_path="Documents/report.xlsx",
238
+ worksheet_name_or_id="Sheet1",
239
+ address="A1:C5"
240
+ )
241
+ ```
242
+
243
+ ### Excel Tables
244
+
245
+ ```python
246
+ table_svc = client.table()
247
+ ```
248
+
249
+ ---
250
+
251
+ ## Credential Storage Options
252
+
253
+ ### Option 1 — JSON file (default)
254
+
255
+ Pass a file path as `credentials`. The token is saved/loaded automatically:
256
+
257
+ ```python
258
+ client = MicrosoftGraphClient(
259
+ client_id="...",
260
+ client_secret="...",
261
+ redirect_uri="...",
262
+ scope=[...],
263
+ credentials="./ms_graph_state.json",
264
+ )
265
+ ```
266
+
267
+ ### Option 2 — Azure Key Vault
268
+
269
+ Pass an `Az` client from [`azkees`](https://pypi.org/project/azkees/) and set the env var `key_msgraph_credentials_state` to the Key Vault secret name where the token JSON will be stored:
270
+
271
+ ```python
272
+ import os
273
+ from azkees import Az
274
+ from ms_graph import MicrosoftGraphClient
275
+
276
+ os.environ["key_msgraph_credentials_state"] = "msgraphstate"
277
+
278
+ az_client = Az(config_section="production", keys_config_path="/app/config/api_keys.ini")
279
+
280
+ client = MicrosoftGraphClient(
281
+ client_id="...",
282
+ client_secret="...",
283
+ redirect_uri="...",
284
+ scope=[...],
285
+ az_client=az_client,
286
+ )
287
+ ```
288
+
289
+ ---
290
+
291
+ ## Enums
292
+
293
+ ```python
294
+ from ms_graph.workbooks_and_charts.enums import (
295
+ CalculationTypes,
296
+ WorksheetVisibility,
297
+ RangeShift,
298
+ Underline,
299
+ )
300
+
301
+ CalculationTypes.RECALCULATE.value # "Recalculate"
302
+ WorksheetVisibility.HIDDEN.value # "Hidden"
303
+ RangeShift.DOWN.value # "Down"
304
+ ```
305
+
306
+ ---
307
+
308
+ ## Changelog
309
+
310
+ See [CHANGELOG.md](CHANGELOG.md) for version history.
311
+
312
+ ## License
313
+
314
+ [MIT](LICENSE)
315
+
316
+ ## Author
317
+
318
+ [Bharani Nitturi](https://github.com/bek42)
319
+
@@ -0,0 +1,290 @@
1
+ # ms-graph
2
+
3
+ [![PyPI version](https://img.shields.io/pypi/v/ms-graph.svg)](https://pypi.org/project/ms-graph/)
4
+ [![Python Versions](https://img.shields.io/pypi/pyversions/ms-graph.svg)](https://pypi.org/project/ms-graph/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ A Python client for the [Microsoft Graph API](https://learn.microsoft.com/en-us/graph/overview), covering OneDrive, SharePoint, Outlook Mail, OneNote, Contacts, Excel Workbooks, Users, Groups, and Search.
8
+
9
+ ---
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ pip install ms-graph
15
+ ```
16
+
17
+ Or with Poetry:
18
+
19
+ ```bash
20
+ poetry add ms-graph
21
+ ```
22
+
23
+ ---
24
+
25
+ ## Prerequisites
26
+
27
+ Register an application in the [Azure Portal](https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationsListBlade) to obtain:
28
+
29
+ - **Client ID**
30
+ - **Client Secret**
31
+ - **Redirect URI**
32
+
33
+ Grant the required [Microsoft Graph API permissions](https://learn.microsoft.com/en-us/graph/permissions-reference) for the services you intend to use.
34
+
35
+ ---
36
+
37
+ ## Quick Start
38
+
39
+ ```python
40
+ from ms_graph import MicrosoftGraphClient
41
+
42
+ client = MicrosoftGraphClient(
43
+ client_id="YOUR_CLIENT_ID",
44
+ client_secret="YOUR_CLIENT_SECRET",
45
+ redirect_uri="YOUR_REDIRECT_URI",
46
+ scope=["Files.Read", "Files.ReadWrite", "Mail.Read"],
47
+ account_type="consumers", # or "organizations" / "common"
48
+ )
49
+
50
+ # Opens a browser prompt on first run to complete OAuth2 flow.
51
+ # Subsequent runs use a saved token / refresh token automatically.
52
+ client.login()
53
+ ```
54
+
55
+ Credentials are persisted to a local JSON file (or Azure Key Vault — see below). On subsequent runs, tokens are refreshed silently.
56
+
57
+ ---
58
+
59
+ ## Services
60
+
61
+ ### OneDrive — Drives
62
+
63
+ ```python
64
+ drives = client.drives()
65
+
66
+ # Root drive
67
+ root = drives.get_root_drive()
68
+
69
+ # Children of root
70
+ children = drives.get_root_drive_children()
71
+
72
+ # Recent files
73
+ recent = drives.get_recent_files()
74
+
75
+ # Shared with me
76
+ shared = drives.get_shared_files()
77
+ ```
78
+
79
+ ### OneDrive — Drive Items
80
+
81
+ ```python
82
+ items = client.drive_item()
83
+
84
+ # By item ID
85
+ item = items.get_drive_item(drive_id="DRIVE_ID", item_id="ITEM_ID")
86
+
87
+ # By path
88
+ item = items.get_drive_item_by_path(drive_id="DRIVE_ID", item_path="Documents/report.xlsx")
89
+
90
+ # Group drive item
91
+ item = items.get_group_drive_item(group_id="GROUP_ID", item_id="ITEM_ID")
92
+ ```
93
+
94
+ ### Outlook Mail
95
+
96
+ ```python
97
+ mail = client.mail()
98
+
99
+ # List messages for signed-in user
100
+ messages = mail.list_my_messages()
101
+
102
+ # List messages for a specific user
103
+ messages = mail.list_user_messages(user_id="user@example.com")
104
+
105
+ # Get a specific message
106
+ msg = mail.get_my_messages(message_id="MESSAGE_ID")
107
+
108
+ # Create a draft
109
+ draft = mail.create_my_message(message={
110
+ "subject": "Hello",
111
+ "body": {"contentType": "Text", "content": "Hi there"},
112
+ "toRecipients": [{"emailAddress": {"address": "recipient@example.com"}}]
113
+ })
114
+ ```
115
+
116
+ ### OneNote
117
+
118
+ ```python
119
+ notes = client.notes()
120
+
121
+ # My notebooks
122
+ notebooks = notes.list_my_notebooks()
123
+
124
+ # Notebooks for a specific user
125
+ notebooks = notes.list_user_notebooks(user_id="user@example.com")
126
+
127
+ # Notebooks for a group
128
+ notebooks = notes.list_group_notebooks(group_id="GROUP_ID")
129
+ ```
130
+
131
+ ### Personal Contacts
132
+
133
+ ```python
134
+ contacts = client.personal_contacts()
135
+
136
+ # All contacts
137
+ all_contacts = contacts.list_my_contacts()
138
+
139
+ # Contact folders
140
+ folders = contacts.list_my_contacts_folder()
141
+
142
+ # Folder by ID
143
+ folder = contacts.list_contacts_folder_by_id(user_id="USER_ID", folder_id="FOLDER_ID")
144
+ ```
145
+
146
+ ### Users
147
+
148
+ ```python
149
+ users = client.users()
150
+
151
+ all_users = users.list_users()
152
+ ```
153
+
154
+ ### Groups
155
+
156
+ ```python
157
+ groups = client.groups()
158
+
159
+ all_groups = groups.list_groups()
160
+ ```
161
+
162
+ ### Search
163
+
164
+ ```python
165
+ search = client.search()
166
+
167
+ results = search.query(search_request={
168
+ "requests": [{
169
+ "entityTypes": ["driveItem"],
170
+ "query": {"queryString": "quarterly report"}
171
+ }]
172
+ })
173
+ ```
174
+
175
+ ### Excel Workbooks
176
+
177
+ ```python
178
+ workbooks = client.workbooks()
179
+
180
+ # Create a session (enables batching edits)
181
+ session = workbooks.create_session(item_path="Documents/report.xlsx")
182
+ session_id = session["id"]
183
+
184
+ # Refresh the session
185
+ workbooks.refresh_session(session_id=session_id, item_path="Documents/report.xlsx")
186
+
187
+ # Close the session
188
+ workbooks.close_session(session_id=session_id, item_path="Documents/report.xlsx")
189
+ ```
190
+
191
+ ### Excel Worksheets
192
+
193
+ ```python
194
+ from ms_graph.workbooks_and_charts import Worksheet
195
+
196
+ worksheet = Worksheet(session=client.graph_session)
197
+
198
+ # Add a new sheet
199
+ worksheet.add_worksheet(item_path="Documents/report.xlsx", name="Summary")
200
+ ```
201
+
202
+ ### Excel Range
203
+
204
+ ```python
205
+ range_svc = client.range()
206
+
207
+ # Get a range by address
208
+ data = range_svc.get_range(
209
+ item_path="Documents/report.xlsx",
210
+ worksheet_name_or_id="Sheet1",
211
+ address="A1:C5"
212
+ )
213
+ ```
214
+
215
+ ### Excel Tables
216
+
217
+ ```python
218
+ table_svc = client.table()
219
+ ```
220
+
221
+ ---
222
+
223
+ ## Credential Storage Options
224
+
225
+ ### Option 1 — JSON file (default)
226
+
227
+ Pass a file path as `credentials`. The token is saved/loaded automatically:
228
+
229
+ ```python
230
+ client = MicrosoftGraphClient(
231
+ client_id="...",
232
+ client_secret="...",
233
+ redirect_uri="...",
234
+ scope=[...],
235
+ credentials="./ms_graph_state.json",
236
+ )
237
+ ```
238
+
239
+ ### Option 2 — Azure Key Vault
240
+
241
+ Pass an `Az` client from [`azkees`](https://pypi.org/project/azkees/) and set the env var `key_msgraph_credentials_state` to the Key Vault secret name where the token JSON will be stored:
242
+
243
+ ```python
244
+ import os
245
+ from azkees import Az
246
+ from ms_graph import MicrosoftGraphClient
247
+
248
+ os.environ["key_msgraph_credentials_state"] = "msgraphstate"
249
+
250
+ az_client = Az(config_section="production", keys_config_path="/app/config/api_keys.ini")
251
+
252
+ client = MicrosoftGraphClient(
253
+ client_id="...",
254
+ client_secret="...",
255
+ redirect_uri="...",
256
+ scope=[...],
257
+ az_client=az_client,
258
+ )
259
+ ```
260
+
261
+ ---
262
+
263
+ ## Enums
264
+
265
+ ```python
266
+ from ms_graph.workbooks_and_charts.enums import (
267
+ CalculationTypes,
268
+ WorksheetVisibility,
269
+ RangeShift,
270
+ Underline,
271
+ )
272
+
273
+ CalculationTypes.RECALCULATE.value # "Recalculate"
274
+ WorksheetVisibility.HIDDEN.value # "Hidden"
275
+ RangeShift.DOWN.value # "Down"
276
+ ```
277
+
278
+ ---
279
+
280
+ ## Changelog
281
+
282
+ See [CHANGELOG.md](CHANGELOG.md) for version history.
283
+
284
+ ## License
285
+
286
+ [MIT](LICENSE)
287
+
288
+ ## Author
289
+
290
+ [Bharani Nitturi](https://github.com/bek42)
@@ -0,0 +1,5 @@
1
+ """ms_graph — A Python client for the Microsoft Graph API."""
2
+
3
+ from ms_graph.client import MicrosoftGraphClient
4
+
5
+ __all__ = ["MicrosoftGraphClient"]