Skip to content

Commit 2df2ba2

Browse files
committed
fixes README based on linter suggestions, and prepares for Pypi upload
1 parent 8a5f494 commit 2df2ba2

File tree

2 files changed

+68
-27
lines changed

2 files changed

+68
-27
lines changed

README.md

Lines changed: 67 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
# Python-MSGraph
2-
`python-msgraph` is a Python wrapper of the [Microsoft Graph](https://developer.microsoft.com/en-us/graph) API.
32

3+
`python-msgraph` is a Python wrapper of the [Microsoft Graph](https://developer.microsoft.com/en-us/graph) API.
44

55
## Installation
6+
67
To install the `python-msgraph` library use the following command:
8+
79
```bash
810
python -m pip install python-msgraph
911
```
12+
1013
or, to build locally and install:
11-
```bash
12-
git clone [email protected]:WMInfoTech/python-msgraph.git && cd python-msgraph
13-
python setup.py install
14-
```
14+
1515

1616
## Usage
1717

1818
### Authentication
19+
1920
The library currently supports connecting to the API using an SSL certificate:
21+
2022
```python
2123
from msgraph import api
2224

@@ -31,31 +33,37 @@ api_instance = api.GraphAPI.from_certificate(authority_host_uri, tenant, resourc
3133

3234
**NOTE**: When a `client_certificate` is changed, the `client_thumbprint` and `client_id` values must also be changed
3335

34-
3536
### Using the API to fetch Users
37+
3638
You can use the `msgraph.user` module to interact with `User` instances. `User` instanced can be fetched using the `msgraph.user.User` class:
39+
3740
```python
3841
from msgraph import user
3942
all_users = user.User.get(api_instance)
4043
```
4144

4245
To fetch a specific user, you can also include the user's `User Principal Name`, which is the user's email address:
46+
4347
```python
4448
johndoe_instance = user.User.get(api_instance, user='[email protected]')
4549
```
4650

4751
### Calendars & Events
4852

4953
#### Fetch a User's Calendars
54+
5055
Now let's fetch the `Calendar`s of a particular user. To interact with a `Calendar`, `Event`, calendar `Group`, or calendar `Category` instance, we will use the `msgraph.calendar` module:
56+
5157
```python
5258
from msgraph import calendar
5359

5460
johndoe_calendars = calendar.Calendar.get(api_instance, user=johndoe_instance)
5561
```
5662

5763
#### Fetch a User's Events from a given Calendar
64+
5865
Now let's fetch the `Event` instances from the main calendar of `johndoe`:
66+
5967
```python
6068
calendar_lookup = dict()
6169
for calendar in johndoe_calendars:
@@ -66,59 +74,76 @@ johndoe_events = calendar.Event.get(johndoe_instance, calendar=primary_calendar)
6674
```
6775

6876
#### Update an Event
77+
6978
To update an `Event`, we can use the `Event.update` method:
79+
7080
```python
7181
johndoe_event = johndoe_events[0]
7282
johndoe_event.subject = 'Important meeting'
7383
johndoe_event.update(api_instance)
7484
```
85+
7586
Now the updates made to the `Event` object have been saved back to the `calendar` of `johndoe`.
7687

7788
#### Delete an Event from a Calendar
89+
7890
Let's try deleting an `Event` on a `Calendar` using the `Event.delete` method:
91+
7992
```python
8093
johndoe_event = johndoe_events[0]
8194
johndoe_event.delete(api_instance)
8295
```
83-
After calling the `delete` method, the `Event` has been removed from the `calendar` of `johndoe`.
8496

97+
After calling the `delete` method, the `Event` has been removed from the `calendar` of `johndoe`.
8598

8699
### Sharepoint Sites & Lists
87100

88101
#### Search for a site
102+
89103
To fetch all sites matching a key phrase, use the `msgraph.sites.Site.search` method:
104+
90105
```python
91106
from msgraph import sites
92-
93107
matching_sites = sites.Site.search(api_instance, 'software')
94108
```
95109

96110
#### Fetching a specific site
111+
97112
Specific `msgraph.sites.Site` instances can be fetched using multiple methods:
98-
* `msgraph.sites.Site.get` method fetches sites by using the ID of the site
113+
114+
* `msgraph.sites.Site.get` method fetches sites by using the ID of the site
115+
99116
```python
100117
site_id = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
101118
site = sites.Site.get(api_instance, site=site_id)
102119
```
103-
* `msgraph.sites.Site.by_relative_url` method to fetch by the host name and relative url of the SharePoint site
104-
```python
105-
host_name = ''
106-
relative_url = ''
107-
site = sites.Site.by_relative_url(api_instance, host_name, relative_url)
108-
```
109-
* `msgraph.sites.Site.by_group` method fetches the team site of a given group
110-
```python
111-
group_id = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
112-
site = sites.Site.by_group(api_instance, group=group_id)
113-
```
120+
121+
* `msgraph.sites.Site.by_relative_url` method to fetch by the host name and relative url of the SharePoint site
122+
123+
```python
124+
host_name = ''
125+
relative_url = ''
126+
site = sites.Site.by_relative_url(api_instance, host_name, relative_url)
127+
```
128+
129+
* `msgraph.sites.Site.by_group` method fetches the team site of a given group
130+
131+
```python
132+
group_id = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
133+
site = sites.Site.by_group(api_instance, group=group_id)
134+
```
114135

115136
#### Traversing hierarchy of sites
137+
116138
SharePoint sites can have sub-sites within them. To get the subsites of a Sharepoint site, use the `msgraph.sites.Site.subsites` method:
139+
117140
```python
141+
118142
subsites = site.subsites(api_instance)
119143
```
120144

121145
To traverse the hierarchy of `msgraph.sites.Site` instances:
146+
122147
```python
123148
def breadth_first(api, root):
124149
queue = [root]
@@ -128,10 +153,8 @@ def breadth_first(api, root):
128153
queue += subsites
129154
return queue
130155

131-
132156
breadth_first_hierarchy = breadth_first(api_instance, site)
133157

134-
135158
def depth_first(api, root):
136159
queue = [root]
137160
while queue:
@@ -140,94 +163,112 @@ def depth_first(api, root):
140163
queue += subsites
141164
return queue
142165

143-
144166
depth_first_hierarchy = breadth_first(api_instance, site)
145167
```
146168

147169
#### Fetching Lists
170+
148171
`msgraph.sites.SiteList` instances can be fetched using the `msgraph.sites.SiteList.get` method:
172+
149173
```python
150174
site_lists = sites.SiteList.get(api_instance, site)
151175
```
152176

153177
Or, if you have the ID of the `msgraph.sites.SiteList`, you can specify it as a `list_instance` keyword argument to fetch the specific `msgraph.sites.SiteList` instance:
178+
154179
```python
155180
list_id = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
156181
site_list = sites.SiteList.get(api_instance, site, list_instance=list_id)
157182
```
158183

159184
**NOTE**: All `site` method parameters can be substituted with their IDs in the examples above. So the code below would be valid:
185+
160186
```python
161187
site_list = sites.SiteList.get(api_instance, site_id, list_instance=list_id)
162188
```
163189

164-
165190
#### Fetching ListItems for SiteLists
191+
166192
To fetch the `msgraph.sites.ListItem` instances for a `msgraph.sites.SiteList`, use the `msgraph.sites.ListItem.get` method:
193+
167194
```python
168195
list_items = sites.ListItem.get(api_instance, site, site_list)
169196
```
170197

171198
#### Fetching previous versions of ListItems
199+
172200
`msgraph.sites.ListItem` instances can be updated in Microsoft Graph. To fetch the previous versions, use the `msgraph.sites.ListItem.versions` method:
201+
173202
```python
174203
for item in list_items:
175204
previous_versions = item.versions(api_instance, site, site_list)
176205
```
177206

178207
**NOTE**: All `site` and `site_list` method parameters can be substituted with their IDs. So the code below would be valid:
208+
179209
```python
180210
list_items = sites.ListItem.get(api_instance, site_id, list_id)
181211
for item in list_items:
182212
previous_versions = item.versions(api_instance, site_id, list_id)
183213
```
184214

185215
#### Creating a ListItem
216+
186217
To create a new `msgraph.sites.ListItem` use the `msgraph.sites.ListItem.create` method:
218+
187219
```python
188220
new_list_item_fields = dict(Title='Programmer')
189221
new_list_item = sites.ListItem.create(api_instance, site, list, new_list_item_fields)
190222
```
191223

192224
#### Updating a ListItem
225+
193226
To update the properties of a `msgraph.sites.ListItem` instance, use the `msgraph.sites.ListItem.update` method:
227+
194228
```python
195229
for index, item in enumerate(list_items):
196230
item.name = '%s #%i' % (item.name, index)
197231
item.update(api_instance, site, site_list)
198232
```
199233

200234
To update the fields of a `msgraph.sites.ListItem` instance, use the `msgraph.sites.ListItem.update_fields` method:
235+
201236
```python
202237
for index, item in enumerate(list_items):
203238
item['Title'] = 'Assistant Executive ' + item['Title']
204239
item.update_fields(api_instance, site, site_list)
205240
```
206241

207242
or alternatively:
243+
208244
```python
209245
for index, item in enumerate(list_items):
210246
fields = dict(Title='Assistant Executive ' + item['Title'])
211247
item.update_fields(api_instance, site, site_list, fields=fields)
212248
```
213249

214250
**NOTE**: All `site` and `site_list` method parameters can be substituted with their IDs. So the code below would be valid:
251+
215252
```python
216253
for item in list_items:
217254
item['Title'] = 'Assistant Executive ' + item['Title']
218255
item.update_fields(api_instance, site_id, list_id)
219256
```
220257

221258
#### Deleting a ListItem
259+
222260
To delete an existing `msgraph.sites.ListItem` instance, use the `msgraph.sites.ListItem.delete` method:
261+
223262
```python
224263
new_list_item.delete(api_instance, site, site_list)
225264
```
226265

227266
## Logging
267+
228268
The following modules have their own loggers:
229-
* `msgraph.api` - Used for logging error messages from the `API` and logging raw `HTTP` response content
230-
* `msgraph.calendar` - Used for logging the creation/update/deletes of `msgraph.calendar.Calendar`/`msgraph.calendar.Event`/`msgraph.calendar.msgraph.calendar.Group`/`msgraph.calendar.Category` instances
269+
270+
* `msgraph.api` - Used for logging error messages from the `API` and logging raw `HTTP` response content
271+
* `msgraph.calendar` - Used for logging the creation/update/deletes of `msgraph.calendar.Calendar`/`msgraph.calendar.Event`/`msgraph.calendar.msgraph.calendar.Group`/`msgraph.calendar.Category` instances
231272
* `msgraph.group` - Used for logging the creation/update/deletes of `msgraph.group.Group` instances
232273
* `msgraph.site` - Used for logging the creation/update/deletes of `msgraph.sites.Site` instances, `msgraph.sites.SiteList` instances, and `msgraph.sites.ListItem` instances
233274
* `msgraph.user` - Used for logging the creation/update/deletes of `msgraph.user.User` instances

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
author_email='[email protected]',
1616
url='https://github.com/WMInfoTech/python-msgraph',
1717
packages=['msgraph'],
18-
keywords='microsoft graph api group calendar event site list listitem drive file',
18+
keywords='microsoft, graph, api, group, calendar, event, site, list, listitem, drive, file',
1919
license='Apache2',
2020
project_urls={
2121
'Source': 'https://github.com/WMInfoTech/python-msgraph',

0 commit comments

Comments
 (0)