{"id":8335,"library":"msgraph-beta-sdk","title":"Microsoft Graph Beta Python SDK","description":"The `msgraph-beta-sdk` is the official Python SDK for interacting with the Microsoft Graph API's beta endpoint. It enables developers to build applications using the latest, often experimental, features of Microsoft Graph. As of its current version (1.57.0), it offers an asynchronous API by default and integrates with `azure.identity` for authentication. It's important to note that this SDK is intended for development and testing new features, not for production environments, due to potential breaking changes and the evolving nature of beta APIs.","status":"active","version":"1.57.0","language":"en","source_language":"en","source_url":"https://github.com/microsoftgraph/msgraph-beta-sdk-python","tags":["microsoft graph","sdk","beta","async","azure","identity","cloud"],"install":[{"cmd":"pip install msgraph-beta-sdk","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for authentication with Microsoft Graph. Provides various credential types (e.g., EnvironmentCredential, DeviceCodeCredential).","package":"azure-identity","optional":false}],"imports":[{"symbol":"GraphServiceClient","correct":"from msgraph_beta import GraphServiceClient"},{"note":"Used for asynchronous authentication from environment variables; other credential types exist in `azure.identity`.","symbol":"EnvironmentCredential","correct":"from azure.identity.aio import EnvironmentCredential"}],"quickstart":{"code":"import asyncio\nimport os\nfrom azure.identity.aio import EnvironmentCredential\nfrom msgraph_beta import GraphServiceClient\n\nasync def main():\n    # It's recommended to set 'AZURE_TENANT_ID', 'AZURE_CLIENT_ID', and 'AZURE_CLIENT_SECRET'\n    # environment variables for EnvironmentCredential.\n    # Replace with your actual scopes based on the permissions required by your application.\n    scopes = ['User.Read', 'Mail.Read'] \n\n    try:\n        credential = EnvironmentCredential()\n        client = GraphServiceClient(credential, scopes=scopes)\n\n        # Example: Get the currently signed-in user's profile\n        user = await client.me.get()\n        print(f\"Hello, {user.display_name}!\")\n        print(f\"Your email: {user.mail}\")\n\n    except Exception as e:\n        print(f\"An error occurred: {e}\")\n\nif __name__ == '__main__':\n    asyncio.run(main())\n","lang":"python","description":"This quickstart demonstrates how to initialize the `GraphServiceClient` using `EnvironmentCredential` from `azure.identity.aio` for asynchronous operations and fetch the current user's profile. Ensure your application is registered with Azure AD and the necessary environment variables (`AZURE_TENANT_ID`, `AZURE_CLIENT_ID`, `AZURE_CLIENT_SECRET`) are set, along with appropriate API permissions (scopes)."},"warnings":[{"fix":"Do not use `msgraph-beta-sdk` for production applications. Develop with the understanding that code may break with new releases. For stable production applications, use the `msgraph-sdk` (v1.0 endpoint).","message":"The `msgraph-beta-sdk` operates against the Microsoft Graph beta endpoint. APIs in the beta endpoint are subject to change without notice and may introduce breaking changes at any time. Features available in beta are not guaranteed to be promoted to the v1.0 endpoint.","severity":"breaking","affected_versions":"All versions of `msgraph-beta-sdk`"},{"fix":"Ensure your code runs within an `asyncio` event loop. Prefix API calls with `await`. For example, `await client.me.get()` instead of `client.me.get()`.","message":"The SDK is asynchronous by default. Operations return awaitable objects, requiring the use of `async`/`await` and an asyncio event loop.","severity":"gotcha","affected_versions":"All versions >= 1.0.0"},{"fix":"Be patient during installation. On Windows, enable long paths in your environment. Refer to Microsoft documentation on 'Enable Long Paths in Windows 10, Version 1607, and Later' if you encounter `OSError`.","message":"Installation of the `msgraph-beta-sdk` can be lengthy due to its size. On Windows, an `OSError` related to long paths may occur.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always use credential classes from the `azure.identity` library (e.g., `EnvironmentCredential`, `DeviceCodeCredential`, `ClientSecretCredential`) to instantiate `GraphServiceClient`.","message":"Older authentication providers (e.g., from `Microsoft.Graph.Auth` in .NET, though relevant concept for Python too) are being deprecated in favor of `azure.identity` for `TokenCredential` based authentication.","severity":"deprecated","affected_versions":"Early versions (exact Python version unconfirmed, but `azure.identity` is the current recommended approach)"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Prepend asynchronous SDK calls with `await` (e.g., `await client.me.get()`). Ensure the function containing the `await` call is an `async` function and is executed within an `asyncio` event loop (e.g., `asyncio.run(main())`).","cause":"Attempting to call an asynchronous SDK method without `await` in an `async` function, or calling it outside an `asyncio` event loop.","error":"TypeError: 'coroutine' object is not awaitable"},{"fix":"Enable long paths in your Windows operating system. This is typically done through Group Policy Editor or by modifying the registry.","cause":"This error can occur on Windows systems during installation of the SDK due to the large number of files and long path names generated by the package.","error":"OSError: [WinError 206] The filename or extension is too long:"},{"fix":"Set the required environment variables in your operating system or development environment. Alternatively, use a different `azure.identity` credential type that suits your authentication flow (e.g., `DeviceCodeCredential` for interactive login).","cause":"The `EnvironmentCredential` relies on specific environment variables (`AZURE_TENANT_ID`, `AZURE_CLIENT_ID`, `AZURE_CLIENT_SECRET`) not being set or being incorrectly configured.","error":"azure.identity.CredentialUnavailableError: EnvironmentCredential authentication failed. No tenant ID, client ID, or client secret found."},{"fix":"Review the Microsoft Graph API documentation for the correct endpoint paths. For example, to get information about the current user, use `client.me.get()`. To get a list of users, use `client.users.get()`.","cause":"Attempting to access an endpoint (e.g., `client.me.users`) that is not valid or incorrectly chained. The `client.me` property already refers to the current user.","error":"The type of the current segment is not expected, and it must be of type 'users'."}]}