Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: internal
packages:
- "@azure-tools/typespec-python"
---

update docs
26 changes: 18 additions & 8 deletions packages/typespec-python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ License information for the generated client code.

**Properties:**

| Name | Type | Default | Description |
| ------------- | -------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `name` | `string` | | License name. The config is required. Predefined licenses are: MIT License, Apache License 2.0, BSD 3-Clause License, MPL 2.0, GPL-3.0, LGPL-3.0. For other license, you need to configure all the other license config manually. |
| `company` | `string` | | License company name. It will be used in copyright sentences. |
| `link` | `string` | | License link. |
| `header` | `string` | | License header. It will be used in the header comment of generated client code. |
| `description` | `string` | | License description. The full license text. |
| Name | Type | Default | Description |
| ------------- | -------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `name` | `string` | | License name. The config is required. Predefined license are: MIT License, Apache License 2.0, BSD 3-Clause License, MPL 2.0, GPL-3.0, LGPL-3.0. For other license, you need to configure all the other license config manually. |
| `company` | `string` | | License company name. It will be used in copyright sentences. |
| `link` | `string` | | License link. |
| `header` | `string` | | License header. It will be used in the header comment of generated client code. |
| `description` | `string` | | License description. The full license text. |

### `package-version`

Expand Down Expand Up @@ -163,7 +163,17 @@ Whether to validate the versioning of the package. Defaults to `true`. If set to

**Type:** `string`

The subdirectory to generate the code in. If not specified, the code will be generated in the root folder. Note: if you're using this flag, you will need to add and maintain the versioning file yourself.
The subdirectory (relative to the package namespace folder) to generate the code in. Use this to keep emitter-generated code separate from hand-written/customized code, so regeneration only overwrites the subdirectory and leaves your customizations untouched. If not specified, the code is generated directly in the package namespace folder. Note: if you're using this flag, you will need to add and maintain the versioning file (`_version.py`) yourself.

Example: for `namespace: azure.storage.blob` with `generation-subdir: _generated`, generated code lands in `azure/storage/blob/_generated/` while your customized code lives in `azure/storage/blob/`. A typical `tspconfig.yaml` looks like:

```yaml
options:
"@azure-tools/typespec-python":
emitter-output-dir: "{output-dir}/{service-dir}/azure-storage-blob"
namespace: "azure.storage.blob"
generation-subdir: "_generated"
```

### `keep-setup-py`

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
---
title: "Emitter usage"
---

## Emitter usage

1. Via the command line

```bash
tsp compile . --emit=@azure-tools/typespec-python
```

2. Via the config

```yaml
emit:
- "@azure-tools/typespec-python"
```

The config can be extended with options as follows:

```yaml
emit:
- "@azure-tools/typespec-python"
options:
"@azure-tools/typespec-python":
option: value
```

## Emitter options

### `emitter-output-dir`

**Type:** `absolutePath`

