You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A simple CLI tool for converting pydantic models into typescript interfaces. Useful for any scenario in which python and javascript applications are interacting, since it allows you to have a single source of truth for type definitions.
6
7
7
8
This tool requires that you have the lovely json2ts CLI utility installed. Instructions can be found here: https://www.npmjs.com/package/json-schema-to-typescript
8
9
9
10
### Installation
11
+
10
12
```bash
11
13
$ pip install pydantic-to-typescript
12
14
```
15
+
13
16
---
17
+
14
18
### CLI
15
19
16
-
|Prop|Description|
17
-
|:----------|:-----------|
18
-
|‑‑module|name or filepath of the python module you would like to convert. All the pydantic models within it will be converted to typescript interfaces. Discoverable submodules will also be checked.|
19
-
|‑‑output|name of the file the typescript definitions should be written to. Ex: './frontend/apiTypes.ts'|
20
-
|‑‑exclude|name of a pydantic model which should be omitted from the resulting typescript definitions. This option can be defined multiple times, ex: `--exclude Foo --exclude Bar` to exclude both the Foo and Bar models from the output.|
21
-
|‑‑json2ts‑cmd|optional, the command used to invoke json2ts. The default is 'json2ts'. Specify this if you have it installed in a strange location and need to provide the exact path (ex: /myproject/node_modules/bin/json2ts)|
|‑‑module | name or filepath of the python module you would like to convert. All the pydantic models within it will be converted to typescript interfaces. Discoverable submodules will also be checked. |
23
+
|‑‑output | name of the file the typescript definitions should be written to. Ex: './frontend/apiTypes.ts' |
24
+
|‑‑exclude | name of a pydantic model which should be omitted from the resulting typescript definitions. This option can be defined multiple times, ex: `--exclude Foo --exclude Bar` to exclude both the Foo and Bar models from the output. |
25
+
|‑‑json2ts‑cmd | optional, the command used to invoke json2ts. The default is 'json2ts'. Specify this if you have it installed in a strange location and need to provide the exact path (ex: /myproject/node_modules/bin/json2ts) |
26
+
22
27
---
28
+
23
29
### Usage
30
+
24
31
Define your pydantic models (ex: /backend/api.py):
0 commit comments