Skip to content

Package Structure

Namespaces

By default, the Python HTTP client emitter generates code into a package structure that follows Python’s naming conventions. We follow the structure of the other http client emitters that we publish: by default a namespace in TypeSpec corresponds to a namespace in our generated Python SDK. See here for more examples.

Default Behavior

The Python HTTP client emitter creates a package structure based on the namespace specified in your TypeSpec file:

@service({
title: "Azure Key Vault Certificate Client",
})
namespace Azure.KeyVault.Certificates {
model Certificate {
id: string;
name: string;
properties: CertificateProperties;
}
model CertificateProperties {
created: utcDateTime;
updated: utcDateTime;
enabled: boolean;
}
@route("/certificates")
interface CertificateOperations {
@get list(): Certificate[];
@get get(@path id: string): Certificate;
}
}

Controlling the Generation Directory

When migrating existing SDKs or working with brownfield services, you might need to place generated code in a specific subdirectory, like _generated. For these scenarios, you can use the namespace configuration option in your tspconfig.yaml file.

If you want the published SDK to follow closely with the package structure and namespaces in your TypeSpec file, you should also pass in the package-name flag with the desired value.

Using the namespace Flag

The namespace option allows you to specify where the generated code should be placed within your package structure. This is particularly useful for cases where you want to:

  1. Keep generated code isolated in a dedicated subdirectory
  2. Maintain backward compatibility with existing SDK structures
  3. Separate generated code from hand-written code

Example Configuration

In this example, we will take you through emitting generated code into a specific subdirectory (like _generated), with the idea that you will be fully-wrapping the generated code. Add the following to your tspconfig.yaml:

emitters:
"@typespec/http-client-python":
namespace: "azure.keyvault.certificates._generated"
package-name: "azure-keyvault-certificates"