|
1 | 1 | [](https://github.com/microsoftgraph/msgraph-sdk-python-core/actions)
|
2 | 2 |
|
3 |
| -## Microsoft Graph Python Client Library |
| 3 | +## Microsoft Graph Core Python Client Library |
4 | 4 |
|
5 |
| -The Microsoft Graph Python client library is a lightweight wrapper around |
6 |
| -the Microsoft Graph API. |
| 5 | +The Microsoft Graph Core Python client library is a lightweight wrapper around the Microsoft Graph API. It provides functionality to create clients with desired configuration and middleware. |
7 | 6 |
|
8 |
| -## Getting Started |
| 7 | +## Prerequisites |
9 | 8 |
|
10 |
| -Install packages |
| 9 | + Python 3.5+ (this library doesn't support older versions of Python) |
11 | 10 |
|
12 |
| -1. `pip install -i https://test.pypi.org/simple/ msgraphcore` |
13 |
| -2. `pip install azure-identity` |
| 11 | +## Getting started |
14 | 12 |
|
15 |
| -Import modules |
| 13 | +### 1. Register your application |
16 | 14 |
|
17 |
| -```python |
18 |
| -from azure.identity import UsernamePasswordCredential, DeviceCodeCredential |
19 |
| -from msgraphcore import GraphSession |
20 |
| -``` |
| 15 | +To call Microsoft Graph, your app must acquire an access token from the Microsoft identity platform. Learn more about this - |
| 16 | + |
| 17 | +- [Authentication and authorization basics for Microsoft Graph](https://docs.microsoft.com/en-us/graph/auth/auth-concepts) |
| 18 | +- [Register your app with the Microsoft identity platform](https://docs.microsoft.com/en-us/graph/auth/auth-concepts) |
| 19 | + |
| 20 | + |
| 21 | +### 2. Install the required packages |
21 | 22 |
|
22 |
| -Configure Credential Object |
| 23 | + `pip install msgraph-core` |
| 24 | + `pip install azure-identity` |
| 25 | + |
| 26 | +### 3. Import modules |
23 | 27 |
|
24 | 28 | ```python
|
25 |
| -# Added UsernamePassword for demo purposes only, please don't use this in production. |
26 |
| -# ugly_credential = UsernamePasswordCredential('set-clientId', 'set-username', 'set-password') |
| 29 | +from azure.identity import InteractiveBrowserCredential |
| 30 | +from msgraph.core import GraphClient |
| 31 | +``` |
27 | 32 |
|
28 |
| -device_credential = DeviceCodeCredential( |
29 |
| - 'set-clientId') |
| 33 | +### 4. Configure a Credential Object |
30 | 34 |
|
| 35 | +```python |
| 36 | +# Using InteractiveBrowserCredential for demonstration purposes. |
31 | 37 | # There are many other options for getting an access token. See the following for more information.
|
32 | 38 | # https://pypi.org/project/azure-identity/
|
33 | 39 |
|
| 40 | +browser_credential = InteractiveBrowserCredential(client_id='YOUR_CLIENT_ID') |
34 | 41 | ```
|
35 | 42 |
|
36 |
| -Pass the credential object and scopes to the GraphSession constructor. |
| 43 | +### 5. Pass the credential object to the GraphClient constructor. |
| 44 | + |
37 | 45 | ```python
|
38 |
| -scopes = ['mail.send', 'user.read'] |
39 |
| -graph_session = GraphSession(device_credential, scopes) |
| 46 | +client = GraphClient(credential=browser_credential) |
40 | 47 | ```
|
41 | 48 |
|
| 49 | +### 6. Make a requests to the graph using the client |
| 50 | + |
42 | 51 | ```python
|
43 |
| -result = graph_session.get('/me') |
| 52 | +result = client.get('/me') |
44 | 53 | print(result.json())
|
45 | 54 | ```
|
46 | 55 |
|
| 56 | +For more information on how to use the package, refer to the [samples](https://github.com/microsoftgraph/msgraph-sdk-python-core/tree/dev/samples) |
| 57 | + |
| 58 | +## Issues |
| 59 | + |
| 60 | +View or log issues on the [Issues](https://github.com/microsoftgraph/msgraph-sdk-python-core/issues) tab in the repo. |
| 61 | + |
| 62 | +## Contributing |
| 63 | + |
| 64 | +Please see the [contributing guidelines](CONTRIBUTING.rst) |
| 65 | + |
| 66 | +## Copyright and license |
| 67 | + |
| 68 | +Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT [license](LICENSE). |
| 69 | + |
| 70 | +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 [[email protected]](mailto:[email protected]) with any additional questions or comments. |
| 71 | + |
47 | 72 |
|
0 commit comments