11# microsoft-python
22Microsoft graph API wrapper for Microsoft Graph written in Python.
33
4- ## Installing
5- ```
6- pip install microsoftgraph-python
7- ```
8-
94## Before start
105To use Microsoft Graph to read and write resources on behalf of a user, your app must get an access token from
116the Microsoft identity platform and attach the token to requests that it sends to Microsoft Graph. The exact
@@ -15,12 +10,28 @@ apps and also by some Web apps is the OAuth 2.0 authorization code grant flow.
1510
1611See https://docs.microsoft.com/en-us/graph/auth-v2-user
1712
13+ ## Breaking changes if you're upgrading prior 1.0.0
14+ - Adds API structure to library for e.g. ` client.get_me() ` => ` client.users.get_me() ` .
15+ - Renames several methods to match API documentation for e.g. ` client.get_me_events() ` => ` client.calendar.list_events() ` .
16+ - Result from calling methods are not longer a dict but a Response obj. To access the dict response as before then call ` .data ` property for e.g ` r = client.users.get_me() ` then ` r.data ` .
17+
18+ ## New in 1.0.0
19+ - You can access to [ Requests library's Response obj] ( https://docs.python-requests.org/en/latest/ ) for e.g. ` r = client.users.get_me() ` then ` r.original ` or the response handled by the library ` r.data ` .
20+ - New Response properties ` r.status_code ` and ` r.throttling ` .
21+ - Better docstrings and type hinting.
22+ - Better library structure.
23+ ## Installing
24+ ```
25+ pip install microsoftgraph-python
26+ ```
1827## Usage
28+ ### Instantiation
1929```
2030from microsoftgraph.client import Client
21- client = Client('CLIENT_ID', 'CLIENT_SECRET', account_type='common') # by default common, thus account_type is optional parameter
31+ client = Client('CLIENT_ID', 'CLIENT_SECRET', account_type='common') # by default common, thus account_type is optional parameter.
2232```
2333
34+ ### OAuth 2.0
2435#### Get authorization url
2536```
2637url = client.authorization_url(redirect_uri, scope, state=None)
@@ -38,228 +49,228 @@ token = client.refresh_token(redirect_uri, refresh_token)
3849
3950#### Set token
4051```
41- token = client.set_token(token)
52+ client.set_token(token)
4253```
4354
55+ ### Users
4456#### Get me
4557```
46- me = client.get_me()
58+ response = client.users .get_me()
4759```
4860
61+ ### Mail
4962#### Get message
5063```
51- me = client.get_message(message_id="")
52- ```
53-
54- ### Webhook section, see the api documentation: https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/resources/webhooks
55-
56- #### Create subscription
57- ```
58- subscription = client.create_subscription(change_type, notification_url, resource, expiration_datetime, client_state=None)
64+ response = client.mail.get_message(message_id)
5965```
6066
61- #### Renew subscription
62- ```
63- renew = client.renew_subscription(subscription_id, expiration_datetime)
64- ```
65-
66- #### Delete subscription
67+ #### Send mail
6768```
68- renew = client.delete_subscription(subscription_id )
69+ response = client.mail.send_mail(subject, content, to_recipients )
6970```
7071
71- ### Onenote section, see the api documentation: https://developer.microsoft.com/en-us/graph/docs/concepts/integrate_with_onenote
72-
72+ ### Notes
7373#### List notebooks
7474```
75- notebooks = client.list_notebooks()
75+ response = client.notes .list_notebooks()
7676```
7777
7878#### Get notebook
7979```
80- notebook = client.get_notebook(notebook_id)
80+ response = client.notes .get_notebook(notebook_id)
8181```
8282
8383#### Get notebook sections
8484```
85- section_notebook = client.get_notebook_sections (notebook_id)
85+ response = client.notes.list_sections (notebook_id)
8686```
8787
88- #### Create page
88+ #### List pages
8989```
90- add_page = client.create_page(section_id, files )
90+ response = client.notes.list_pages( )
9191```
9292
93- #### List pages
93+ #### Create page
9494```
95- pages = client.list_pages( )
95+ response = client.notes.create_page(section_id, files )
9696```
9797
98- ### Calendar section, see the api documentation: https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/resources/calendar
99-
98+ ### Calendar
10099#### Get events
101100```
102- events = client.get_me_events ()
101+ response = client.calendar.list_events ()
103102```
104103
105104#### Create calendar event
106105```
107- events = client.create_calendar_event(subject, content, start_datetime, start_timezone, end_datetime, end_timezone,
108- recurrence_type, recurrence_interval, recurrence_days_of_week, recurrence_range_type,
109- recurrence_range_startdate, recurrence_range_enddate, location, attendees, calendar=None)
106+ response = client.calendar.create_event(subject, content, start_datetime,start_timezone, end_datetime, end_timezone, location, calendar, content_type)
110107```
111108
112109#### Get calendars
113110```
114- events = client.get_me_calendars ()
111+ response = client.calendar.list_calendars ()
115112```
116113
117114#### Create calendar
118115```
119- events = client.create_calendar(name)
116+ response = client.calendar .create_calendar(name)
120117```
121118
122- ### Contacts section, see the api documentation: https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/resources/contact
123-
124- #### Get contacts
125- If you need a specific contact send the contact id in data_id
119+ ### Contacts
120+ #### Get a contact
126121```
127- specific_contact = client.outlook_get_me_contacts(data_id="" )
122+ response = client.contacts.get_contact(contact_id )
128123```
129- If you want all the contacts
124+
125+ #### Get contacts
130126```
131- specific_contact = client.outlook_get_me_contacts ()
127+ response = client.contacts.list_contacts ()
132128```
133129
134130#### Create contact
135131```
136- add_contact = client.outlook_create_me_contact ()
132+ response = client.contacts.create_contact ()
137133```
138134
139135#### Create contact in specific folder
140136```
141- add_contact_folder = client.outlook_create_contact_in_folder (folder_id)
137+ response = client.contacts.create_contact_in_folder (folder_id)
142138```
143139
144140#### Get contact folders
145141```
146- folders = client.outlook_get_contact_folders ()
142+ response = client.contacts.list_contact_folders ()
147143```
148144
149145#### Create contact folders
150146```
151- add_folders = client.outlook_create_contact_folder ()
147+ response = client.contacts.create_contact_folder ()
152148```
153149
154- ### Onedrive section, see the api documentation: https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/resources/onedrive
155-
150+ ### Files
156151#### Get root items
157152```
158- root_items = client.drive_root_items()
153+ response = client.files .drive_root_items()
159154```
160155
161156#### Get root children items
162157```
163- root_children_items = client.drive_root_children_items()
158+ response = client.files .drive_root_children_items()
164159```
165160
166161#### Get specific folder items
167162```
168- folder_items = client.drive_specific_folder(folder_id)
163+ response = client.files .drive_specific_folder(folder_id)
169164```
170165
171- ### Excel section, see the api documentation: https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/resources/excel
172- For use excel, you should know the folder id where the file is
173- #### Create session for specific item
166+ #### Get item
174167```
175- create_session = client.drive_create_session (item_id)
168+ response = client.files.drive_get_item (item_id)
176169```
177170
178- #### Refresh session for specific item
171+ #### Download the contents of a specific item
179172```
180- refresh_session = client.drive_refresh_session (item_id)
173+ response = client.files.drive_download_contents (item_id)
181174```
182175
183- #### Close session for specific item
176+ ### Workbooks
177+ #### Create session for specific item
184178```
185- close_session = client.drive_close_session (item_id)
179+ response = client.workbooks.create_session (item_id)
186180```
187181
188- #### Download the contents of a specific item
182+ #### Refresh session for specific item
189183```
190- contents_bytes = client.drive_download_contents (item_id)
184+ response = client.workbooks.refresh_session (item_id)
191185```
192186
193- #### Get a Drive item resource
187+ #### Close session for specific item
194188```
195- drive_item_dict = client.drive_get_item (item_id)
189+ response = client.workbooks.close_session (item_id)
196190```
197191
198192#### Get worksheets
199193```
200- get_worksheets = client.excel_get_worksheets (item_id)
194+ response = client.workbooks.list_worksheets (item_id)
201195```
202196
203197#### Get specific worksheet
204198```
205- specific_worksheet = client.excel_get_specific_worksheet (item_id, worksheet_id)
199+ response = client.workbooks.get_worksheet (item_id, worksheet_id)
206200```
207201
208202#### Add worksheets
209203```
210- add_worksheet = client.excel_add_worksheet (item_id)
204+ response = client.workbooks.add_worksheet (item_id)
211205```
212206
213207#### Update worksheet
214208```
215- update_worksheet = client.excel_update_worksheet (item_id, worksheet_id)
209+ response = client.workbooks.update_worksheet (item_id, worksheet_id)
216210```
217211
218212#### Get charts
219213```
220- get_charts = client.excel_get_charts (item_id, worksheet_id)
214+ response = client.workbooks.list_charts (item_id, worksheet_id)
221215```
222216
223217#### Add chart
224218```
225- add_chart = client.excel_add_chart (item_id, worksheet_id)
219+ response = client.workbooks.add_chart (item_id, worksheet_id)
226220```
227221
228222#### Get tables
229223```
230- get_tables = client.excel_get_tables (item_id)
224+ response = client.workbooks.list_tables (item_id)
231225```
232226
233227#### Add table
234228```
235- add_table = client.excel_add_table (item_id)
229+ response = client.workbooks.add_table (item_id)
236230```
237231
238232#### Add column to table
239233```
240- add_column = client.excel_add_column (item_id, worksheets_id, table_id)
234+ response = client.workbooks.create_column (item_id, worksheets_id, table_id)
241235```
242236
243237#### Add row to table
244238```
245- add_row = client.excel_add_row (item_id, worksheets_id, table_id)
239+ response = client.workbooks.create_row (item_id, worksheets_id, table_id)
246240```
247241
248242#### Get table rows
249243```
250- get_rows = client.excel_get_rows (item_id, table_id)
244+ response = client.workbooks.list_rows (item_id, table_id)
251245```
252246
253247#### Get range
254248```
255- get_range = client.excel_get_range (item_id, worksheets_id)
249+ response = client.workbooks.get_range (item_id, worksheets_id)
256250```
257251
258252#### Update range
259253```
260- update_range = client.excel_update_range (item_id, worksheets_id)
254+ response = client.workbooks.update_range (item_id, worksheets_id)
261255```
262256
257+ ### Webhooks
258+ #### Create subscription
259+ ```
260+ response = client.webhooks.create_subscription(change_type, notification_url, resource, expiration_datetime, client_state=None)
261+ ```
262+
263+ #### Renew subscription
264+ ```
265+ response = client.webhooks.renew_subscription(subscription_id, expiration_datetime)
266+ ```
267+
268+ #### Delete subscription
269+ ```
270+ response = client.webhooks.delete_subscription(subscription_id)
271+ ```
272+
273+
263274## Requirements
264275- requests
265276
0 commit comments