Microsoft Graph Python SDK is now available for public preview

Isaac Vargas Chacon

We’re excited to introduce the Microsoft Graph Python SDK, now available for public preview. This comes as a result of the growth and adoption in our Python core library.

You can now access the beta and v1 endpoints of Microsoft Graph, with a fluent experience, designed to facilitate discoverability and enhance with best features of the Python language. Contrary to other fluent experiences in Python, we don’t map every endpoint and method to a unique function. Instead, we present a framework to construct any request using method chaining, providing a clean flow that works seamlessly with Python. The fluent pattern contributes to reducing errors by displaying only the methods corresponding to operations on that resource, aided by the IDE’s autocomplete, allowing the developer to confidently type code that runs. The SDK also makes use of type annotations to provide clarity and control during the development process.

The Python SDK improves the best of the Python core library, supplying an authentication provider that automatically refreshes access tokens, along with a built-in retry handler that understands response status codes and automatically waits the recommended time. The SDK also provides async experience, allowing the application to work on multiple requests at the same time and perform other operations while it waits for the response, improving the speed and efficiency of the application. It is also equipped with HTTP2 support and model classes corresponding to Microsoft Graph resources, allowing the developer to work with Python objects, automatically serializing and deserializing JSON format in requests and responses.

Continuing our efforts to standardize our tools, this SDK is also generated with Kiota, an open-source project for generating an API client to call any OpenAPI described API, assuring quality and consistency across our tools.

Authentication provider

The authentication provider handles the fetching, caching, and refreshing of tokens automatically, ensuring your requests are always authenticated. The auth provider verifies the token is always valid by tracking the expiration and automatically refreshing it in the background before it expires.

Fluent request builder pattern for Python

The fluent pattern makes the request building experience more intuitive. Instead of passing raw URLs, this new version provides a fluent experience that enhances discoverability and efficiency, also reducing the time spent in reference docs.

This request builder pattern was carefully designed with Python developers in mind, providing enhanced discoverability without mutating the objects.

Built-in retry handler

A configurable built-in retry handler understands 429, 503 and 504 response status codes, reading the information in the `Retry-After` header and making decisions accordingly. For throttling status codes, the handler reads the recommendation in the `Retry-After` header and retries after the recommended time.

Get started with Microsoft Graph Python SDK

  • Start with the Microsoft Graph SDKs documentation page.
  • The README and code examples will teach you how to use the Python SDK. And the Upgrade guide contains instructions to upgrade from the Python Core library. You can also find the SDK to access the beta endpoint here.
  • Open an issue for errors you encounter that we didn’t include in our guide or simply to share feedback with us.
  • Sign up for the Microsoft 365 Developer Program to get a free Microsoft 365 developer subscription and start building with Microsoft Graph.

Happy coding!


Discussion is closed.

Feedback usabilla icon