{"id":1563,"library":"msgraph-core","title":"Microsoft Graph Core Library","description":"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.","status":"active","version":"1.3.8","language":"en","source_language":"en","source_url":"https://github.com/microsoftgraph/msgraph-sdk-python-core","tags":["microsoft-graph","sdk","api-client","http-client","authentication","odata"],"install":[{"cmd":"pip install msgraph-core","lang":"bash","label":"Install core library"},{"cmd":"pip install azure-identity","lang":"bash","label":"Install Azure Identity for authentication (recommended)"}],"dependencies":[{"reason":"Core HTTP client functionality.","package":"requests","optional":false},{"reason":"Abstractions used across Kiota-generated SDKs, foundational for request/response models.","package":"kiota-abstractions","optional":false},{"reason":"HTTP client abstractions used by the core adapter.","package":"kiota-http","optional":false},{"reason":"Utility for parsing date/time strings.","package":"python-dateutil","optional":false},{"reason":"Provides various credential types for Azure AD authentication, commonly used with AzureIdentityAuthenticationProvider.","package":"azure-identity","optional":true}],"imports":[{"symbol":"GraphClientFactory","correct":"from msgraph_core import GraphClientFactory"},{"note":"The authentication provider for Azure Identity is in a specific sub-module.","wrong":"from msgraph_core.authentication import AzureIdentityAuthenticationProvider","symbol":"AzureIdentityAuthenticationProvider","correct":"from msgraph_core.authentication.azure_identity import AzureIdentityAuthenticationProvider"},{"note":"Common error model for Graph API responses.","symbol":"ODataError","correct":"from msgraph_core.models import ODataError"}],"quickstart":{"code":"import os\nfrom msgraph_core import GraphClientFactory\nfrom msgraph_core.authentication.azure_identity import AzureIdentityAuthenticationProvider\nfrom azure.identity import ClientSecretCredential # Or any other credential\n\n# 1. Get credentials (replace with your actual client_id, tenant_id, client_secret)\n# For local testing, ensure these are set as environment variables or replace directly\ntenant_id = os.environ.get(\"AZURE_TENANT_ID\", \"YOUR_TENANT_ID\")\nclient_id = os.environ.get(\"AZURE_CLIENT_ID\", \"YOUR_CLIENT_ID\")\nclient_secret = os.environ.get(\"AZURE_CLIENT_SECRET\", \"YOUR_CLIENT_SECRET\")\n\n# Scopes required for Microsoft Graph\nscopes = ['https://graph.microsoft.com/.default']\n\n# Basic check for credentials for a runnable example\nif not all([tenant_id, client_id, client_secret]):\n    print(\"WARNING: Azure credentials not found in environment variables. Using placeholder values.\")\n    print(\"Please set AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET for a real test.\")\n    # Using placeholders for quickstart to be technically 'runnable' without env vars,\n    # but it will fail the auth handshake.\n    tenant_id = \"_DUMMY_TENANT_ID_\"\n    client_id = \"_DUMMY_CLIENT_ID_\"\n    client_secret = \"_DUMMY_CLIENT_SECRET_\"\n\ntry:\n    # 2. Create an authentication provider\n    credential = ClientSecretCredential(\n        tenant_id=tenant_id,\n        client_id=client_id,\n        client_secret=client_secret\n    )\n    auth_provider = AzureIdentityAuthenticationProvider(credential=credential, scopes=scopes)\n\n    # 3. Create a GraphClient instance using the factory\n    # The factory returns an instance of GraphClient which uses GraphRequestAdapter internally\n    # with default middleware, configured for Graph API requests.\n    graph_client = GraphClientFactory.create_with_default_middleware(auth_provider)\n\n    # 4. Make a request using the low-level client (part of msgraph-core)\n    print(\"Making a request to /me to demonstrate msgraph-core functionality...\")\n    # Note: For real-world use with the full Graph API schema, consider msgraph-sdk.\n    response = graph_client.get('/me')\n    response.raise_for_status() # Raise an exception for HTTP errors (4xx or 5xx)\n\n    user_data = response.json()\n    print(f\"Successfully fetched user data for: {user_data.get('displayName', 'Unknown User')}\")\n    print(f\"User ID: {user_data.get('id', 'N/A')}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    if \"AADSTS\" in str(e):\n        print(\"Hint: This often indicates an issue with your Azure AD credentials or permissions.\")\n        print(\"Check client ID, tenant ID, client secret, and API permissions (e.g., User.Read.All or User.Read).\")\n\n","lang":"python","description":"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."},"warnings":[{"fix":"Refer to official Microsoft Graph Python SDK v2 migration guides for detailed steps. Re-architecture authentication, request building, and response handling.","message":"The `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.","severity":"breaking","affected_versions":"All `msgraph-core` versions (v1.x.x are v2 SDK based)."},{"fix":"Ensure `azure-identity` is installed via `pip install azure-identity` and correctly configure your chosen credential type from that library.","message":"While `msgraph-core` provides `AzureIdentityAuthenticationProvider`, it does not bundle the `azure-identity` library. You must explicitly `pip install azure-identity` to use the convenient credential classes (e.g., `ClientSecretCredential`, `DefaultAzureCredential`).","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}