{"id":16227,"date":"2023-11-08T10:41:07","date_gmt":"2023-11-08T18:41:07","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/?p=16227"},"modified":"2023-11-09T05:54:46","modified_gmt":"2023-11-09T13:54:46","slug":"generate-tailored-python-and-php-api-clients-for-any-api-with-kiota","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/generate-tailored-python-and-php-api-clients-for-any-api-with-kiota\/","title":{"rendered":"Generate tailored Python and PHP API clients for any API with Kiota"},"content":{"rendered":"<p><span style=\"font-size: 1rem; text-align: var(--bs-body-text-align);\">Working on data science, AI or back-end web applications usually requires managing different APIs with its HTTP clients, which can be inconvenient as different APIs build API clients differently. With <\/span><a href=\"https:\/\/aka.ms\/kiota\/docs\">Kiota<\/a> <span style=\"font-size: 1rem; text-align: var(--bs-body-text-align);\">you don\u2019t need to learn a new API client for every API, instead, you can now generate a consistent client experience across all the APIs you are using, regardless of their nature, all you need is an OpenAPI file.<\/span><\/p>\n<p>To learn more about OpenAPI, see <a href=\"https:\/\/www.openapis.org\/\">Home &#8211; OpenAPI Initiative (openapis.org)<\/a><\/p>\n<p>The experience is available as a command line tool and as a Visual Studio Code extension. Kiota eliminates the need to take a dependency on a different API client for every API that you need to call, as well as limiting the size of the client to the exact API surface area you\u2019re interested in, improving the efficiency of the client.<\/p>\n<p>In a matter of seconds, Kiota can:<\/p>\n<ul>\n<li>Search for API descriptions<\/li>\n<li>Filter and select the API endpoints you need<\/li>\n<li>Generate models and a chained method API surface in the language of your choice: C#, Go, PHP, Python (and preview or experimental support for Java, CLI, TypeScript, Ruby and Swift).<\/li>\n<li>Call the API with the new client.<\/li>\n<\/ul>\n<h2>Generating Python API clients<\/h2>\n<p>If you are working on data science, AI or cybersecurity projects, you may need to integrate different APIs. You can generate a consistent API client experience for all those APIs using Kiota.<\/p>\n<p><strong>Step 1<\/strong>: Install Kiota<\/p>\n<p>First, <a href=\"https:\/\/learn.microsoft.com\/en-us\/openapi\/kiota\/install\">install Kiota<\/a> as a command-line tool in your machine.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/isvargasmsft\/238b00fb3695a6b732d37a756b1d171c.js\"><\/script><\/p>\n<p><strong>Step 2<\/strong>: Prerequisites<\/p>\n<p>To generate Python clients, install these required tools:<\/p>\n<ul>\n<li><a href=\"https:\/\/www.python.org\/\">Python 3.6+<\/a><\/li>\n<li><a href=\"https:\/\/pip.pypa.io\/en\/stable\/\">pip 20.0+<\/a><\/li>\n<li><a href=\"https:\/\/docs.python.org\/3\/library\/asyncio.html\">asyncio\/any other supported async environment e.g AnyIO, Trio.<\/a><\/li>\n<\/ul>\n<p><strong>Step 3<\/strong>: Install dependencies<\/p>\n<p>Run the following commands to get the required dependencies.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/isvargasmsft\/7d4b589be09e02ca6775c277e34edfb9.js\"><\/script><\/p>\n<p><strong>Step 4<\/strong>: Generate the API client<\/p>\n<p>Use the OpenAPI file to generate an API client with Kiota.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/isvargasmsft\/fde9716f8d6b4b8bb090c10825127926.js\"><\/script><\/p>\n<p><strong>Step 5<\/strong>: Call the API<\/p>\n<p>All Kiota generated API clients will share a consistent usability experience.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/isvargasmsft\/6fe2748a7287138e5031c9bfa30ef4d0.js\"><\/script><\/p>\n<p>See the complete tutorial here: <a href=\"https:\/\/learn.microsoft.com\/en-us\/openapi\/kiota\/quickstarts\/python\">Build API clients for Python | Microsoft Learn<\/a><\/p>\n<h2>Generating PHP API clients<\/h2>\n<p>If you are working with back-end web applications or integrating with a Learning Management System (LMS), you may need to integrate and manage different APIs in your project. With Kiota, you can generate a consistent API client experience across all APIs, simplifying the code in your app.<\/p>\n<p><strong>Step 1<\/strong>: Install Kiota<\/p>\n<p>First, <a href=\"https:\/\/learn.microsoft.com\/en-us\/openapi\/kiota\/install\">install Kiota<\/a> as a command-line tool in your machine.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/isvargasmsft\/238b00fb3695a6b732d37a756b1d171c.js\"><\/script><\/p>\n<p><strong>Step 2<\/strong>: Prerequisites<\/p>\n<p>To generate PHP clients, install these required tools:<\/p>\n<ul>\n<li><a href=\"https:\/\/www.php.net\/downloads\">PHP ^7.4 or ^8.0<\/a><\/li>\n<li><a href=\"https:\/\/getcomposer.org\/\">Composer<\/a><\/li>\n<\/ul>\n<p><strong>Step 3<\/strong>: Install dependencies<\/p>\n<p>Run the following commands to get the required dependencies.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/isvargasmsft\/4c187f6bbc1665f3382f96fee66f04a2.js\"><\/script><\/p>\n<p><strong>Step 4<\/strong>: Generate the API client<\/p>\n<p>Use the OpenAPI file to generate an API client with Kiota.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/isvargasmsft\/c714b0f1164ad9982c6e6e3074889d7e.js\"><\/script><\/p>\n<p><strong>Step 5<\/strong>: Call the API<\/p>\n<p>All Kiota generated API clients will share a consistent usability experience.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/isvargasmsft\/f732a15462d615c56c9dad6a55119f53.js\"><\/script><\/p>\n<p>See the complete tutorial here: <a href=\"https:\/\/learn.microsoft.com\/en-us\/openapi\/kiota\/quickstarts\/php\">Build API clients for PHP | Microsoft Learn<\/a><\/p>\n<p>You can also run Kiota directly from Visual Studio Code, using the <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-graph.kiota\">VS Code extension<\/a>.<\/p>\n<h2>Also new in Kiota<\/h2>\n<p>We are also happy to announce new features of Kiota:<\/p>\n<ul>\n<li>Added support for API Manifests.<\/li>\n<li>Added support for raw URL in the fluent API surface.<\/li>\n<li>Added support for OpenTelemetry tracing.<\/li>\n<li>Added support for enum query parameter types.<\/li>\n<li>Added support for multiple content type request bodies.<\/li>\n<li>Added support for multiple content type responses.<\/li>\n<li>Added a json output for the Kiota info command.<\/li>\n<\/ul>\n<p>For details, read the release notes: <a href=\"https:\/\/github.com\/microsoft\/kiota\/releases\/tag\/v1.8.0\">Release v1.8.0 \u00b7 microsoft\/kiota (github.com)<\/a>, <a href=\"https:\/\/github.com\/microsoft\/kiota\/releases\/tag\/v1.7.0\">Release v1.7.0 \u00b7 microsoft\/kiota (github.com)<\/a>, <a href=\"https:\/\/github.com\/microsoft\/kiota\/releases\/tag\/v1.6.0\">Release v1.6.0 \u00b7 microsoft\/kiota (github.com)<\/a><\/p>\n<p>Resources<\/p>\n<ul>\n<li>To learn more about Kiota, see <a href=\"https:\/\/learn.microsoft.com\/en-us\/openapi\/kiota\/\">Kiota documentation | Microsoft Learn<\/a><\/li>\n<li>Follow us on\u00a0<a href=\"https:\/\/twitter.com\/Microsoft365Dev\">@Microsoft365Dev) \/ X (Twitter)<\/a>\u00a0to stay up to date on news and announcements.<\/li>\n<li>To learn more about OpenAPI, see <a href=\"https:\/\/www.openapis.org\/\">Home &#8211; OpenAPI Initiative (openapis.org)<\/a><\/li>\n<\/ul>\n<p>Happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how Kiota eliminates the need to take a dependency on a different SDK for every API that you need to call.<\/p>\n","protected":false},"author":95132,"featured_media":16236,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[3],"tags":[174,180,220],"class_list":["post-16227","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-microsoft-graph","tag-kiota","tag-microsoft-graph-php-sdk","tag-python-sdk"],"acf":[],"blog_post_summary":"<p>Learn how Kiota eliminates the need to take a dependency on a different SDK for every API that you need to call.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/16227","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=16227"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/16227\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/media\/16236"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/media?parent=16227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/categories?post=16227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/tags?post=16227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}