Folder Conversion
Convert all your Zod schemas at once. One command walks a folder, finds exported schemas, and writes a file per export.
How It Works
Section titled “How It Works”schemabridge convert folder ./src/schemas --out ./generated --to pydanticSchemaBridge scans every file in ./src/schemas, finds exported Zod schemas, and converts them to Python:
src/schemas/├── user.ts → generated/user.py├── product.ts → generated/product.py└── common/ └── types.ts → generated/common/types.pyYour folder structure stays intact. Each exported schema becomes its own file (snake_case).
Multiple Schemas Per File
Section titled “Multiple Schemas Per File”If one TypeScript file exports multiple schemas, each gets converted:
Input:
export const userSchema = z.object({ ... });export const adminSchema = z.object({ ... });Output:
generated/├── user_schema.py└── admin_schema.pyThe file names come from the export names, converted to snake_case.
Flat Output
Section titled “Flat Output”Want all files in one folder? Use --flat:
schemabridge convert folder ./src/schemas --out ./generated --flatgenerated/├── user.py├── product.py└── types.pyNo subfolders, everything at the top level.
Python Package Mode
Section titled “Python Package Mode”Add --init to create __init__.py files for proper Python imports:
schemabridge convert folder ./src/schemas --out ./generated --initgenerated/├── __init__.py├── user.py└── common/ ├── __init__.py └── types.pyEach generated __init__.py imports every model in that folder and re-exports child packages, so the package tree works with plain Python imports. This behavior only applies when generating Pydantic outputs (--to pydantic or --to all); for TypeScript-only runs, --init / generateInitFiles is ignored.
Now you can import like this:
from generated.user import UserSchemafrom generated.common.types import TypesSchemaBuild Integration
Section titled “Build Integration”Add folder conversion to your build process:
import { convertFolder } from 'schemabridge';
await convertFolder({ sourceDir: './src/schemas', outDir: './python/models', target: 'pydantic', preserveStructure: true, generateInitFiles: true,});{ "scripts": { "generate": "tsx scripts/generate.ts" }}Run npm run generate and your Python models update automatically.
What gets converted
Section titled “What gets converted”- Only exported Zod schemas in files under
sourceDir. Non-exported schemas (e.g.,const schema = z.object(...)) are ignored. - Referenced schemas are inlined inside their parents; separate files are only created for exports.
- Enums (
z.enum([...])) becomeLiteral[...]in Python and union types in.d.ts.
Zod v4 tips
Section titled “Zod v4 tips”- Use direct helpers:
z.date(),z.coerce.date(),z.string().uuid(),z.string().email(). - Avoid deprecated patterns like
z.string().datetime()unless you truly want string output; otherwise considerz.date()/z.coerce.date().