-
Notifications
You must be signed in to change notification settings - Fork 3k
Generate a Python SDK from a Swagger file
The document provides instructions and guidelines on how to generate a Python SDK from a Swagger file.
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
- If your endpoint is ARM, add
-
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.
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
- Your package name will be prefixed by
- If not:
- Your package name will be prefixed by
azure-
- Your namespace will
azure
- Your package name will be prefixed by
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
- If your endpoint is ARM, add
-
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