Defines the emitter output directory. Defaults to `{output-dir}/@azure-tools/typespec-python`
See [Configuring output directory for more info](https://typespec.io/docs/handbook/configuration/configuration/#configuring-output-directory)

### `examples-dir`

**Type:** `string`

Specifies the directory where the emitter will look for example files. If the flag isn’t set, the emitter defaults to using an `examples` directory located at the project root.

### `namespace`

**Type:** `string`

Specifies the namespace you want to override for namespaces set in the spec. With this config, all namespace for the spec types will default to it.

### `flavor`

**Type:** `string`

The flavor of the SDK.

### `models-mode`

**Type:** `"dpg" | "none" | "typeddict"`

What kind of models to generate. If you pass in `none`, we won't generate models. `dpg` models are the default models we generate. If you pass in `typeddict`, we will generate models as typed dictionaries.

### `generate-sample`

**Type:** `boolean`

Whether to generate sample files, for basic samples of your generated sdks. Defaults to `false`.

### `generate-test`

**Type:** `boolean`

Whether to generate test files, for basic testing of your generated sdks. Defaults to `false`.

### `api-version`

**Type:** `string | object`

Use this flag if you would like to generate the sdk only for a specific version. Default value is the latest version. Also accepts values `latest` and `all`. For multi-service packages, provide a map from each service namespace's full name to its desired version; services not listed default to their latest version.

**Options:**

- `string`
- `object`

### `license`

**Type:** `object { name, company, link, header, description }`

License information for the generated client code.

**Properties:**

| Name | Type | Default | Description |
| ------------- | -------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `name` | `string` | | License name. The config is required. Predefined license are: MIT License, Apache License 2.0, BSD 3-Clause License, MPL 2.0, GPL-3.0, LGPL-3.0. For other license, you need to configure all the other license config manually. |
| `company` | `string` | | License company name. It will be used in copyright sentences. |
| `link` | `string` | | License link. |
| `header` | `string` | | License header. It will be used in the header comment of generated client code. |
| `description` | `string` | | License description. The full license text. |

### `package-version`

**Type:** `string`

The version of the package.

### `package-name`

**Type:** `string`

The name of the package.

### `generate-packaging-files`

**Type:** `boolean`

Whether to generate packaging files. Packaging files refer to the `setup.py`, `README`, and other files that are needed to package your code.

### `packaging-files-dir`

**Type:** `string`

If you are using a custom packaging files directory, you can specify it here. We won't generate with the default packaging files we have.

### `packaging-files-config`

**Type:** `object`

If you are using a custom packaging files directory, and have additional configuration parameters you want to pass in during generation, you can specify it here. Only applicable if `packaging-files-dir` is set.

### `package-pprint-name`

**Type:** `string`

The name of the package to be used in pretty-printing. Will be the name of the package in `README` and pprinting of `setup.py`.

### `head-as-boolean`

**Type:** `boolean`

Whether to return responses from HEAD requests as boolean. Defaults to `true`.

### `use-pyodide`

**Type:** `boolean`

Whether to generate using `pyodide` instead of `python`. If there is no python installed on your device, we will default to using pyodide to generate the code.

### `validate-versioning`

**Type:** `boolean`

Whether to validate the versioning of the package. Defaults to `true`. If set to `false`, we will not validate the versioning of the package.

### `generation-subdir`

**Type:** `string`

The subdirectory (relative to the package namespace folder) to generate the code in. Use this to keep emitter-generated code separate from hand-written/customized code, so regeneration only overwrites the subdirectory and leaves your customizations untouched. If not specified, the code is generated directly in the package namespace folder. Note: if you're using this flag, you will need to add and maintain the versioning file (`_version.py`) yourself.

Example: for `namespace: azure.storage.blob` with `generation-subdir: _generated`, generated code lands in `azure/storage/blob/_generated/` while your customized code lives in `azure/storage/blob/`. A typical `tspconfig.yaml` looks like:

```yaml
options:
"@azure-tools/typespec-python":
emitter-output-dir: "{output-dir}/{service-dir}/azure-storage-blob"
namespace: "azure.storage.blob"
generation-subdir: "_generated"
```

### `keep-setup-py`

**Type:** `boolean`

Whether to keep the existing `setup.py` when `generate-packaging-files` is `true`. If set to `false` and by default, `pyproject.toml` will be generated instead. To generate `setup.py`, use `basic-setup-py`.

### `keep-pyproject-fields`

**Type:** `object { authors, description, classifiers, urls }`

Which manually customized `[project]` fields to preserve in an existing `pyproject.toml` instead of overwriting them on regeneration. Set a field to `true` to keep it. By default no fields are preserved.

**Properties:**

| Name | Type | Default | Description |
| ------------- | --------- | ------- | ------------------------------------------------------------------- |
| `authors` | `boolean` | | Preserve the `authors` field (e.g. a custom author name and email). |
| `description` | `boolean` | | Preserve the `description` field. |
| `classifiers` | `boolean` | | Preserve the `classifiers` field. |
| `urls` | `boolean` | | Preserve the `[project.urls]` table. |

### `clear-output-folder`

**Type:** `boolean`

Whether to clear the output folder before generating the code. Defaults to `false`.

### `emit-yaml-only`

**Type:** `boolean`

Emit YAML code model only, without running Python generator. For batch processing.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
title: Overview
sidebar_position: 0
toc_min_heading_level: 2
toc_max_heading_level: 3
---

import { Tabs, TabItem } from '@astrojs/starlight/components';

TypeSpec emitter for Python SDKs

## Install

<Tabs>
<TabItem label="In a spec" default>

```bash
npm install @azure-tools/typespec-python
```

</TabItem>
<TabItem label="In a library" default>

```bash
npm install --save-peer @azure-tools/typespec-python
```

</TabItem>
</Tabs>

## Emitter usage

[See documentation](./emitter.md)
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ catalog:
"@types/swagger-ui-express": ^4.1.8
"@types/which": ^3.0.4
"@types/yargs": ^17.0.35
"@typespec/http-client-python": ">=0.34.0 <1.0.0"
"@typespec/http-client-python": ">=0.34.1 <1.0.0"
"@typespec/ts-http-runtime": "0.3.6"
"@vitejs/plugin-react": ^6.0.1
"@vitest/coverage-v8": ^4.1.3
Expand Down
Loading