Convert pydantic model to other format
Project description
pydantic-converter
Convert pydantic models to other formats like typescript interfaces.
Installation
pip install pydantic-converter
Usage
You need to install json-schema-to-typescript to use this tool.
# sample.py
from pydantic_converter import schema
from pydantic import BaseModel
@schema
class User(BaseModel):
name: str
age: int
$ pydantic-converter --help
NAME
pydantic-converter
SYNOPSIS
pydantic-converter PATH OUTPUT_FILE <flags>
POSITIONAL ARGUMENTS
PATH
Type: str | pathlib.Path
OUTPUT_FILE
Type: str | pathlib.Path
FLAGS
-r, --recursive=RECURSIVE # Search .py files recursively from the given path.
Type: bool
Default: False
-c, --camelize=CAMELIZE # Convert field names to camelCase.
Type: bool
Default: False
-e, --export_to=EXPORT_TO
Type: Literal
Default: 'ts'
$ pydantic-converter ./ ./output.ts
# output.ts
export Name = string;
export Age = number;
export interface User {
name: Name;
age: Age;
}
TODO
- Support other language formats
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydantic_converter-0.1.4.tar.gz.
File metadata
- Download URL: pydantic_converter-0.1.4.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fffb40478b81efd297b96f55372d432f931a8d7af21b44fcc6ca260a017f2a04
|
|
| MD5 |
fc47ee0a9d8d12b306aa1a2a4fcf6dca
|
|
| BLAKE2b-256 |
530b756dcfd9d7140fdb647da63b6ee122b33402dfa53e4e03690abe15557d01
|
File details
Details for the file pydantic_converter-0.1.4-py3-none-any.whl.
File metadata
- Download URL: pydantic_converter-0.1.4-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eefbc2cb92e47b26064888faac6052b6ebc1884a98ee22ae5e1794a370948957
|
|
| MD5 |
8034ef43f5069e737d45a79ed2835013
|
|
| BLAKE2b-256 |
6a8ba61f3954a79f69d4a90d462ed4d46cb90f3ef4840d01f4dc1cecd3738a6b
|