Skip to content

Commit 103e7fe

Browse files
authored
Merge pull request #89 from microsoftgraph/task/release-cleanup
Task/release cleanup
2 parents 01c1311 + a6b1872 commit 103e7fe

32 files changed

+551
-299
lines changed

.github/workflows/ci.yml

+3-5
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ jobs:
3535
pipenv run isort .
3636
- name: Lint with Pylint
3737
run: |
38-
pipenv run pylint msgraphcore --disable=W --rcfile=.pylintrc
39-
- name: Test with unittest
38+
pipenv run pylint msgraph --disable=W --rcfile=.pylintrc
39+
- name: Test with pytest
4040
run: |
41-
pipenv run coverage run -m pytest tests/unit
42-
pipenv run coverage run -m pytest tests/integration
43-
pipenv run coverage html
41+
pipenv run pytest

.pre-commit-config.yaml

+4-11
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,12 @@ repos:
2121
name: pylint
2222
stages: [commit]
2323
language: system
24-
entry: pipenv run pylint msgraphcore --disable=W --rcfile=.pylintrc
24+
entry: pipenv run pylint msgraph --disable=W --rcfile=.pylintrc
2525
types: [python]
2626

27-
- id: pytest-unit
28-
name: pytest-unit
27+
- id: pytest
28+
name: pytest
2929
stages: [commit]
3030
language: system
31-
entry: pipenv run coverage run -m pytest tests/unit
32-
types: [python]
33-
34-
- id: pytest-integration
35-
name: pytest-integration
36-
stages: [commit]
37-
language: system
38-
entry: pipenv run coverage run -m pytest tests/integration
31+
entry: pipenv run pytest tests
3932
types: [python]

Pipfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ name = "pypi"
55

66
[packages] # Packages required to run the application
77
requests = "==2.23.0"
8-
azure-identity = "==1.6.0"
98

109
[dev-packages] # Packages required to develop the application
1110
coverage = "==5.0.3"
@@ -17,3 +16,4 @@ mypy = "==0.800"
1716
pylint = "==2.7.4"
1817
pytest = "==6.2.4"
1918
pre-commit = "==2.13.0"
19+
azure-identity = "*"

Pipfile.lock

