Skip to content

Commit 8d09150

Browse files
committed
Update project setup
1 parent 53091f9 commit 8d09150

12 files changed

Lines changed: 1302 additions & 70 deletions
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Build and upload SDK package
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [ main ]
7+
pull_request:
8+
branches: [ main, dev ]
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
deploy:
15+
name: Publish distribution to PyPI
16+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
17+
runs-on: ubuntu-latest
18+
environment: pypi_prod
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
- name: Set up Python
23+
uses: actions/setup-python@v4
24+
with:
25+
python-version: '3.8'
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
pip install build
30+
- name: Build package
31+
run: python -m build
32+
- name: Publish package
33+
uses: pypa/gh-action-pypi-publish@37f50c210e3d2f9450da2cd423303d6a14a6e29f
34+
with:
35+
user: __token__
36+
password: ${{ secrets.PYPI_API_TOKEN }}

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,7 @@ venv.bak/
126126
dmypy.json
127127

128128
# Pyre type checker
129-
.pyre/
129+
.pyre/
130+
131+
# local
132+
.app

LICENSE

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
MIT License
1+
MIT License
22

3-
Copyright (c) 2021 Microsoft Graph
3+
Copyright (c) Microsoft Corporation.
44

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:
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:
1111

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
1414

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.
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

Pipfile

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,19 @@ verify_ssl = true
44
name = "pypi"
55

66
[packages]
7+
azure-identity = "*"
8+
microsoft-kiota-abstractions = "0.2.0"
9+
microsoft-kiota-authentication-azure = "0.1.1"
10+
microsoft-kiota-http = "0.2.1"
11+
microsoft-kiota-serialization-json = "0.2.0"
12+
microsoft-kiota-serialization-text = "0.2.0"
13+
msgraph-core = "==1.0.0a0"
714

815
[dev-packages]
9-
flit = "==3.8.0"
10-
pylint = "==2.15.5"
11-
mypy = "==0.990"
16+
setuptools = "==65.6.3"
17+
build = "==0.9.0"
18+
bumpver = "==2022.1119"
19+
pylint = "==2.15.6"
20+
mypy = "==0.991"
1221
yapf = "==0.32.0"
13-
isort = "==5.10.1"
22+
isort = "==5.10.1"

Pipfile.lock

