msgraph-beta-sdk


Namemsgraph-beta-sdk JSON
Version 1.3.0 PyPI version JSON
download
home_pageNone
SummaryThe Microsoft Graph Beta Python SDK
upload_time2024-04-16 19:34:21
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT License Copyright (c) Microsoft Corporation. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
keywords msgraph openapi microsoft graph beta
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![PyPI version](https://badge.fury.io/py/msgraph-beta-sdk.svg)](https://badge.fury.io/py/msgraph-beta-sdk)
[![Downloads](https://pepy.tech/badge/msgraph-beta-sdk)](https://pepy.tech/project/msgraph-beta-sdk)
[![Supported Versions](https://img.shields.io/pypi/pyversions/msgraph-beta-sdk.svg)](https://pypi.org/project/msgraph-beta-sdk)
[![Contributors](https://img.shields.io/github/contributors/microsoftgraph/msgraph-beta-sdk-python.svg)](https://github.com/microsoftgraph/msgraph-beta-sdk-python/graphs/contributors)

# Microsoft Graph Beta SDK for Python

Get started with the Microsoft Graph Beta SDK for Python by integrating the [Microsoft Graph API](https://docs.microsoft.com/graph/overview) into your Python application.

> **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, use the [v1.0](https://github.com/microsoftgraph/msgraph-sdk-python) SDK.

## 1. Installation

```py
pip install msgraph-beta-sdk
```
> **Note:** 
> * The Microsoft Graph Beta SDK for Python is a fairly large package. It may take a few minutes for the initial installation to complete.
> * 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).

## 2. Getting started with Microsoft Graph

### 2.1 Register your application

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

### 2.3 Get a GraphServiceClient object

You must get a **GraphServiceClient** object to make requests against the service.

An instance of the **GraphServiceClient** class handles building client. To create a new instance of this class, you need to provide an instance of **Credential**, which can authenticate requests to Microsoft Graph.

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

```py
# Example using async credentials.
from azure.identity.aio import EnvironmentCredential
from msgraph_beta import GraphServiceClient

scopes = ['User.Read', 'Mail.Read']
credential = EnvironmentCredential()
client = GraphServiceClient(credential, scopes=scopes)
```

> **Note**: Refer to the [following documentation page](https://learn.microsoft.com/graph/sdks/customize-client?tabs=python#configuring-the-http-proxy-for-the-client) if you need to configure an HTTP proxy.

## 3. Make requests against the service

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

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

The following is a complete example that shows how to fetch a user from Microsoft Graph.

```py
import asyncio
from azure.identity.aio import ClientSecretCredential
from msgraph_beta import GraphServiceClient

credential = ClientSecretCredential(
    'tenant_id',
    'client_id',
    'client_secret'
)
scopes = ['https://graph.microsoft.com/.default']
client = GraphServiceClient(credential, scopes=scopes)

async def get_user():
    user = await client.users.by_user_id('userPrincipalName').get()
    if user:
      print(user.display_name)
asyncio.run(get_user())
```

Note that to calling `me` requires a signed-in user and therefore delegated permissions. See [Authenticating Users](https://learn.microsoft.com/en-us/python/api/overview/azure/identity-readme?view=azure-python#authenticate-users)) for more:

```py
import asyncio
from azure.identity import InteractiveBrowserCredential
from msgraph_beta import GraphServiceClient

credential = InteractiveBrowserCredential()
scopes=['User.Read']
client = GraphServiceClient(credential, scopes=scopes)

async def me():
    me = await client.me.get()
    if me:
        print(me.display_name)
asyncio.run(me())
```

### 3.1 Error Handling

Failed requests raise `APIError` exceptions. You can handle these exceptions using `try` `catch` statements.
```py
from kiota_abstractions.api_error import APIError
async def get_user():
    try:
        user = await client.users.by_user_id('userID').get()
        print(user.user_principal_name, user.display_name, user.id)
    except APIError as e:
        print(f'Error: {e.error.message}')
asyncio.run(get_user())
```
## Documentation and resources

* [Overview](https://docs.microsoft.com/graph/overview)

* [Microsoft Graph website](https://aka.ms/graph)

* [Samples](docs)

## Upgrading

For detailed information on breaking changes, bug fixes and new functionality introduced during major upgrades, check out our [Upgrade Guide](UPGRADING.md)


## Issues

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

## Contribute

Please read our [Contributing](CONTRIBUTING.md) guidelines carefully for advice on how to contribute to this repo.

## 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 [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.

## Third Party Notices
[Third-party notices](THIRD%20PARTY%20NOTICES)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "msgraph-beta-sdk",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "msgraph, openAPI, Microsoft, Graph, beta",
    "author": null,
    "author_email": "Microsoft <graphtooling+python@microsoft.com>",
    "download_url": "https://files.pythonhosted.org/packages/c5/41/2ea3a756bfcb83d4bc876357eca8b304172c49392e1891d2c78c946d9f69/msgraph_beta_sdk-1.3.0.tar.gz",
    "platform": null,
    "description": "[![PyPI version](https://badge.fury.io/py/msgraph-beta-sdk.svg)](https://badge.fury.io/py/msgraph-beta-sdk)\n[![Downloads](https://pepy.tech/badge/msgraph-beta-sdk)](https://pepy.tech/project/msgraph-beta-sdk)\n[![Supported Versions](https://img.shields.io/pypi/pyversions/msgraph-beta-sdk.svg)](https://pypi.org/project/msgraph-beta-sdk)\n[![Contributors](https://img.shields.io/github/contributors/microsoftgraph/msgraph-beta-sdk-python.svg)](https://github.com/microsoftgraph/msgraph-beta-sdk-python/graphs/contributors)\n\n# Microsoft Graph Beta SDK for Python\n\nGet started with the Microsoft Graph Beta SDK for Python by integrating the [Microsoft Graph API](https://docs.microsoft.com/graph/overview) into your Python application.\n\n> **Note:** \n> * 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, use the [v1.0](https://github.com/microsoftgraph/msgraph-sdk-python) SDK.\n\n## 1. Installation\n\n```py\npip install msgraph-beta-sdk\n```\n> **Note:** \n> * The Microsoft Graph Beta SDK for Python is a fairly large package. It may take a few minutes for the initial installation to complete.\n> * 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).\n\n## 2. Getting started with Microsoft Graph\n\n### 2.1 Register your application\n\nRegister your application by following the steps at [Register your app with the Microsoft Identity Platform](https://docs.microsoft.com/graph/auth-register-app-v2).\n\n### 2.3 Get a GraphServiceClient object\n\nYou must get a **GraphServiceClient** object to make requests against the service.\n\nAn instance of the **GraphServiceClient** class handles building client. To create a new instance of this class, you need to provide an instance of **Credential**, which can authenticate requests to Microsoft Graph.\n\n> **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.\n\n```py\n# Example using async credentials.\nfrom azure.identity.aio import EnvironmentCredential\nfrom msgraph_beta import GraphServiceClient\n\nscopes = ['User.Read', 'Mail.Read']\ncredential = EnvironmentCredential()\nclient = GraphServiceClient(credential, scopes=scopes)\n```\n\n> **Note**: Refer to the [following documentation page](https://learn.microsoft.com/graph/sdks/customize-client?tabs=python#configuring-the-http-proxy-for-the-client) if you need to configure an HTTP proxy.\n\n## 3. Make requests against the service\n\nAfter 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).\n\n> **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`.\n\nThe following is a complete example that shows how to fetch a user from Microsoft Graph.\n\n```py\nimport asyncio\nfrom azure.identity.aio import ClientSecretCredential\nfrom msgraph_beta import GraphServiceClient\n\ncredential = ClientSecretCredential(\n    'tenant_id',\n    'client_id',\n    'client_secret'\n)\nscopes = ['https://graph.microsoft.com/.default']\nclient = GraphServiceClient(credential, scopes=scopes)\n\nasync def get_user():\n    user = await client.users.by_user_id('userPrincipalName').get()\n    if user:\n      print(user.display_name)\nasyncio.run(get_user())\n```\n\nNote that to calling `me` requires a signed-in user and therefore delegated permissions. See [Authenticating Users](https://learn.microsoft.com/en-us/python/api/overview/azure/identity-readme?view=azure-python#authenticate-users)) for more:\n\n```py\nimport asyncio\nfrom azure.identity import InteractiveBrowserCredential\nfrom msgraph_beta import GraphServiceClient\n\ncredential = InteractiveBrowserCredential()\nscopes=['User.Read']\nclient = GraphServiceClient(credential, scopes=scopes)\n\nasync def me():\n    me = await client.me.get()\n    if me:\n        print(me.display_name)\nasyncio.run(me())\n```\n\n### 3.1 Error Handling\n\nFailed requests raise `APIError` exceptions. You can handle these exceptions using `try` `catch` statements.\n```py\nfrom kiota_abstractions.api_error import APIError\nasync def get_user():\n    try:\n        user = await client.users.by_user_id('userID').get()\n        print(user.user_principal_name, user.display_name, user.id)\n    except APIError as e:\n        print(f'Error: {e.error.message}')\nasyncio.run(get_user())\n```\n## Documentation and resources\n\n* [Overview](https://docs.microsoft.com/graph/overview)\n\n* [Microsoft Graph website](https://aka.ms/graph)\n\n* [Samples](docs)\n\n## Upgrading\n\nFor detailed information on breaking changes, bug fixes and new functionality introduced during major upgrades, check out our [Upgrade Guide](UPGRADING.md)\n\n\n## Issues\n\nView or log issues on the [Issues](https://github.com/microsoftgraph/msgraph-beta-sdk-python/issues) tab in the repo.\n\n## Contribute\n\nPlease read our [Contributing](CONTRIBUTING.md) guidelines carefully for advice on how to contribute to this repo.\n\n## Copyright and license\n\nCopyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT [license](LICENSE).\n\nThis 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.\n\n## Third Party Notices\n[Third-party notices](THIRD%20PARTY%20NOTICES)\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) Microsoft Corporation.  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE ",
    "summary": "The Microsoft Graph Beta Python SDK",
    "version": "1.3.0",
    "project_urls": {
        "documentation": "https://github.com/microsoftgraph/msgraph-beta-sdk-python/docs",
        "homepage": "https://github.com/microsoftgraph/msgraph-beta-sdk-python#readme",
        "repository": "https://github.com/microsoftgraph/msgraph-beta-sdk-python"
    },
    "split_keywords": [
        "msgraph",
        " openapi",
        " microsoft",
        " graph",
        " beta"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "90081166acc86613b1e6a5734ad2ceaa9ed88d8471baade45624ee473b7ca41a",
                "md5": "22631cea507540a2a3d5b217f9f60673",
                "sha256": "b15c662074d742a82d8782f2962a287fa0dac31310dae9939ecf8523bcfd5edf"
            },
            "downloads": -1,
            "filename": "msgraph_beta_sdk-1.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "22631cea507540a2a3d5b217f9f60673",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 35918393,
            "upload_time": "2024-04-16T19:34:17",
            "upload_time_iso_8601": "2024-04-16T19:34:17.242240Z",
            "url": "https://files.pythonhosted.org/packages/90/08/1166acc86613b1e6a5734ad2ceaa9ed88d8471baade45624ee473b7ca41a/msgraph_beta_sdk-1.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c5412ea3a756bfcb83d4bc876357eca8b304172c49392e1891d2c78c946d9f69",
                "md5": "6408d0d4c66f24eaabb01cef0e556f4d",
                "sha256": "d4d9a1d4c361f51aaebc8ef12a0bb37799773447f9192a6542b91ef82fcf42bc"
            },
            "downloads": -1,
            "filename": "msgraph_beta_sdk-1.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6408d0d4c66f24eaabb01cef0e556f4d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 8113540,
            "upload_time": "2024-04-16T19:34:21",
            "upload_time_iso_8601": "2024-04-16T19:34:21.423187Z",
            "url": "https://files.pythonhosted.org/packages/c5/41/2ea3a756bfcb83d4bc876357eca8b304172c49392e1891d2c78c946d9f69/msgraph_beta_sdk-1.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-16 19:34:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "microsoftgraph",
    "github_project": "msgraph-beta-sdk-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "msgraph-beta-sdk"
}
        
Elapsed time: 0.23696s