pydantic-generator generates the pydantic model classes.
Project description
pydantic-generator
pydantic-generator generates a pydantic schema module from a json file.
install
pydantic-generates uses ast.unparse()
and therefore only supports python 3.9+.
$ python3.9 -m pip install pydantic-generator
$ pydanticgen --help
usage: pydanticgen [-h] -i INPUT_ [-o OUTPUT]
optional arguments:
-h, --help show this help message and exit
-i INPUT_, --input_ INPUT_, --input INPUT_
-o OUTPUT, --output OUTPUT
example
$ ls
response.json
$ cat response.json
{
"menu": {
"id": "file",
"value": "File",
"popup": {
"menuitem": [
{
"value": "New",
"onclick": "CreateNewDoc()"
},
{
"value": "Open",
"onclick": "OpenDoc()"
},
{
"value": "Close",
"onclick": "CloseDoc()"
}
]
}
}
}
# this command generates Response.json
$ pydanticgen -i response.json
$ ls
response.json Response.py
$ cat Response.py
from pydantic import BaseModel
class Response(BaseModel):
class Menu(BaseModel):
id: str
value: str
class Popup(BaseModel):
class Menuitem(BaseModel):
value: str
onclick: str
menuitem: list[Menuitem]
popup: Popup
menu: Menu
(This sample can be found at https://json.org/example.html.)
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file pydantic-generator-1.0.0.tar.gz
.
File metadata
- Download URL: pydantic-generator-1.0.0.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.9.0 Darwin/19.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e9555748855c076588b27ca8bc71497545718fa9b76225578a81aaa903727ad |
|
MD5 | 6399151584a9a6a798134d1542b61fad |
|
BLAKE2b-256 | fbb165fcb56fcd5f309d5a41bfa8028adf251c19a7e897966b4b9a34e970da61 |
File details
Details for the file pydantic_generator-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: pydantic_generator-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.9.0 Darwin/19.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57cace41c1db21d925bd1d704480710fa70a0905cc02797be76db29d840a5d36 |
|
MD5 | b177ae4d0c205329e803eae98b8487c0 |
|
BLAKE2b-256 | 616978eb0e3ec8e43d1187e3b024f3c749b3de3d14f4fae67517fde42563374d |