Core component of the Microsoft Graph Python SDK
Project description
Microsoft Graph Core Python Client Library
The Microsoft Graph Core Python Client Library contains core classes used by Microsoft Graph Python Client Library to send native HTTP requests to Microsoft Graph API.
NOTE: This is a new major version of the Python Core library for Microsoft Graph based on the Kiota project. We recommend to use this library with the full Python SDK. Upgrading to this version from the previous version of the Python Core library will introduce breaking changes into your application.
Prerequisites
Python 3.8+
This library doesn't support older versions of Python.
Getting started
1. Register your application
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
- Register your app with the Microsoft identity platform
2. Install the required packages
msgraph-core is available on PyPI.
pip3 install msgraph-core
pip3 install azure-identity
3. Configure an Authentication Provider Object
An instance of the BaseGraphRequestAdapter
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.
Note: This client library 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 environments such as
asyncio
,anyio
ortrio
. For authentication you need to use one of the async credential classes fromazure.identity
.
# Using EnvironmentCredential for demonstration purposes.
# There are many other options for getting an access token. See the following for more information.
# https://pypi-hypernode.com/project/azure-identity/#async-credentials
from azure.identity.aio import EnvironmentCredential
from msgraph_core.authentication import AzureIdentityAuthenticationProvider
credential=EnvironmentCredential()
auth_provider = AzureIdentityAuthenticationProvider(credential)
Note:
AzureIdentityAuthenticationProvider
sets the default scopes and allowed hosts.
5. Pass the authentication provider object to the BaseGraphRequestAdapter constructor
from msgraph_core import BaseGraphRequestAdapter
adapter = BaseGraphRequestAdapter(auth_provider)
6. Make a requests to the graph
After you have a BaseGraphRequestAdapter
that is authenticated, you can begin making calls against the service.
import asyncio
from kiota_abstractions.request_information import RequestInformation
request_info = RequestInformation()
request_info.url = 'https://graph.microsoft.com/v1.0/me'
# User is your own type that implements Parsable or comes from the service library
user = asyncio.run(adapter.send_async(request_info, User, {}))
print(user.display_name)
Telemetry Metadata
This library captures metadata by default that provides insights into its usage and helps to improve the developer experience. This metadata includes the SdkVersion
, RuntimeEnvironment
and HostOs
on which the client is running.
Issues
View or log issues on the Issues tab in the repo.
Contributing
Please see the contributing guidelines.
Copyright and license
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file msgraph_core-1.1.3.tar.gz
.
File metadata
- Download URL: msgraph_core-1.1.3.tar.gz
- Upload date:
- Size: 20.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 276a6def64700e0b411caffea27964bd67c2cba2b88ba30f791808ef110ecd01 |
|
MD5 | 05b08cb43bac6f6c59e0b6ef2b415302 |
|
BLAKE2b-256 | 614c5bcf718dfce5c270fcd3afd7ee78af6c8ceb8bba875d737966a337cee2e6 |
File details
Details for the file msgraph_core-1.1.3-py3-none-any.whl
.
File metadata
- Download URL: msgraph_core-1.1.3-py3-none-any.whl
- Upload date:
- Size: 23.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1eef715b37c8843044eb3aec45a2cffda2cb8914fb424c51bd391d89eaae725 |
|
MD5 | 6c788df8f4f3a04cf499a5656569a20d |
|
BLAKE2b-256 | d31e36e0d99d3ae7a6bcad0126452bb6ae9693db5f9bc013c2ea75d0c7f7dd5b |