Generate tailored Python and PHP API clients for any API with Kiota

Isaac Vargas Chacon

Jessica Wu

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 Kiota you don’t 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.

To learn more about OpenAPI, see Home – OpenAPI Initiative (openapis.org)

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’re interested in, improving the efficiency of the client.

In a matter of seconds, Kiota can:

  • Search for API descriptions
  • Filter and select the API endpoints you need
  • 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).
  • Call the API with the new client.

Generating Python API clients

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.

Step 1: Install Kiota

First, install Kiota as a command-line tool in your machine.

Step 2: Prerequisites

To generate Python clients, install these required tools:

Step 3: Install dependencies

Run the following commands to get the required dependencies.

Step 4: Generate the API client

Use the OpenAPI file to generate an API client with Kiota.

Step 5: Call the API

All Kiota generated API clients will share a consistent usability experience.

See the complete tutorial here: Build API clients for Python | Microsoft Learn

Generating PHP API clients

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.

Step 1: Install Kiota

First, install Kiota as a command-line tool in your machine.

Step 2: Prerequisites

To generate PHP clients, install these required tools:

Step 3: Install dependencies

Run the following commands to get the required dependencies.

Step 4: Generate the API client

Use the OpenAPI file to generate an API client with Kiota.

Step 5: Call the API

All Kiota generated API clients will share a consistent usability experience.

See the complete tutorial here: Build API clients for PHP | Microsoft Learn

You can also run Kiota directly from Visual Studio Code, using the VS Code extension.

Also new in Kiota

We are also happy to announce new features of Kiota:

  • Added support for API Manifests.
  • Added support for raw URL in the fluent API surface.
  • Added support for OpenTelemetry tracing.
  • Added support for enum query parameter types.
  • Added support for multiple content type request bodies.
  • Added support for multiple content type responses.
  • Added a json output for the Kiota info command.

For details, read the release notes: Release v1.8.0 · microsoft/kiota (github.com), Release v1.7.0 · microsoft/kiota (github.com), Release v1.6.0 · microsoft/kiota (github.com)

Resources

Happy coding!

0 comments

Discussion is closed.

Feedback usabilla icon