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
3 changes: 3 additions & 0 deletions cspell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,13 @@ words:
- ptvsd
- pylint
- pylintrc
- pyodide
- pygen
- qnas
- ragrs
- rcfile
- recommonmark
- regen
- reqs
- retrys
- roundtrippable
Expand All @@ -123,6 +125,7 @@ words:
- tfft
- tikka
- toctree
- tspd
- undoc
- venv
- venvtools
Expand Down
189 changes: 105 additions & 84 deletions packages/typespec-python/README.md
Original file line number Diff line number Diff line change
@@ -1,118 +1,139 @@
# TypeSpec Python Client Emitter
# @azure-tools/typespec-python

## Getting started
TypeSpec emitter for Python SDKs

### Initialize TypeSpec Project
## Install

Follow [TypeSpec Getting Started](https://typespec.io/docs) to initialize your TypeSpec project.
```bash
npm install @azure-tools/typespec-python
```

## Usage

Make sure `npx tsp compile .` runs correctly.
1. Via the command line

### Add typespec-python to your project
```bash
tsp compile . --emit=@azure-tools/typespec-python
```

Include @azure-tools/typespec-python dependencies in `package.json`:
2. Via the config

```diff
"dependencies": {
+ "@azure-tools/typespec-python": "latest"
},
```yaml
emit:
- "@azure-tools/typespec-python"
```

Run `npm install` to install the dependency.
The config can be extended with options as follows:

### Generate a Python client library
```yaml
emit:
- "@azure-tools/typespec-python"
options:
"@azure-tools/typespec-python":
option: value
```

You can either specify typespec-python on the commandline or through tspconfig.yaml.
## Emitter options

#### Generate with `--emit` command
### `emitter-output-dir`

Run command `npx tsp compile --emit @azure-tools/typespec-python <path-to-typespec-file>`
**Type:** `absolutePath`

e.g.
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)

```cmd
npx tsp compile main.tsp --emit @azure-tools/typespec-python
```
### `examples-dir`

or
**Type:** `string`

```cmd
npx tsp compile client.tsp --emit @azure-tools/typespec-python
```
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.

#### Generate with tspconfig.yaml
### `namespace`

Add the following configuration in tspconfig.yaml:
**Type:** `string`

```diff
emit:
- "@azure-tools/typespec-python"
options:
"@azure-tools/typespec-python":
+ package-dir: "azure-contoso"
+ package-name: "azure-contoso"
```
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.

Run the command to generate your library:
### `flavor`

```cmd
npx tsp compile main.tsp
```
**Type:** `string`

or
The flavor of the SDK.

```cmd
npx tsp compile client.tsp
```
### `models-mode`

## Configure the generated library
**Type:** `"dpg" | "none"`

You can further configure the generated client library using the emitter options provided through @azure-tools/typespec-python.
What kind of models to generate. If you pass in `none`, we won't generate models. `dpg` models are the default models we generate.

You can set options in the command line directly via `--option @azure-tools/typespec-python.<optionName>=XXX`, e.g. `--option @azure-tools/typespec-python.package-name="azure-contoso"`
### `generate-sample`

or
**Type:** `boolean`

Modify `tspconfig.yaml` in the TypeSpec project to add emitter options under options/@azure-tools/typespec-python.
Whether to generate sample files, for basic samples of your generated sdks. Defaults to `false`.

```diff
emit:
- "@azure-tools/typespec-python"
options:
"@azure-tools/typespec-python":
+ package-dir: "{package-dir}"
+ package-name: "azure-contoso"
```
### `generate-test`

### Supported emitter options
**Type:** `boolean`

Common emitter configuration example:
Whether to generate test files, for basic testing of your generated sdks. Defaults to `false`.

```yaml
emit:
- "@azure-tools/typespec-python"
options:
"@azure-tools/typespec-python":
package-dir: "{package-dir}"
package-name: "azure-contoso"
```
### `api-version`

**Type:** `string`

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`.

### `license`

**Type:** `object`

License information for the generated client code.

### `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`

|Option|Type|Description|
|-|-|-|
|`package-version`|string|Specify the package version. Default version: `1.0.0b1`.|
|`package-name`|string|Specify the package name.|
|`package-dir`|string|Specify the output directory for the package.|
|`generate-packaging-files`|boolean|Indicate if packaging files, such as setup.py, should be generated.|
|`package-pprint-name`|string|Specify the pretty print name for the package.|
|`flavor`|string|Represents the type of SDK that will be generated. By default, there will be no branding in the generated client library. Specify `"azure"` to generate an SDK following Azure guidelines.|
|`company-name`|string|Specify the company name to be inserted into licensing data. For `"azure"` flavor, the default value inserted is `Microsoft`.|

**Advanced emitter options**

|Option|Type|Description|
|-|-|-|
|`head-as-boolean`|boolean|Generate head calls to return a boolean. Default: `true`.|
|`packaging-files-dir`|string|Pass in the path to a custom directory with SDK packaging files.|
|`packaging-files-config`|object|Specify configuration options that will be passed directly into the packaging files specified by the `packaging-files-dir` option.|
|`tracing`|boolean|Only available for the `"azure"` flavor of SDKs, provide tracing support in the generated client library. Default: `true`.|
|`debug`|boolean|Enable debugging.|
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.
10 changes: 7 additions & 3 deletions packages/typespec-python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
"type": "module",
"main": "dist/src/index.js",
"exports": {
".": "./dist/src/index.js",
"./testing": "./dist/src/testing/index.js"
".": {
"types": "./dist/src/index.d.ts",
"default": "./dist/src/index.js"
}
},
"tspMain": "dist/src/index.js",
"engines": {
Expand All @@ -36,7 +38,8 @@
"lint:fix": "eslint . --fix --ext .ts",
"format": "npx prettier **/*.ts --write && tsx ./scripts/eng/format.ts",
"regenerate": "tsx ./scripts/eng/regenerate.ts",
"test": "tsx ./scripts/eng/run-tests.ts"
"test": "tsx ./scripts/eng/run-tests.ts",
"regen-docs": "npm run build && tspd doc . --enable-experimental --output-dir ./website/src/content/docs/docs/emitters/clients/typespec-python/reference --skip-js"
},
"files": [
"dist/**",
Expand Down Expand Up @@ -76,6 +79,7 @@
"@typespec/events": "~0.70.0",
"@typespec/sse": "~0.70.0",
"@typespec/streams": "~0.70.0",
"@typespec/tspd": "~0.70.0",
"@typespec/xml": "~0.70.0",
"@azure-tools/typespec-azure-resource-manager": "~0.56.0",
"@azure-tools/typespec-azure-core": "~0.56.0",
Expand Down
Loading
Loading