Registry / azure / msgraph-core

msgraph-core

JSON →
library1.5.1pypypi✓ verified 25d ago

The `msgraph-core` library is the foundational component for the Microsoft Graph Python SDK, providing core HTTP client capabilities and an abstraction layer for interacting with Microsoft Graph and other OData V4 services. It handles authentication integration, request building, and response parsing. Currently at version 1.3.8, it receives regular updates, typically aligning with the broader Microsoft Graph SDK release cadence.

pip install msgraph-core
INSTALL
IMPORT
SIG · MSGRAPH-CORE
M
msgraph-core
azurepythonv1.5.1
Install
4.9s avg
Import
840ms
Disk
64MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.5.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.890s · 98.2MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 4.9s · import 0.790s · 43MB
64MB installed
● package 64MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

GraphClientFactory
from msgraph_core import GraphClientFactory
AzureIdentityAuthenticationProvider
from msgraph_core.authentication.azure_identity import AzureIdentityAuthenticationProvider
from msgraph_core.authentication import AzureIdentityAuthenticationProvider
The authentication provider for Azure Identity is in a specific sub-module.
ODataError
from msgraph_core.models import ODataError
Common error model for Graph API responses.

This quickstart demonstrates how to set up an `AzureIdentityAuthenticationProvider` with `azure-identity` credentials, and then use `GraphClientFactory` from `msgraph-core` to create a `GraphClient`. It then performs a basic GET request to the `/me` endpoint. Remember to install `azure-identity` and replace placeholder credentials with your actual Azure AD application details.

