zod2py
v0.0.3
Published
Convert Zod schemas to Python dataclasses
Downloads
2
Maintainers
Readme
zod2py
This is a simple tool to convert Zod to Python. You can use this tool to sync your Zod schema with your Python API and use Zod as a single source of truth.
Getting Started
npm i -D zod2py
npx zod2py init
to create the config file- Add a script to run your watcher in your
package.json
:
{
"scripts": {
"watch": "zod2py watch",
"run": "zod2py run"
}
}
- Run
npm run watch
to start the watcher (e.g. when developing) - Or run
npm run run
to run the conversion once (e.g. when building)
Example
Based on the config zod2py.config.json
{
"files": ["src/**/*.z2p.js"],
"output": "{FOLDER}/z2p/{FILE}.py"
}
Zod2Py will listen to any X/*.z2p.js
files and generate a corresponding X/z2p/*.z2p.py
file with the schema converted to Python dataclasses, enums, aliases, and more.
You can then use the generated Python files in your project.