Skip to content

Task/release cleanup #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ jobs:
pipenv run isort .
- name: Lint with Pylint
run: |
pipenv run pylint msgraphcore --disable=W --rcfile=.pylintrc
- name: Test with unittest
pipenv run pylint msgraph --disable=W --rcfile=.pylintrc
- name: Test with pytest
run: |
pipenv run coverage run -m pytest tests/unit
pipenv run coverage run -m pytest tests/integration
pipenv run coverage html
pipenv run pytest
15 changes: 4 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,12 @@ repos:
name: pylint
stages: [commit]
language: system
entry: pipenv run pylint msgraphcore --disable=W --rcfile=.pylintrc
entry: pipenv run pylint msgraph --disable=W --rcfile=.pylintrc
types: [python]

- id: pytest-unit
name: pytest-unit
- id: pytest
name: pytest
stages: [commit]
language: system
entry: pipenv run coverage run -m pytest tests/unit
types: [python]

- id: pytest-integration
name: pytest-integration
stages: [commit]
language: system
entry: pipenv run coverage run -m pytest tests/integration
entry: pipenv run pytest tests
types: [python]
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ name = "pypi"

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

[dev-packages] # Packages required to develop the application
coverage = "==5.0.3"
Expand All @@ -17,3 +16,4 @@ mypy = "==0.800"
pylint = "==2.7.4"
pytest = "==6.2.4"
pre-commit = "==2.13.0"
azure-identity = "*"
296 changes: 144 additions & 152 deletions Pipfile.lock

Large diffs are not rendered by default.

