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; }}
azure-keyvault-certificates/βββ azure/β βββ keyvault/β βββ certificates/β βββ __init__.pyβ βββ _models.pyβ βββ _client.pyβ βββ ...βββ setup.pyβββ ...
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:
- Keep generated code isolated in a dedicated subdirectory
- Maintain backward compatibility with existing SDK structures
- 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"
namespace Azure.KeyVault.Certificates;
@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; }}
azure-keyvault-certificates/βββ azure/β βββ keyvault/β βββ certificates/β βββ __init__.pyβ βββ _generated/β βββ __init__.pyβ βββ _models.pyβ βββ _client.pyβ βββ ...βββ setup.pyβββ ...