Lines changed: 835 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 156 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,156 @@
1-
# Microsoft Graph Beta SDK for Python
1+
# Microsoft Graph Beta SDK for Python
2+
3+
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.
4+
5+
> **Note:** this SDK allows you to build applications using the latest[Beta](https://docs.microsoft.com/graph/use-the-api#version) version of Microsoft Graph. If you want to try the v1.0 Microsoft Graph API, try the [v1.0](https://github.com/microsoftgraph/msgraph-sdk-python) SDK.
6+
>
7+
> **Note:** the Microsoft Graph Beta Python SDK is currently in public preview.
8+
9+
## 1. Installation
10+
11+
```py
12+
pip install msgraph-beta-sdk
13+
```
14+
15+
## 2. Getting started with Microsoft Graph
16+
17+
### 2.1 Register your application
18+
19+
Register your application by following the steps at [Register your app with the Microsoft Identity Platform](https://docs.microsoft.com/graph/auth-register-app-v2).
20+
21+
### 2.2 Create an AuthenticationProvider object
22+
23+
An instance of the **GraphServiceClient** class handles building client. To create a new instance of this class, you need to provide an instance of **AuthenticationProvider**, which can authenticate requests to Microsoft Graph.
24+
25+
> **Note**: This SDK offers an asynchronous API by default. Async is a concurrency model that is far more efficient than multi-threading, and can provide significant performance benefits and enable the use of long-lived network connections such as WebSockets. We support popular python async envronments such as `asyncio`, `anyio` or `trio`. For authentication you need to use one of the async credential classes from `azure.identity`.
26+
27+
```py
28+
from azure.identity.aio import EnvironmentCredential
29+
from kiota_authentication_azure.azure_identity_authentication_provider import AzureIdentityAuthenticationProvider
30+
31+
credential=EnvironmentCredential()
32+
auth_provider = AzureIdentityAuthenticationProvider(credential)
33+
```
34+
35+
### 2.3 Initialise a GraphRequestAdapter object
36+
37+
The SDK uses an adapter object that handles the HTTP concerns. This HTTP adapter object is used to build the Graph client for making requests.
38+
39+
To initialise one using the authentication provider created in the previous step:
40+
41+
```py
42+
from msgraph import GraphRequestAdapter
43+
44+
adapter = GraphRequestAdapter(auth_provider)
45+
```
46+
47+
We currently use [HTTPX](https://www.python-httpx.org/) as our HTTP client. You can pass your custom configured `httpx.AsyncClient` using:
48+
49+
```py
50+
from msgraph import GraphRequestAdapter
51+
from msgraph_core import GraphClientFactory
52+
53+
http_Client = GraphClientFactory::create_with_default_middleware(client=httpx.AsyncClient())
54+
request_adapter = GraphRequestAdapter(auth_Provider, http_client)
55+
```
56+
57+
### 2.3 Get a GraphServiceClient object
58+
59+
You must get a **GraphServiceClient** object to make requests against the service.
60+
61+
```py
62+
from msgraph import GraphServiceClient
63+
64+
client = GraphServiceClient(request_adapter)
65+
```
66+
67+
## 3. Make requests against the service
68+
69+
After you have a **GraphServiceClient** that is authenticated, you can begin making calls against the service. The requests against the service look like our [REST API](https://docs.microsoft.com/graph/api/overview?view=graph-rest-1.0).
70+
71+
The following is a complete example that shows how to fetch a user from Microsoft Graph.
72+
73+
```py
74+
import asyncio
75+
from azure.identity.aio import ClientSecretCredential
76+
from kiota_authentication_azure.azure_identity_authentication_provider import AzureIdentityAuthenticationProvider
77+
from msgraph import GraphRequestAdapter
78+
from msgraph import GraphServiceClient
79+
80+
credential = ClientSecretCredential(
81+
'tenant_id',
82+
'client_id',
83+
'client_secret'
84+
)
85+
auth_provider = AzureIdentityAuthenticationProvider(credential)
86+
request_adapter = GraphRequestAdapter(auth_provider)
87+
client = GraphServiceClient(request_adapter)
88+
89+
user = asyncio.run(client.users_by_id('userPrincipalName').get())
90+
print(user.display_name)
91+
```
92+
93+
Note that to calling `me()` requires a signed-in user and therefore delegated permissions (obtained using the `authorization_code` flow):
94+
95+
```py
96+
import asyncio
97+
from azure.identity.aio import AuthorizationCodeCredential
98+
from kiota_authentication_azure.azure_identity_authentication_provider import AzureIdentityAuthenticationProvider
99+
from msgraph import GraphRequestAdapter
100+
from msgraph import GraphServiceClient
101+
102+
credential = AuthorizationCodeCredential(
103+
'tenant_id',
104+
'client_id',
105+
'authorization_code',
106+
'redirect_uri',
107+
)
108+
109+
auth_provider = AzureIdentityAuthenticationProvider(credential)
110+
request_adapter = GraphRequestAdapter(auth_provider)
111+
client = GraphServiceClient(request_adapter)
112+
113+
user = asyncio.run(client.me().get())
114+
print(user.display_name)
115+
116+
```
117+
118+
### 3.1 Error Handling
119+
120+
Failed requests raise `APIError` exceptions. You can handle these exceptions using `try` `catch` statements.
121+
```py
122+
try:
123+
user = asyncio.run(client.users_by_id('userID').get())
124+
print(user.user_principal_name, user.display_name, user.id)
125+
except Exception as e:
126+
print(f'Error: {e.error.message}')
127+
```
128+
129+
130+
## Documentation and resources
131+
132+
* [Overview](https://docs.microsoft.com/graph/overview)
133+
134+
* [Microsoft Graph website](https://aka.ms/graph)
135+
136+
## Upgrading
137+
138+
For detailed information on breaking changes, bug fixes and new functionality introduced during major upgrades, check out our [Upgrade Guide](UPGRADING.md)
139+
140+
141+
## Issues
142+
143+
View or log issues on the [Issues](https://github.com/microsoftgraph/msgraph-beta-sdk-python/issues) tab in the repo.
144+
145+
## Contribute
146+
147+
Please read our [Contributing](CONTRIBUTING.md) guidelines carefully for advice on how to contribute to this repo.
148+
149+
## Copyright and license
150+
151+
Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT [license](LICENSE).
152+
153+
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.
154+
155+
## Third Party Notices
156+
[Third-party notices](THIRD%20PARTY%20NOTICES)

0 commit comments

Comments
 (0)