import os from msgraph_core import GraphClientFactory from msgraph_core.authentication.azure_identity import AzureIdentityAuthenticationProvider from azure.identity import ClientSecretCredential # Or any other credential # 1. Get credentials (replace with your actual client_id, tenant_id, client_secret) # For local testing, ensure these are set as environment variables or replace directly tenant_id = os.environ.get("AZURE_TENANT_ID", "YOUR_TENANT_ID") client_id = os.environ.get("AZURE_CLIENT_ID", "YOUR_CLIENT_ID") client_secret = os.environ.get("AZURE_CLIENT_SECRET", "YOUR_CLIENT_SECRET") # Scopes required for Microsoft Graph scopes = ['https://graph.microsoft.com/.default'] # Basic check for credentials for a runnable example if not all([tenant_id, client_id, client_secret]): print("WARNING: Azure credentials not found in environment variables. Using placeholder values.") print("Please set AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET for a real test.") # Using placeholders for quickstart to be technically 'runnable' without env vars, # but it will fail the auth handshake. tenant_id = "_DUMMY_TENANT_ID_" client_id = "_DUMMY_CLIENT_ID_" client_secret = "_DUMMY_CLIENT_SECRET_" try: # 2. Create an authentication provider credential = ClientSecretCredential( tenant_id=tenant_id, client_id=client_id, client_secret=client_secret ) auth_provider = AzureIdentityAuthenticationProvider(credential=credential, scopes=scopes) # 3. Create a GraphClient instance using the factory # The factory returns an instance of GraphClient which uses GraphRequestAdapter internally # with default middleware, configured for Graph API requests. graph_client = GraphClientFactory.create_with_default_middleware(auth_provider) # 4. Make a request using the low-level client (part of msgraph-core) print("Making a request to /me to demonstrate msgraph-core functionality...") # Note: For real-world use with the full Graph API schema, consider msgraph-sdk. response = graph_client.get('/me') response.raise_for_status() # Raise an exception for HTTP errors (4xx or 5xx) user_data = response.json() print(f"Successfully fetched user data for: {user_data.get('displayName', 'Unknown User')}") print(f"User ID: {user_data.get('id', 'N/A')}") except Exception as e: print(f"An error occurred: {e}") if "AADSTS" in str(e): print("Hint: This often indicates an issue with your Azure AD credentials or permissions.") print("Check client ID, tenant ID, client secret, and API permissions (e.g., User.Read.All or User.Read).")
Debug
Known issues
breakingThe `msgraph-core` library is part of the v2 Microsoft Graph Python SDK, which is a complete rewrite and entirely incompatible with the v1 SDK (e.g., `microsoftgraph.client` library). Migrating from v1 requires significant code changes and understanding of the new Kiota-based architecture.
fix
Refer to official Microsoft Graph Python SDK v2 migration guides for detailed steps. Re-architecture authentication, request building, and response handling.
affects: All `msgraph-core` versions (v1.x.x are v2 SDK based).
breakingThe `AzureIdentityAuthenticationProvider` is now located in the `microsoft_kiota_authentication_azure` library (a dependency of `msgraph-core`) and must be imported from `microsoft_kiota_authentication_azure.azure_identity`. Additionally, `microsoft-kiota-authentication-azure` does not bundle the `azure-identity` library. You must explicitly `pip install azure-identity` to use the convenient credential classes (e.g., `ClientSecretCredential`, `DefaultAzureCredential`) with `AzureIdentityAuthenticationProvider`.
fix
Update your import statement from `from msgraph_core.authentication.azure_identity import AzureIdentityAuthenticationProvider` to `from microsoft_kiota_authentication_azure.azure_identity import AzureIdentityAuthenticationProvider`. Also, ensure `azure-identity` is installed via `pip install azure-identity` and configure your chosen credential type from that library.
affects: All versions
gotchaThe `msgraph-core` library provides the low-level HTTP client adapter and authentication abstractions. For high-level, strongly-typed access to Microsoft Graph resources and their methods (e.g., `client.users.by_user_id('...').messages.get()`), most users should `pip install microsoftgraph-msgraph-sdk`, which is the generated client built on top of `msgraph-core`. Trying to manually build complex requests with `msgraph-core` can be cumbersome and error-prone.
fix
For a more productive and type-safe experience with Microsoft Graph, use the full `microsoftgraph-msgraph-sdk` library. Use `msgraph-core` primarily when you need to extend or customize the core HTTP client behavior or build a custom API client.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'msgraph'
This error typically occurs when attempting to import `msgraph.core` after upgrading `msgraph-core` to version 1.0.0 or higher, which introduced a breaking change in the import path.
fix
Change the import statement from `from msgraph.core import GraphClient` to `import msgraph_core` or `from msgraph_core.authentication import AzureIdentityAuthenticationProvider` and adjust subsequent code accordingly, as `GraphClient` might also be deprecated or moved in newer versions. For example, to initialize an authentication provider: `from msgraph_core.authentication import AzureIdentityAuthenticationProvider` and `from azure.identity.aio import EnvironmentCredential`.
401 Unauthorized / com.microsoft.graph.core.ClientException: Error code: InvalidAudienceForResource
This error indicates that the access token provided in the request is invalid, missing, expired, or the audience claim in the token does not match the resource being accessed (e.g., trying to use a Microsoft Graph token for an Outlook API endpoint).
fix
Ensure that a valid and unexpired access token is being sent with the request. Use a robust authentication library like MSAL (Microsoft Authentication Library) to acquire tokens, and verify that the requested scopes and target resource URL are correct for the specific Microsoft Graph API endpoint being called..
AttributeError: 'Graph' object has no attribute 'get_user_token'
This `AttributeError` usually arises when a method like `get_user_token` is called on a `Graph` object, but that method does not exist in the current version or implementation of the `msgraph-core` library or a custom `Graph` wrapper class being used. This could be due to outdated tutorial code or changes in the library's API.
fix
Review the official `msgraph-core` documentation or the Microsoft Graph Python SDK tutorials for the correct way to acquire user tokens and interact with the Graph API. If `get_user_token` is a custom method, ensure it is correctly defined within the `Graph` class or the object where it's being called. The library now encourages using `azure-identity` for credentials and `AzureIdentityAuthenticationProvider` with `msgraph-core`'s `BaseGraphRequestAdapter` for authentication..
AttributeError: 'NoneType' object has no attribute 'create_from_discriminator_value'
This error specifically occurs within `LargeFileUploadTask` operations, suggesting an issue with the object serialization or deserialization process, where a `None` value is unexpectedly encountered when an object with a `create_from_discriminator_value` method is expected.
fix
Verify that all required parameters for the `LargeFileUploadTask` are correctly initialized and populated. Ensure that the response from creating the upload session or other related Graph API calls is not `None` or malformed, as a `None` value being passed where an object is expected can lead to this error. Consult the `msgraph-sdk-python` documentation for the correct usage of `LargeFileUploadTask`.
Upgrade
Version history
1.5.1latest on PyPI · released Jul 13, 2026
Audit
Dependencies
requestsrequiredCore HTTP client functionality.
kiota-abstractionsrequiredAbstractions used across Kiota-generated SDKs, foundational for request/response models.
kiota-httprequiredHTTP client abstractions used by the core adapter.
python-dateutilrequiredUtility for parsing date/time strings.
azure-identityoptionalProvides various credential types for Azure AD authentication, commonly used with AzureIdentityAuthenticationProvider.
Agent activity
22 hits · last 30 days
node
16
Amazon
1
OpenAI (training)
1
Resources
msgraph-core — pip install msgraph-core · libregistry