SDKs overview
Microsoft Graph provides a unified API endpoint for accessing data and intelligence across Microsoft 365, Windows 365, and Azure Active Directory. To facilitate developer interaction with this extensive API, Microsoft offers official Software Development Kits (SDKs) across various programming languages. These SDKs streamline the process of building applications that integrate with Microsoft Graph by providing language-idiomatic interfaces, handling HTTP requests, managing authentication tokens, and simplifying data serialization and deserialization.
The SDKs are designed to reduce boilerplate code and abstract away the complexities of direct HTTP calls to the RESTful API. They typically include client classes for different service areas (e.g., users, mail, calendar), model classes representing the various entities (e.g., User, Message, Event), and utility functions for common tasks like pagination and batching. Developers can choose an SDK based on their preferred programming language to accelerate development and maintain consistency with their existing tech stacks.
Beyond the official offerings, a vibrant community contributes additional libraries and tools. These community-driven projects can offer specialized functionalities, alternative client implementations, or support for languages not officially covered by Microsoft. Both official and community resources aim to enhance the developer experience when building solutions that leverage the Microsoft Graph platform.
Official SDKs by language
Microsoft maintains official SDKs for several popular programming languages, ensuring direct support and compatibility with the latest API versions and features of Microsoft Graph. These SDKs are regularly updated and documented on the Microsoft Graph SDK documentation.
| Language | Package/Module | Install Command | Maturity |
|---|---|---|---|
| .NET | Microsoft.Graph |
dotnet add package Microsoft.Graph |
Generally Available |
| Go | github.com/microsoftgraph/msgraph-sdk-go |
go get github.com/microsoftgraph/msgraph-sdk-go |
Generally Available |
| Java | com.microsoft.graph:microsoft-graph |
Maven: Add dependency in pom.xml. Gradle: Add dependency in build.gradle. |
Generally Available |
| JavaScript | @microsoft/microsoft-graph-client |
npm install @microsoft/microsoft-graph-client or yarn add @microsoft/microsoft-graph-client |
Generally Available |
| PHP | microsoft/microsoft-graph |
composer require microsoft/microsoft-graph |
Generally Available |
| PowerShell | Microsoft.Graph |
Install-Module Microsoft.Graph |
Generally Available |
| Python | msgraph-sdk-python |
pip install msgraph-sdk-python |
Generally Available |
| Ruby | microsoft_graph |
gem install microsoft_graph |
Generally Available |
Installation
Installation methods vary by language and package manager. The following provides general guidance for each official SDK. For detailed, up-to-date instructions, refer to the specific Microsoft Graph SDK documentation for your chosen language.
.NET
For .NET applications, the Microsoft Graph SDK is distributed as a NuGet package. You can install it using the .NET CLI or the NuGet Package Manager in Visual Studio:
dotnet add package Microsoft.Graph
Or via the NuGet Package Manager Console:
Install-Package Microsoft.Graph
Go
The Go SDK is available via go get:
go get github.com/microsoftgraph/msgraph-sdk-go
Ensure your Go environment is properly configured, and then import the necessary packages in your Go source files.
Java
For Java projects, the Microsoft Graph SDK is typically included as a dependency in your pom.xml (Maven) or build.gradle (Gradle) file. Example for Maven:
<dependency>
<groupId>com.microsoft.graph</groupId>
<artifactId>microsoft-graph</artifactId>
<version>6.0.0</version> <!-- Check for the latest version -->
</dependency>
Refer to the Microsoft Graph Java SDK setup guide for the latest version and detailed instructions.
JavaScript
The JavaScript SDK can be installed using npm or yarn:
npm install @microsoft/microsoft-graph-client
# or
yarn add @microsoft/microsoft-graph-client
This package is suitable for both Node.js and browser-based applications, often requiring a bundler like Webpack or Rollup for browser use.
PHP
The PHP SDK is installed via Composer:
composer require microsoft/microsoft-graph
After installation, include Composer's autoloader in your PHP script: require 'vendor/autoload.php';
PowerShell
The Microsoft Graph PowerShell SDK is available from the PowerShell Gallery:
Install-Module Microsoft.Graph
You may need to run PowerShell as an administrator to install modules. For specific scopes or modules, refer to the PowerShell SDK installation documentation.
Python
The Python SDK is installed using pip:
pip install msgraph-sdk-python
This installs the core SDK. Additional sub-packages for specific API versions or preview features might be available.
Ruby
The Ruby SDK is available as a gem:
gem install microsoft_graph
After installation, you can require the gem in your Ruby scripts: require 'microsoft_graph'
Quickstart example
This example demonstrates how to use the JavaScript SDK to authenticate and retrieve the currently logged-in user's profile information. This assumes you have already set up an Azure AD application registration and have the necessary client ID and redirect URI configured for OAuth 2.0 authentication.
First, ensure you have installed the SDK:
npm install @microsoft/microsoft-graph-client @azure/msal-browser
Then, use the following JavaScript code:
import * as Msal from "@azure/msal-browser";
import { Client } from "@microsoft/microsoft-graph-client";
import { AuthCodeMSALBrowserAuthenticationProvider } from "@microsoft/microsoft-graph-client/authProviders/authCodeMsalBrowser";
// 1. Configure MSAL for authentication
const msalConfig = {
auth: {
clientId: "YOUR_CLIENT_ID", // Replace with your Azure AD app client ID
authority: "https://login.microsoftonline.com/common",
redirectUri: "http://localhost:3000", // Your redirect URI
},
cache: {
cacheLocation: "sessionStorage", // or "localStorage"
storeAuthStateInCookie: false,
},
};
const msalInstance = new Msal.PublicClientApplication(msalConfig);
const scopes = ["User.Read", "Mail.Read"]; // Define required permissions
const options = new AuthCodeMSALBrowserAuthenticationProvider(msalInstance, {
account: msalInstance.getActiveAccount(),
scopes: scopes,
interactionType: Msal.InteractionType.Popup,
loginHint: "",
});
const authProvider = new AuthCodeMSALBrowserAuthenticationProvider(msalInstance, options);
// 2. Initialize the Microsoft Graph client
const graphClient = Client.withAuthenticationProvider(authProvider);
async function getUserProfile() {
try {
// 3. Get the user's profile
const user = await graphClient.api("/me").get();
console.log("User Profile:", user);
return user;
} catch (error) {
console.error("Error fetching user profile:", error);
// Handle authentication or API errors
if (error instanceof Msal.InteractionRequiredAuthError) {
// This error indicates a need for user interaction (e.g., re-login, consent)
await msalInstance.loginPopup({ scopes: scopes });
// Retry after successful login
return getUserProfile();
}
throw error;
}
}
// Call the function to get the user profile
getUserProfile();
This example first configures the Microsoft Authentication Library (MSAL) for browser-based authentication, which is crucial for handling OAuth 2.0 flows with Azure Active Directory. It then initializes the Microsoft Graph client with an authentication provider that uses MSAL. Finally, it demonstrates how to make a simple API call to retrieve the current user's profile information (/me endpoint) and includes basic error handling for common authentication scenarios, such as requiring user interaction.
For server-side applications, the authentication flow would typically involve client credentials or on-behalf-of flows, often using libraries like @azure/msal-node or Microsoft.Identity.Web for .NET. The general pattern of initializing the Graph client with an authentication provider and then making API calls remains consistent across SDKs.
Community libraries
While Microsoft provides a strong set of official SDKs, the developer community often extends support or offers alternative implementations. These libraries can fill gaps, provide different architectural approaches, or offer specialized tooling. It's important to note that community libraries may not have the same level of official support, maintenance, or security guarantees as the official SDKs.
Examples of community contributions and related tools include:
- PowerShell Modules for specific scenarios: Beyond the official PowerShell SDK, developers may create specialized modules to automate specific Microsoft 365 tasks or integrate with other systems.
- Third-party wrappers or clients: For languages not officially supported, or if developers prefer a different API design, community members might create their own client libraries. These often leverage the underlying REST API directly.
- API testing and development tools: Tools that help in exploring the Microsoft Graph API, generating code snippets, or testing API calls. For instance, Postman collections or Insomnia workspaces are often shared by the community to simplify API interaction.
- Integration with low-code/no-code platforms: While not strictly libraries, community connectors and custom actions for platforms like Power Automate or Azure Logic Apps can be seen as extensions that simplify Microsoft Graph integration for non-developers.
When considering a community library, developers should evaluate its active maintenance, community support, documentation quality, and alignment with security best practices. Checking the project's GitHub repository for recent commits, open issues, and pull requests can provide insight into its current state. For example, a search on GitHub for Microsoft Graph Python libraries might reveal various community-driven projects alongside the official SDK.
For official guidance and the most reliable integration, Microsoft always recommends using the official Microsoft Graph SDKs when available for your language and platform.