{"id":15817,"date":"2023-11-01T11:30:05","date_gmt":"2023-11-01T18:30:05","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/?p=15817"},"modified":"2023-11-06T05:01:53","modified_gmt":"2023-11-06T13:01:53","slug":"introducing-the-microsoft-graph-python-sdk","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/introducing-the-microsoft-graph-python-sdk\/","title":{"rendered":"Introducing the Microsoft Graph Python SDK"},"content":{"rendered":"<p>We are happy to announce Microsoft Graph Python SDK in GA. Previously, this SDK was <a href=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/introducing-the-microsoft-graph-python-sdk-now-available-for-public-preview\/\">released in public preview<\/a> in November 2022.<\/p>\n<p>You can now access the beta and v1 endpoints of <a href=\"https:\/\/learn.microsoft.com\/en-us\/graph\/overview\">Microsoft Graph<\/a>, with a fluent experience, designed to facilitate discoverability with the best features of the Python language.<\/p>\n<p>In this blog, we will cover the key features of the Microsoft Graph Python SDK.<\/p>\n<h2>Simplified initialization and authentication<\/h2>\n<p>With simplified authentication, you can start making requests to Microsoft Graph in just 5 lines of code. Just add your credentials to the library of your choice, initialize the client and your app will be ready to make requests.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/isvargasmsft\/785e58a5ee92511e051fa48cfe99cfeb.js\"><\/script><\/p>\n<p>The authentication provider handles the fetching, caching, and refreshing of tokens automatically, ensuring your requests are always authenticated. The auth provider verifies that the token is always valid by tracking the expiration and automatically refreshing the token in the background before it expires.<\/p>\n<h2>Fluent experience to build requests<\/h2>\n<p>Contrary to other fluent experiences in Python, we don\u2019t 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 in Python.<\/p>\n<p><img decoding=\"async\" width=\"1463\" height=\"307\" class=\"wp-image-15818 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/10\/a-screenshot-of-a-computer-description-automatica-9.png\" alt=\"A screenshot of a computer Description automatically generated\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/10\/a-screenshot-of-a-computer-description-automatica-9.png 1463w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/10\/a-screenshot-of-a-computer-description-automatica-9-300x63.png 300w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/10\/a-screenshot-of-a-computer-description-automatica-9-1024x215.png 1024w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2023\/10\/a-screenshot-of-a-computer-description-automatica-9-768x161.png 768w\" sizes=\"(max-width: 1463px) 100vw, 1463px\" \/><\/p>\n<p>The fluent pattern contributes to reducing errors, by displaying only the methods corresponding to operations on the specified resource. Aided by the IDE&#8217;s autocomplete, the SDK allows the developer to confidently type code that runs.<\/p>\n<h2>Built-in retry-handler<\/h2>\n<p>The SDK offers a configurable built-in Retry-Handler that understands 429 (Too Many Requests), 503 (Service Unavailable) and 504 (Gateway Timeout) response status codes, that usually require the application to retry the request after some time. The handler reads the recommendation in the `Retry-After` header and retries after the recommended time automatically. You can also customize the handler and specify a\u00a0custom value for the\u00a0`RetriesTimeLimit`\u00a0greater than 0, to introduce time-based evaluated request retries with the default count-based request retry.<\/p>\n<h2>More features<\/h2>\n<ul>\n<li>HTTP2 support: The Python SDK support HTTP2 out of the box by default.<\/li>\n<li>Type annotations: The SDK allows you to specify a variable\u2019s type to provide clarity and control during the development process.<\/li>\n<li>Model classes: The SDK uses 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.<\/li>\n<\/ul>\n<h2>Kiota generated<\/h2>\n<p>You can also generate a Python SDK for any API you are using in your project and create a consistent SDK experience across APIs. All you need is an OpenAPI description. To learn more, visit the <a href=\"https:\/\/learn.microsoft.com\/en-us\/openapi\/kiota\/quickstarts\/python\">Kiota documentation<\/a>.<\/p>\n<h2>Get started with the Microsoft Graph Python SDK<\/h2>\n<ul>\n<li>To get familiar with the Microsoft Graph SDKs, start with the <a href=\"https:\/\/docs.microsoft.com\/en-us\/graph\/sdks\/sdks-overview\">documentation page<\/a>.<\/li>\n<li>The <a id=\"post-15817-_Int_IQGKIvVO\"><\/a><a href=\"https:\/\/github.com\/microsoftgraph\/msgraph-sdk-python\/blob\/main\/README.md\">README<\/a> and code examples will teach you how to use the Python SDK. You can also find the SDK to access the beta endpoint <a href=\"https:\/\/github.com\/microsoftgraph\/msgraph-beta-sdk-python\">here<\/a>.<\/li>\n<li>Please don\u2019t hesitate to <a href=\"https:\/\/github.com\/microsoftgraph\/msgraph-sdk-python\/issues\/new\">open an issue<\/a> for errors you encounter that we didn\u2019t include in our guide or simply to share feedback with us.<\/li>\n<li>Sign up for\u00a0the\u00a0<a href=\"https:\/\/developer.microsoft.com\/en-us\/microsoft-365\/dev-program\">Microsoft 365 Developer Program<\/a>\u00a0to get a free Microsoft 365 developer subscription\u00a0and\u00a0start\u00a0building with Microsoft Graph.<\/li>\n<\/ul>\n<p>Happy coding!<\/p>\n<p>Follow us on <a href=\"http:\/\/www.twitter.com\/microsoft365dev\">X \/ @Microsoft365Dev<\/a> for the latest updates.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Access the beta and v1 endpoints of Microsoft Graph, with a fluent experience, designed to facilitate discoverability with the best features of the Python language.<\/p>\n","protected":false},"author":95132,"featured_media":15824,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[3],"tags":[220],"class_list":["post-15817","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-microsoft-graph","tag-python-sdk"],"acf":[],"blog_post_summary":"<p>Access the beta and v1 endpoints of Microsoft Graph, with a fluent experience, designed to facilitate discoverability with the best features of the Python language.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/15817","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/users\/95132"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/comments?post=15817"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/15817\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/media\/15824"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/media?parent=15817"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/categories?post=15817"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/tags?post=15817"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}