Skip to content

Generate a Python SDK from a Swagger file

Laurent Mazuel edited this page Apr 13, 2017 · 35 revisions

The document provides instructions and guidelines on how to generate a Python SDK from a Swagger file.

Step 1: You're testing Python only

If you discovering Python, we have great intros using Notebooks on Azure.

  • You need to install Autorest: aka.ms/autorest/install

  • To call Autorest, you need the following options:

    • Required parameter: -ft 2

    • About the generator:

      • If your endpoint is ARM, add -g Azure.Python
      • If not, add -g Python. If your client might ask authentication, add -AddCredentials true
    • About the modeler, if your file is Composite file, add -Modeler CompositeSwagger

Example: autorest --version=latest -i myswagger.json -g Azure.Python -ft 2

And that's it, you have Python code ready to test. Note that this generation is for testing only and should not be sent to a customer or published to PyPI.

Step 2: You want a real package to release

First, your Swagger needs to ab at least a PR in the official Microsoft Swagger RestAPI repo. This allows to determine the name of your future package.

  • If your root folder is prefixed by arm-:
    • Your package name will be prefixed by azure-mgmt-
    • Your namespace will azure.mgmt
  • If not:
    • Your package name will be prefixed by azure-
    • Your namespace will azure

Example, the arm-compute folder will create the package azure-mgmt-compute and will contain the namespace azure.mgmt.compute.

Let's assume from now that your Swagger is in arm-compute

To call Autorest, you need the following options:

  • Required parameters:

    -ft 2 -Header MICROSOFT_MIT_NO_VERSION -Namespace azure.mgmt.compute -PackageName azure-mgmt-compute -PackageVersion 0.1.0

  • About the generator:

    • If your endpoint is ARM, add -g Azure.Python
    • If not, add -g Python. If your client might ask authentication, add -AddCredentials true
  • About the modeler, if your file is Composite file, add -Modeler CompositeSwagger

Example: autorest --version=latest -i arm-compute/compositeComputeClient.json -g Azure.Python -ft 2 -Header MICROSOFT_MIT_NO_VERSION -Namespace azure.mgmt.compute -PackageName azure-mgmt-compute -PackageVersion 0.1.0