Skip to content

How to generate client libraries

This page outlines the steps to build a client library based on your TypeSpec specification. It provides a guide for the whole process from initial API design to the release of SDKs. please visit https://aka.ms/azsdk/dpcodegen.

The best documentation on how to generate can be found using those links:

At a glance, add your emitter name to your package.json, along with the right options in the tspconfig.yaml.

NOTE: Generating all languages from the same folder may be complicated due to the preview status of the emitters and TypeSpec libraries, such as typespec-azure-core and typespec-azure-resource-manager. It is recommended to have a unique language emitter in each package.json to avoid conflicts until all emitters and the TypeSpec libraries reach their first stable release.

Modify your package.json to include the necessary dependencies for the language emitter(s). Remember to run npm install after making changes to the file:

{
"name": "clients",
"dependencies": {
"@typespec/compiler": "latest",
"@typespec/rest": "latest",
"@typespec/http": "latest",
"@azure-tools/typespec-azure-core": "latest",
"@azure-tools/typespec-python": "latest"
},
"private": true
}

Always update your tspconfig.yaml file rather than passing options through the command line.

emit:
# Emitter for Swagger files with Autorest Extensions
- "@azure-tools/typespec-autorest"
# add "@azure-tools/typespec-python" to your package.json to generate Python code
- "@azure-tools/typespec-python"
# add "@azure-tools/typespec-java" to your package.json to generate Java code
- "@azure-tools/typespec-java"
# add "@azure-tools/typespec-csharp" to your package.json to generate C# code
- "@azure-tools/typespec-csharp"
# add "@azure-tools/typespec-ts" to your package.json to generate Typescript code
- "@azure-tools/typespec-ts"
options:
"@azure-tools/typespec-python":
package-name: azure-service-template

Several language repositories utilize the tsp-client tool to simplify generating client libraries. For more information on the tool, see Getting started with tsp-client.