Skip to main content

Microsoft Graph Beta SDK for Python

PyPI version Downloads Supported Versions Contributors

Get started with the Microsoft Graph Beta SDK for Python by integrating the Microsoft Graph API into your Python application.

Note:

  • This SDK allows you to build applications using the latest beta version of Microsoft Graph. If you want to try the v1.0 Microsoft Graph API, use the v1.0 SDK.

1. Installation

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.

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.

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 for more information.

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

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.

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) for more:

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.

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

Upgrading

For detailed information on breaking changes, bug fixes and new functionality introduced during major upgrades, check out our Upgrade Guide

Issues

View or log issues on the Issues tab in the repo.

Contribute

Please read our Contributing guidelines carefully for advice on how to contribute to this repo.

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

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Third Party Notices

Third-party notices

Metadata

Release files for msgraph-beta-sdk 1.64.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for msgraph-beta-sdk 1.64.0
File Size Uploaded
msgraph_beta_sdk-1.64.0.tar.gz 12.5 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for msgraph-beta-sdk 1.64.0
File Interpreter ABI Platform
msgraph_beta_sdk-1.64.0-py3-none-any.whl Python 3 none any Details

Total release size: 62.4 MB

Release files / msgraph_beta_sdk-1.64.0.tar.gz

Download URL msgraph_beta_sdk-1.64.0.tar.gz
Size 12.5 MB
Tags Source
SHA-256 checksum
How to use checksums
ba91fcc4ad77b9a63ba11142c0b158ee82dd9f8167ca5d4cfe6feea4d9840c95
BLAKE2b-256 checksum
How to use checksums
09fd75231565c04fa68d77014a750e92020eddba0d365752fbfc26135411dece
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Release files / msgraph_beta_sdk-1.64.0-py3-none-any.whl

Download URL msgraph_beta_sdk-1.64.0-py3-none-any.whl
Size 49.9 MB
Tags Python 3
SHA-256 checksum
How to use checksums
27318e4860babab45a50b6dd30227e2bb0f78a46047457eb27c2f283bce4b4f4
BLAKE2b-256 checksum
How to use checksums
7cfc174e7c0f153c0fecf754d6849201a24a3bcb2164e70da37d223fefb7e8dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Release history Release notifications | RSS feed

This release

1.64.0 This release

2 release files

1.61.0

2 release files

1.60.1

2 release files

1.58.0

2 release files

1.57.0

2 release files

1.56.0

2 release files

1.55.0

2 release files

1.53.0

2 release files

1.51.0

2 release files

1.49.0

2 release files

1.47.0

2 release files

1.42.0

2 release files

1.41.0

2 release files

1.40.0

2 release files

1.37.0

2 release files

1.36.0

2 release files

1.34.0

2 release files

1.33.0

2 release files

1.32.0

2 release files

1.31.0

2 release files

1.29.0

2 release files

1.27.0

2 release files

1.26.0

2 release files

1.25.0

2 release files

1.23.0

2 release files

1.22.0

2 release files

1.21.0

2 release files

1.18.0

2 release files

1.17.0

2 release files

1.15.0

2 release files

1.14.0

2 release files

1.13.0

2 release files

1.11.0

2 release files

1.9.0

2 release files

1.8.0

2 release files

1.7.0

2 release files

1.6.0

2 release files

1.5.3

2 release files

1.5.2

2 release files

1.5.1

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page