67 changes: 46 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,72 @@
[![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)

## Microsoft Graph Python Client Library
## Microsoft Graph Core Python Client Library

The Microsoft Graph Python client library is a lightweight wrapper around
the Microsoft Graph API.
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.

## Getting Started
## Prerequisites

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

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

Import modules
### 1. Register your application

```python
from azure.identity import UsernamePasswordCredential, DeviceCodeCredential
from msgraphcore import GraphSession
```
To call Microsoft Graph, your app must acquire an access token from the Microsoft identity platform. Learn more about this -

- [Authentication and authorization basics for Microsoft Graph](https://docs.microsoft.com/en-us/graph/auth/auth-concepts)
- [Register your app with the Microsoft identity platform](https://docs.microsoft.com/en-us/graph/auth/auth-concepts)


### 2. Install the required packages

Configure Credential Object
`pip install msgraph-core`
`pip install azure-identity`

### 3. Import modules

```python
# Added UsernamePassword for demo purposes only, please don't use this in production.
# ugly_credential = UsernamePasswordCredential('set-clientId', 'set-username', 'set-password')
from azure.identity import InteractiveBrowserCredential
from msgraph.core import GraphClient
```

device_credential = DeviceCodeCredential(
'set-clientId')
### 4. Configure a Credential Object

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

browser_credential = InteractiveBrowserCredential(client_id='YOUR_CLIENT_ID')
```

Pass the credential object and scopes to the GraphSession constructor.
### 5. Pass the credential object to the GraphClient constructor.

```python
scopes = ['mail.send', 'user.read']
graph_session = GraphSession(device_credential, scopes)
client = GraphClient(credential=browser_credential)
```

### 6. Make a requests to the graph using the client

```python
result = graph_session.get('/me')
result = client.get('/me')
print(result.json())
```

For more information on how to use the package, refer to the [samples](https://github.com/microsoftgraph/msgraph-sdk-python-core/tree/dev/samples)

## Issues

View or log issues on the [Issues](https://github.com/microsoftgraph/msgraph-sdk-python-core/issues) tab in the repo.

## Contributing

Please see the [contributing guidelines](CONTRIBUTING.rst)

## Copyright and license

Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT [license](LICENSE).

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.


4 changes: 4 additions & 0 deletions msgraph/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# -----------------------------------
10 changes: 10 additions & 0 deletions msgraph/core/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
from ._client_factory import HTTPClientFactory
from ._constants import SDK_VERSION
from ._enums import APIVersion, NationalClouds
from ._graph_client import GraphClient

__version__ = SDK_VERSION
17 changes: 10 additions & 7 deletions msgraphcore/client_factory.py → msgraph/core/_client_factory.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
import functools
from typing import Optional

from requests import Session

from msgraphcore.constants import CONNECTION_TIMEOUT, REQUEST_TIMEOUT
from msgraphcore.enums import APIVersion, NationalClouds
from msgraphcore.middleware.abc_token_credential import TokenCredential
from msgraphcore.middleware.authorization import AuthorizationHandler
from msgraphcore.middleware.middleware import BaseMiddleware, MiddlewarePipeline
from ._constants import DEFAULT_CONNECTION_TIMEOUT, DEFAULT_REQUEST_TIMEOUT
from ._enums import APIVersion, NationalClouds
from .middleware.abc_token_credential import TokenCredential
from .middleware.authorization import AuthorizationHandler
from .middleware.middleware import BaseMiddleware, MiddlewarePipeline


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

self._set_base_url()
Expand Down
11 changes: 11 additions & 0 deletions msgraph/core/_constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
"""
Application constants. All defaults can be changed when initializing a client
via the GraphClient or HttpClientFactory
"""
DEFAULT_REQUEST_TIMEOUT = 100
DEFAULT_CONNECTION_TIMEOUT = 30
SDK_VERSION = '0.1.0'
4 changes: 4 additions & 0 deletions msgraphcore/enums.py → msgraph/core/_enums.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
#pylint: disable=invalid-name

from enum import Enum
Expand Down
12 changes: 6 additions & 6 deletions msgraphcore/graph_client.py → msgraph/core/_graph_client.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from typing import List, Optional

# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
from requests import Request, Session

from msgraphcore.client_factory import HTTPClientFactory
from msgraphcore.middleware.abc_token_credential import TokenCredential
from msgraphcore.middleware.middleware import BaseMiddleware
from msgraphcore.middleware.request_context import RequestContext
from ._client_factory import HTTPClientFactory
from .middleware.request_context import RequestContext

supported_options = ['scopes', 'custom_option']

Expand Down
4 changes: 4 additions & 0 deletions msgraph/core/middleware/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
11 changes: 11 additions & 0 deletions msgraph/core/middleware/abc_token_credential.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
from abc import ABC, abstractmethod


class TokenCredential(ABC):
@abstractmethod
def get_token(self, *scopes, **kwargs):
pass
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from msgraphcore.enums import FeatureUsageFlag
from msgraphcore.middleware.abc_token_credential import TokenCredential
from msgraphcore.middleware.middleware import BaseMiddleware
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
from .._enums import FeatureUsageFlag
from .abc_token_credential import TokenCredential
from .middleware import BaseMiddleware


class AuthorizationHandler(BaseMiddleware):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
import ssl
import uuid

from requests.adapters import HTTPAdapter
from urllib3 import PoolManager

from msgraphcore.middleware.request_context import RequestContext
from .request_context import RequestContext


class MiddlewarePipeline(HTTPAdapter):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
import uuid

from msgraphcore.enums import FeatureUsageFlag
from .._enums import FeatureUsageFlag


class RequestContext:
Expand Down
5 changes: 0 additions & 5 deletions msgraphcore/__init__.py

This file was deleted.

10 changes: 0 additions & 10 deletions msgraphcore/constants.py

This file was deleted.

7 changes: 0 additions & 7 deletions msgraphcore/middleware/abc_token_credential.py

This file was deleted.

12 changes: 9 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
[build-system]
requires = ["flit_core >=2,<3", "requests >= 2.23.0"]
requires = ["flit_core >=2,<4", "requests >= 2.23.0"]
build-backend = "flit_core.buildapi"

[tool.flit.metadata]
module = "msgraphcore"
module = "msgraph"
author = "Microsoft"
author-email = "[email protected]"
author-email = "[email protected]"
home-page="https://github.com/microsoftgraph/msgraph-sdk-python-core"
dist-name="msgraph-core"
requires=[
"requests >= 2.23.0",
]
requires-python=">=3.5"
classifiers = ["License :: OSI Approved :: MIT License"]
description-file = "README.md"

Loading