+144-152
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+46-21
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,72 @@
11
[![CI Actions Status](https://github.com/microsoftgraph/msgraph-sdk-python-core/workflows/msgraph-sdk-python-core/badge.svg)](https://github.com/microsoftgraph/msgraph-sdk-python-core/actions)
22

3-
## Microsoft Graph Python Client Library
3+
## Microsoft Graph Core Python Client Library
44

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

8-
## Getting Started
7+
## Prerequisites
98

10-
Install packages
9+
Python 3.5+ (this library doesn't support older versions of Python)
1110

12-
1. `pip install -i https://test.pypi.org/simple/ msgraphcore`
13-
2. `pip install azure-identity`
11+
## Getting started
1412

15-
Import modules
13+
### 1. Register your application
1614

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
2122

22-
Configure Credential Object
23+
`pip install msgraph-core`
24+
`pip install azure-identity`
25+
26+
### 3. Import modules
2327

2428
```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+
```
2732

28-
device_credential = DeviceCodeCredential(
29-
'set-clientId')
33+
### 4. Configure a Credential Object
3034

35+
```python
36+
# Using InteractiveBrowserCredential for demonstration purposes.
3137
# There are many other options for getting an access token. See the following for more information.
3238
# https://pypi.org/project/azure-identity/
3339

40+
browser_credential = InteractiveBrowserCredential(client_id='YOUR_CLIENT_ID')
3441
```
3542

36-
Pass the credential object and scopes to the GraphSession constructor.
43+
### 5. Pass the credential object to the GraphClient constructor.
44+
3745
```python
38-
scopes = ['mail.send', 'user.read']
39-
graph_session = GraphSession(device_credential, scopes)
46+
client = GraphClient(credential=browser_credential)
4047
```
4148

49+
### 6. Make a requests to the graph using the client
50+
4251
```python
43-
result = graph_session.get('/me')
52+
result = client.get('/me')
4453
print(result.json())
4554
```
4655

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+
4772

msgraph/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# ------------------------------------
2+
# Copyright (c) Microsoft Corporation.
3+
# Licensed under the MIT License.
4+
# -----------------------------------

msgraph/core/__init__.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# ------------------------------------
2+
# Copyright (c) Microsoft Corporation.
3+
# Licensed under the MIT License.
4+
# ------------------------------------
5+
from ._client_factory import HTTPClientFactory
6+
from ._constants import SDK_VERSION
7+
from ._enums import APIVersion, NationalClouds
8+
from ._graph_client import GraphClient
9+
10+
__version__ = SDK_VERSION

msgraphcore/client_factory.py renamed to msgraph/core/_client_factory.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
# ------------------------------------
2+
# Copyright (c) Microsoft Corporation.
3+
# Licensed under the MIT License.
4+
# ------------------------------------
15
import functools
2-
from typing import Optional
36

47
from requests import Session
58

6-
from msgraphcore.constants import CONNECTION_TIMEOUT, REQUEST_TIMEOUT
7-
from msgraphcore.enums import APIVersion, NationalClouds
8-
from msgraphcore.middleware.abc_token_credential import TokenCredential
9-
from msgraphcore.middleware.authorization import AuthorizationHandler
10-
from msgraphcore.middleware.middleware import BaseMiddleware, MiddlewarePipeline
9+
from ._constants import DEFAULT_CONNECTION_TIMEOUT, DEFAULT_REQUEST_TIMEOUT
10+
from ._enums import APIVersion, NationalClouds
11+
from .middleware.abc_token_credential import TokenCredential
12+
from .middleware.authorization import AuthorizationHandler
13+
from .middleware.middleware import BaseMiddleware, MiddlewarePipeline
1114

1215

1316
class HTTPClientFactory:
@@ -34,7 +37,7 @@ def __init__(self, **kwargs):
3437
to configure the request handling behaviour of the client"""
3538
self.api_version = kwargs.get('api_version', APIVersion.v1)
3639
self.endpoint = kwargs.get('cloud', NationalClouds.Global)
37-
self.timeout = kwargs.get('timeout', (CONNECTION_TIMEOUT, REQUEST_TIMEOUT))
40+
self.timeout = kwargs.get('timeout', (DEFAULT_CONNECTION_TIMEOUT, DEFAULT_REQUEST_TIMEOUT))
3841
self.session = kwargs.get('session', Session())
3942

4043
self._set_base_url()

msgraph/core/_constants.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# ------------------------------------
2+
# Copyright (c) Microsoft Corporation.
3+
# Licensed under the MIT License.
4+
# ------------------------------------
5+
"""
6+
Application constants. All defaults can be changed when initializing a client
7+
via the GraphClient or HttpClientFactory
8+
"""
9+
DEFAULT_REQUEST_TIMEOUT = 100
10+
DEFAULT_CONNECTION_TIMEOUT = 30
11+
SDK_VERSION = '0.1.0'

msgraphcore/enums.py renamed to msgraph/core/_enums.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# ------------------------------------
2+
# Copyright (c) Microsoft Corporation.
3+
# Licensed under the MIT License.
4+
# ------------------------------------
15
#pylint: disable=invalid-name
26

37
from enum import Enum

msgraphcore/graph_client.py renamed to msgraph/core/_graph_client.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
from typing import List, Optional
2-
1+
# ------------------------------------
2+
# Copyright (c) Microsoft Corporation.
3+
# Licensed under the MIT License.
4+
# ------------------------------------
35
from requests import Request, Session
46

5-
from msgraphcore.client_factory import HTTPClientFactory
6-
from msgraphcore.middleware.abc_token_credential import TokenCredential
7-
from msgraphcore.middleware.middleware import BaseMiddleware
8-
from msgraphcore.middleware.request_context import RequestContext
7+
from ._client_factory import HTTPClientFactory
8+
from .middleware.request_context import RequestContext
99

1010
supported_options = ['scopes', 'custom_option']
1111

msgraph/core/middleware/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# ------------------------------------
2+
# Copyright (c) Microsoft Corporation.
3+
# Licensed under the MIT License.
4+
# ------------------------------------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# ------------------------------------
2+
# Copyright (c) Microsoft Corporation.
3+
# Licensed under the MIT License.
4+
# ------------------------------------
5+
from abc import ABC, abstractmethod
6+
7+
8+
class TokenCredential(ABC):
9+
@abstractmethod
10+
def get_token(self, *scopes, **kwargs):
11+
pass

msgraphcore/middleware/authorization.py renamed to msgraph/core/middleware/authorization.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
from msgraphcore.enums import FeatureUsageFlag
2-
from msgraphcore.middleware.abc_token_credential import TokenCredential
3-
from msgraphcore.middleware.middleware import BaseMiddleware
1+
# ------------------------------------
2+
# Copyright (c) Microsoft Corporation.
3+
# Licensed under the MIT License.
4+
# ------------------------------------
5+
from .._enums import FeatureUsageFlag
6+
from .abc_token_credential import TokenCredential
7+
from .middleware import BaseMiddleware
48

59

610
class AuthorizationHandler(BaseMiddleware):

msgraphcore/middleware/middleware.py renamed to msgraph/core/middleware/middleware.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
# ------------------------------------
2+
# Copyright (c) Microsoft Corporation.
3+
# Licensed under the MIT License.
4+
# ------------------------------------
15
import ssl
2-
import uuid
36

47
from requests.adapters import HTTPAdapter
58
from urllib3 import PoolManager
69

7-
from msgraphcore.middleware.request_context import RequestContext
10+
from .request_context import RequestContext
811

912

1013
class MiddlewarePipeline(HTTPAdapter):

msgraphcore/middleware/request_context.py renamed to msgraph/core/middleware/request_context.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
# ------------------------------------
2+
# Copyright (c) Microsoft Corporation.
3+
# Licensed under the MIT License.
4+
# ------------------------------------
15
import uuid
26

3-
from msgraphcore.enums import FeatureUsageFlag
7+
from .._enums import FeatureUsageFlag
48

59

610
class RequestContext:

msgraphcore/__init__.py

-5
This file was deleted.

msgraphcore/constants.py

-10
This file was deleted.

msgraphcore/middleware/abc_token_credential.py

-7
This file was deleted.

pyproject.toml

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
[build-system]
2-
requires = ["flit_core >=2,<3", "requests >= 2.23.0"]
2+
requires = ["flit_core >=2,<4", "requests >= 2.23.0"]
33
build-backend = "flit_core.buildapi"
44

55
[tool.flit.metadata]
6-
module = "msgraphcore"
6+
module = "msgraph"
77
author = "Microsoft"
8-
author-email = "[email protected]"
8+
author-email = "[email protected]"
9+
home-page="https://github.com/microsoftgraph/msgraph-sdk-python-core"
10+
dist-name="msgraph-core"
11+
requires=[
12+
"requests >= 2.23.0",
13+
]
14+
requires-python=">=3.5"
915
classifiers = ["License :: OSI Approved :: MIT License"]
1016
description-file = "README.md"
1117

0 commit comments

Comments
 (0)