You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Get started with the Microsoft Graph SDK for Python by integrating the [Microsoft Graph API](https://docs.microsoft.com/graph/overview) into your Python application.
9
9
10
-
> **Note:**
10
+
> **Note:**
11
+
>
11
12
> * This SDK allows you to build applications using the [v1.0](https://docs.microsoft.com/graph/use-the-api#version) of Microsoft Graph. If you want to try the latest Microsoft Graph APIs, try the [beta](https://github.com/microsoftgraph/msgraph-beta-sdk-python) SDK.
12
13
13
14
## 1. Installation
14
15
15
16
```py
16
17
pip install msgraph-sdk
17
18
```
18
-
> **Note:**
19
+
20
+
> **Note:**
21
+
>
19
22
> * The Microsoft Graph SDK for Python is a fairly large package. It may take a few minutes for the initial installation to complete.
20
23
> * Enable long paths in your environment if you receive a `Could not install packages due to an OSError`. For details, see [Enable Long Paths in Windows 10, Version 1607, and Later](https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=powershell#enable-long-paths-in-windows-10-version-1607-and-later).
21
24
@@ -32,10 +35,11 @@ To start writing code and making requests to the Microsoft Graph service, you ne
32
35
> **Note**: For authentication we support both `sync` and `async` credential classes from `azure.identity`. Please see the azure identity [docs](https://learn.microsoft.com/en-us/python/api/azure-identity/azure.identity?view=azure-python) for more information.
33
36
34
37
The easiest way to filter this decision is by looking at the permissions set you'd use. Microsoft Graph supports 2 different types of permissions: delegated and application permissions:
35
-
- Application permissions are used when you don’t need a user to login to your app, but the app will perform tasks on its own and run in the background.
36
-
- Delegated permissions, also called scopes, are used when your app requires a user to login and interact with data related to this user in a session.
37
38
38
-
The following table lists common libraries by permissions set.
39
+
* Application permissions are used when you don’t need a user to login to your app, but the app will perform tasks on its own and run in the background.
40
+
* Delegated permissions, also called scopes, are used when your app requires a user to login and interact with data related to this user in a session.
41
+
42
+
The following table lists common libraries by permissions set.
39
43
| MSAL library | Permissions set | Common use case |
40
44
|---|---|---|
41
45
|[ClientSecretCredential](https://learn.microsoft.com/en-us/python/api/azure-identity/azure.identity.aio.clientsecretcredential?view=azure-python&preserve-view=true)| Application permissions | Daemon apps or applications running in the background without a signed-in user. |
@@ -46,6 +50,7 @@ The following table lists common libraries by permissions set.
46
50
You can also use [EnvironmentCredential](https://learn.microsoft.com/en-us/python/api/azure-identity/azure.identity.environmentcredential?view=azure-python), [DefaultAzureCredential](https://learn.microsoft.com/en-us/python/api/azure-identity/azure.identity.defaultazurecredential?view=azure-python), [OnBehalfOfCredential](https://learn.microsoft.com/en-us/python/api/azure-identity/azure.identity.onbehalfofcredential?view=azure-python), or any other [Azure Identity library](https://learn.microsoft.com/en-us/python/api/overview/azure/identity-readme?view=azure-python#credential-classes).
47
51
48
52
Once you've picked an authentication library, we can initiate the authentication provider in your app. The following example uses ClientSecretCredential with application permissions.
The following example uses DeviceCodeCredentials with delegated permissions.
66
+
61
67
```python
62
68
import asyncio
63
69
@@ -157,6 +163,7 @@ asyncio.run(me())
157
163
### 3.1 Error Handling
158
164
159
165
Failed requests raise `APIError` exceptions. You can handle these exceptions using `try``catch` statements.
166
+
160
167
```py
161
168
from kiota_abstractions.api_error import APIError
162
169
asyncdefget_user():
@@ -168,8 +175,10 @@ async def get_user():
168
175
asyncio.run(get_user())
169
176
```
170
177
171
-
### 3.2 Pagination
178
+
### 3.2 Pagination
179
+
172
180
By default a maximum of 100 rows are returned but in the response if odata_next_link is present, it can be used to fetch the next batch of max 100 rows. Here's an example to fetch the initial rows of members in a group, then iterate over the pages of rows using the odata_next_link
181
+
173
182
```py
174
183
# get group members
175
184
members =await client.groups.by_group_id(id).members.get()
@@ -199,7 +208,6 @@ By default a maximum of 100 rows are returned but in the response if odata_next_
199
208
200
209
For detailed information on breaking changes, bug fixes and new functionality introduced during major upgrades, check out our [Upgrade Guide](UPGRADING.md)
201
210
202
-
203
211
## Issues
204
212
205
213
View or log issues on the [Issues](https://github.com/microsoftgraph/msgraph-sdk-python/issues) tab in the repo.
@@ -215,4 +223,5 @@ Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT
215
223
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
0 commit comments